Project

General

Profile

Download (5.21 KB) Statistics
| Branch: | Tag: | Revision:

runcible / test / resources / repository_group_test.rb @ master

1
require 'rubygems'
2
require 'minitest/autorun'
3
require './lib/runcible/resources/repository_group'
4
require './lib/runcible/resources/repository'
5
require './test/support/repository_support'
6

    
7
module Resources
8
  module TestRepoGroupBase
9
    def setup
10
      @support = RepositorySupport.new
11
      @resource = TestRuncible.server.resources.repository_group
12
      @repo_group_id = 'integration_test_repository_group'
13
    end
14

    
15
    def create_repo_group(options = {})
16
      if options[:with_distributor]
17
        @resource.create(@repo_group_id, :display_name => 'foo_w_distributor', :description => 'Test description.',
18
                                         :distributors => [Runcible::Models::GroupExportDistributor.new(false, false)])
19
      else
20
        @resource.create(@repo_group_id, :display_name => 'foo', :description => 'Test description.')
21
      end
22
    rescue => e
23
      puts "could not create repo group with id => #{@repo_group_id}. Exception => #{e}"
24
    end
25

    
26
    def destroy_repo_group
27
      @resource.delete(@repo_group_id)
28
    rescue => e
29
      puts "could not destroy repo group with id => #{@repo_group_id}. Exception => #{e}"
30
    end
31
  end
32

    
33
  class TestRepoGroupCreate < MiniTest::Unit::TestCase
34
    include TestRepoGroupBase
35

    
36
    def teardown
37
      destroy_repo_group
38
      super
39
    end
40

    
41
    def test_create
42
      response = create_repo_group
43
      assert_equal @repo_group_id, response['id']
44
    end
45
  end
46

    
47
  class TestRepoGroup < MiniTest::Unit::TestCase
48
    include TestRepoGroupBase
49

    
50
    def teardown
51
      destroy_repo_group
52
      super
53
    end
54

    
55
    def setup
56
      super
57
      create_repo_group
58
    end
59

    
60
    def test_retrieve
61
      response = @resource.retrieve(@repo_group_id)
62
      assert_equal @repo_group_id, response['id']
63
    end
64

    
65
    def test_retrieve_all
66
      response = @resource.retrieve_all
67
      refute_empty response
68
      assert_equal 1, response.select { |grp| grp[:id] == @repo_group_id }.size
69
    end
70
  end
71

    
72
  class TestRepoGroupDestroy < MiniTest::Unit::TestCase
73
    include TestRepoGroupBase
74

    
75
    def setup
76
      super
77
      create_repo_group
78
    end
79

    
80
    def test_destroy
81
      response = @resource.delete(@repo_group_id)
82
      assert_equal 200, response.code
83
    end
84
  end
85

    
86
  class TestRepoGroupAssociate < MiniTest::Unit::TestCase
87
    include TestRepoGroupBase
88

    
89
    def setup
90
      super
91
      create_repo_group
92
      @support.create_repo
93
      @repo_id = RepositorySupport.repo_id
94
    end
95

    
96
    def teardown
97
      destroy_repo_group
98
      @support.destroy_repo
99
      super
100
    end
101

    
102
    def test_associate
103
      @criteria = {:criteria =>
104
                     {:filters =>
105
                       {:id =>
106
                          {'$in' => [@repo_id]}
107
                       }
108
                     }
109
                  }
110
      response = @resource.associate(@repo_group_id, @criteria)
111

    
112
      assert_equal 200, response.code
113
      assert_includes response, @repo_id
114
    end
115
  end
116

    
117
  class TestRepoGroupUnassociate < MiniTest::Unit::TestCase
118
    include TestRepoGroupBase
119

    
120
    def setup
121
      super
122
      create_repo_group
123
      @support.create_repo
124
      @repo_id = RepositorySupport.repo_id
125
      @criteria = {:criteria =>
126
                     {:filters =>
127
                       {:id =>
128
                          {'$in' => [@repo_id]}
129
                       }
130
                     }
131
                  }
132
      @resource.associate(@repo_group_id, @criteria)
133
    end
134

    
135
    def teardown
136
      destroy_repo_group
137
      @support.destroy_repo
138
      super
139
    end
140

    
141
    def test_unassociate
142
      response = @resource.unassociate(@repo_group_id, @criteria)
143

    
144
      assert_equal 200, response.code
145
      refute_includes response, @repo_id
146
    end
147
  end
148

    
149
  class TestRepoGroupRetrieveDistributorsAndPublish < MiniTest::Unit::TestCase
150
    include TestRepoGroupBase
151

    
152
    def setup
153
      super
154
      # the runcible repo group distributor uses a random ID when POSTing, we
155
      # need to be more lenient on VCR matches for test_publish to work.
156
      VCR.eject_cassette
157
      VCR.insert_cassette('resources/repo_group_retrieve_distributors_and_publish',
158
                          :match_requests_on => [:path, :method])
159

    
160
      create_repo_group(:with_distributor => true)
161
      @support.create_repo
162
      @repo_id = RepositorySupport.repo_id
163
    end
164

    
165
    def teardown
166
      destroy_repo_group
167
      @support.destroy_repo
168
      super
169
    end
170

    
171
    def test_retrieve_distributors
172
      response = @resource.retrieve_distributors @repo_group_id
173
      assert_equal 200, response.code
174
      assert_equal response.first['distributor_type_id'], 'group_export_distributor'
175
    end
176

    
177
    def test_publish
178
      distributors = @resource.retrieve_distributors @repo_group_id
179
      response = @resource.publish @repo_group_id, distributors.first["id"]
180
      assert_equal 202, response.code
181
    end
182
  end
183

    
184
  class TestRepoGroupRetrieveDistributorsEmpty < MiniTest::Unit::TestCase
185
    include TestRepoGroupBase
186

    
187
    def setup
188
      super
189
      create_repo_group
190
      @support.create_repo
191
      @repo_id = RepositorySupport.repo_id
192
    end
193

    
194
    def teardown
195
      destroy_repo_group
196
      @support.destroy_repo
197
      super
198
    end
199

    
200
    def test_retrieve_distributors_empty
201
      response = @resource.retrieve_distributors @repo_group_id
202
      assert_equal 200, response.code
203
      assert_equal response, []
204
    end
205
  end
206
end