Project

General

Profile

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

runcible / test / extensions / repository_test.rb @ e5f2394a

1
require 'rubygems'
2
require 'minitest/autorun'
3

    
4
require './test/support/repository_support'
5
require './lib/runcible'
6

    
7
module Extensions
8
  module TestRepositoryBase
9
    def setup
10
      @support = RepositorySupport.new
11
      @extension = TestRuncible.server.extensions.repository
12
    end
13
  end
14

    
15
  class TestRepositoryCreate < MiniTest::Unit::TestCase
16
    include TestRepositoryBase
17

    
18
    def setup
19
      super
20
      @support.destroy_repo
21
    end
22

    
23
    def teardown
24
      super
25
      @support.destroy_repo
26
    end
27

    
28
    def test_create_with_importer
29
      response = @extension.create_with_importer(RepositorySupport.repo_id, :id => 'yum_importer')
30
      assert_equal 201, response.code
31

    
32
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
33
      assert_equal RepositorySupport.repo_id, response['id']
34
      assert_equal 'yum_importer', response['importers'].first['importer_type_id']
35
    end
36

    
37
    def test_create_with_importer_object
38
      response = @extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::YumImporter.new)
39
      assert_equal 201, response.code
40

    
41
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
42
      assert_equal RepositorySupport.repo_id, response['id']
43
      assert_equal 'yum_importer', response['importers'].first['importer_type_id']
44
    end
45

    
46
    def test_create_with_distributors
47
      distributors = [{'type_id' => 'yum_distributor', 'id' => '123', 'auto_publish' => true,
48
                       'config' => {'relative_url' => 'path', 'http' => true, 'https' => true}}]
49
      response = @extension.create_with_distributors(RepositorySupport.repo_id, distributors)
50

    
51
      assert_equal 201, response.code
52
      assert_equal RepositorySupport.repo_id, response['id']
53
    end
54

    
55
    def test_create_with_distributor_object
56
      repo_id = RepositorySupport.repo_id + '_distro'
57
      response = @extension.create_with_distributors(repo_id, [Runcible::Models::YumDistributor.new(
58
        'path', true, true, :id => '123')])
59
      assert_equal 201, response.code
60

    
61
      response = @extension.retrieve(repo_id, :details => true)
62
      assert_equal repo_id, response['id']
63
      assert_equal 'yum_distributor', response['distributors'].first['distributor_type_id']
64
    ensure
65
      @support.destroy_repo(repo_id)
66
    end
67

    
68
    def test_create_with_importer_and_distributors
69
      distributors = [{'type_id' => 'yum_distributor', 'id' => '123', 'auto_publish' => true,
70
                       'config' => {'relative_url' => '123/456', 'http' => true, 'https' => true}}]
71
      response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id,
72
                                                                  {:id => 'yum_importer'}, distributors)
73
      assert_equal 201, response.code
74

    
75
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
76
      assert_equal RepositorySupport.repo_id, response['id']
77
      assert_equal 'yum_distributor', response['distributors'].first['distributor_type_id']
78
    end
79

    
80
    def test_create_with_importer_and_distributors_objects
81
      distributors = [Runcible::Models::YumDistributor.new(
82
        'path', true, true, :id => '123')]
83
      importer = Runcible::Models::YumImporter.new
84
      response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, importer, distributors)
85
      assert_equal 201, response.code
86

    
87
      response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
88
      assert_equal RepositorySupport.repo_id, response['id']
89
      assert_equal 'yum_importer', response['importers'].first['importer_type_id']
90
    end
91
  end
92

    
93
  class TestRepositoryMisc < MiniTest::Unit::TestCase
94
    def self.before_suite
95
      self.support = RepositorySupport.new
96
      self.support.create_and_sync_repo(:importer_and_distributor => true)
97
    end
98

    
99
    def self.after_suite
100
      self.support.destroy_repo
101
    end
102

    
103
    def setup
104
      @extension = TestRuncible.server.extensions.repository
105
    end
106

    
107
    def test_search_by_repository_ids
108
      response = @extension.search_by_repository_ids([RepositorySupport.repo_id])
109

    
110
      assert_equal 200, response.code
111
      refute_empty response.map { |repo| repo['display_name'] == RepositorySupport.repo_id }
112
    end
113

    
114
    def test_create_or_update_schedule
115
      response = @extension.create_or_update_schedule(
116
        RepositorySupport.repo_id,
117
        'yum_importer',
118
        '2012-09-25T20:44:00Z/P7D'
119
      )
120
      assert_equal 201, response.code
121

    
122
      response = @extension.create_or_update_schedule(
123
        RepositorySupport.repo_id,
124
        'yum_importer',
125
        '2011-09-25T20:44:00Z/P7D'
126
      )
127
      assert_equal 200, response.code
128
    end
129

    
130
    def test_remove_schedules
131
      TestRuncible.server.resources.repository_schedule.create(
132
        RepositorySupport.repo_id,
133
        'yum_importer',
134
        '2012-10-25T20:44:00Z/P7D'
135
      )
136
      @extension.remove_schedules(RepositorySupport.repo_id, 'yum_importer')
137
    end
138

    
139
    def test_retrieve_with_details
140
      response = @extension.retrieve_with_details(RepositorySupport.repo_id)
141

    
142
      assert_equal 200, response.code
143
      assert_includes response, 'distributors'
144
    end
145

    
146
    def test_publish_all
147
      responses = @extension.publish_all(RepositorySupport.repo_id)
148
      assert_equal 1, responses.length
149
      responses.each do |response|
150
        tasks = assert_async_response(response)
151
        assert_includes tasks.first['tags'], 'pulp:action:publish'
152
      end
153
    end
154

    
155
    def test_publish_status
156
      response = @extension.publish_status(RepositorySupport.repo_id)
157
      assert_equal 200, response.code
158
    end
159

    
160
    def test_sync_status
161
      response = @extension.sync_status(RepositorySupport.repo_id)
162

    
163
      assert_equal 200, response.code
164
    end
165

    
166
    def test_generate_applicability_by_ids_with_spawned_tasks
167
      response = @extension.regenerate_applicability_by_ids([RepositorySupport.repo_id], false)
168
      refute response.key?("group_id")
169
      tasks = assert_async_response(response)
170
      assert_equal 'finished', tasks.first['state']
171
    end
172

    
173
    def test_generate_applicability_by_ids_with_task_groups
174
      response = @extension.regenerate_applicability_by_ids([RepositorySupport.repo_id], true)
175
      assert response.key?("group_id")
176
      assert_async_response(response)
177
    end
178
  end
179

    
180
  class TestRepositoryUnitList < MiniTest::Unit::TestCase
181
    def self.before_suite
182
      @@extension = TestRuncible.server.extensions.repository
183
      self.support = RepositorySupport.new
184
      self.support.destroy_repo
185
      self.support.create_and_sync_repo(:importer => true)
186
    end
187

    
188
    def self.after_suite
189
      self.support.destroy_repo
190
    end
191

    
192
    def test_rpm_ids
193
      response = @@extension.rpm_ids(RepositorySupport.repo_id)
194

    
195
      refute_empty response
196
      assert_kind_of String, response.first
197
    end
198

    
199
    def test_rpms
200
      response = @@extension.rpms(RepositorySupport.repo_id)
201

    
202
      refute_empty response
203
      assert_kind_of Hash, response.first
204
    end
205

    
206
    def test_errata_ids
207
      response = @@extension.errata_ids(RepositorySupport.repo_id)
208
      refute_empty response
209
    end
210

    
211
    def test_errata
212
      response = @@extension.errata(RepositorySupport.repo_id)
213
      refute_empty response
214
    end
215

    
216
    def test_distributions
217
      response = @@extension.distributions(RepositorySupport.repo_id)
218

    
219
      refute_empty response
220
    end
221

    
222
    def test_package_groups
223
      response = @@extension.package_groups(RepositorySupport.repo_id)
224

    
225
      refute_empty response
226
    end
227

    
228
    def test_package_categories
229
      response = @@extension.package_categories(RepositorySupport.repo_id)
230

    
231
      refute_empty response
232
    end
233

    
234
    def test_rpms_by_name
235
      list = @@extension.rpms(RepositorySupport.repo_id)
236
      rpm = list.first
237
      response = @@extension.rpms_by_nvre(RepositorySupport.repo_id, rpm['name'])
238

    
239
      refute_empty response
240
    end
241

    
242
    def test_rpms_by_nvre
243
      list = @@extension.rpms(RepositorySupport.repo_id)
244
      rpm = list.first
245
      response = @@extension.rpms_by_nvre(RepositorySupport.repo_id, rpm['name'], rpm['version'],
246
                                              rpm['release'], rpm['epoch'])
247

    
248
      refute_empty response
249
    end
250
  end
251
end