Project

General

Profile

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

runcible / test / extensions / consumer_test.rb @ 1a2d49fd

1
require 'rubygems'
2
require 'minitest/autorun'
3
require './lib/runcible/resources/consumer'
4
require './lib/runcible/extensions/consumer'
5
require './test/support/repository_support'
6
require './test/support/consumer_support'
7

    
8
module Extensions
9
  class TestConsumer < MiniTest::Unit::TestCase
10
    def self.before_suite
11
      @@repo_support = RepositorySupport.new
12
      @@consumer_support = ConsumerSupport.new
13
      @@repo_support.create_and_sync_repo(:importer_and_distributor => true)
14
    end
15

    
16
    def self.after_suite
17
      @@repo_support.destroy_repo
18
    end
19

    
20
    def setup
21
      @resource = TestRuncible.server.resources.consumer
22
      @extension = TestRuncible.server.extensions.consumer
23
      @consumer_id = 'integration_test_consumer_extensions11000'
24
      @@consumer_support.destroy_consumer
25
      @@consumer_support.create_consumer(true)
26
      @consumer_id = ConsumerSupport.consumer_id
27
      bind_repo
28
    end
29

    
30
    def teardown
31
      @@consumer_support.destroy_consumer
32
    end
33

    
34
    def bind_repo
35
      response = @extension.bind_all(@consumer_id, RepositorySupport.repo_id,
36
                                  Runcible::Models::YumDistributor.type_id, :notify_agent => false)
37
      @@repo_support.wait_on_response(response.first)
38
    end
39

    
40
    def test_activate_node
41
      response = @extension.activate_node(@consumer_id)
42
      refute_empty response
43
    end
44

    
45
    def test_deactivate_node
46
      @extension.activate_node(@consumer_id)
47
      response = @extension.deactivate_node(@consumer_id)
48
      refute_empty response
49
    end
50

    
51
    def test_bind_all
52
      @extension.unbind_all(@consumer_id, RepositorySupport.repo_id, Runcible::Models::YumDistributor.type_id)
53
      response = @extension.bind_all(@consumer_id, RepositorySupport.repo_id,
54
                                     Runcible::Models::YumDistributor.type_id, :notify_agent => false)
55
      assert_equal 200, response.first.code
56
    end
57

    
58
    def test_unbind_all
59
      response = @extension.unbind_all(@consumer_id, RepositorySupport.repo_id,
60
                                       Runcible::Models::YumDistributor.type_id)
61

    
62
      assert_equal 200, response.first.code
63
    end
64

    
65
    def test_install_content
66
      response = @extension.install_content(@consumer_id, 'rpm', ['zsh', 'foo'])
67

    
68
      assert_equal 202, response.code
69
      assert response['spawned_tasks'].first['task_id']
70
    end
71

    
72
    def test_update_content
73
      response = @extension.update_content(@consumer_id, 'rpm', ['zsh', 'foo'])
74

    
75
      assert_equal 202, response.code
76
      assert response['spawned_tasks'].first['task_id']
77
    end
78

    
79
    def test_uninstall_content
80
      response = @extension.uninstall_content(@consumer_id, 'rpm', ['zsh', 'foo'])
81

    
82
      assert_equal 202, response.code
83
      assert response['spawned_tasks'].first['task_id']
84
    end
85

    
86
    def test_generate_content
87
      content = @extension.generate_content('rpm', ['unit_1', 'unit_2'])
88

    
89
      refute_empty content
90
      refute_empty content.select { |unit| unit[:type_id] == 'rpm' }
91
    end
92

    
93
    def test_generate_content_all
94
      content = @extension.generate_content('rpm', ['unit_1'], :all => true)
95

    
96
      refute_empty content
97
      assert_equal 'rpm', content.first[:type_id]
98
      assert_empty content.first[:unit_key]
99
    end
100

    
101
    def test_generate_applicability_by_ids
102
      response = @extension.regenerate_applicability_by_ids([@consumer_id])
103

    
104
      assert_equal 202, response.code
105
      tasks = RepositorySupport.new.wait_on_response(response)
106
      assert 'finished', tasks.first['state']
107
    end
108

    
109
    def test_applicable_errata
110
      response = @extension.applicable_errata([@consumer_id])
111

    
112
      assert_equal 200, response.code
113
    end
114

    
115
    def test_applicable_rpms
116
      response = @extension.applicable_rpms([@consumer_id])
117

    
118
      assert_equal 200, response.code
119
    end
120
  end
121

    
122
  class TestConsumerApplicabilityScenario < MiniTest::Unit::TestCase
123
    def self.before_suite
124
      @@repo_support = RepositorySupport.new
125
      @@consumer_support = ConsumerSupport.new
126
      @@repo_support.create_and_sync_repo(:importer_and_distributor => true)
127
    end
128

    
129
    def self.after_suite
130
      @@repo_support.destroy_repo
131
    end
132

    
133
    def setup
134
      @extension = TestRuncible.server.extensions.consumer
135
      @consumer_id = 'integration_test_consumer_extensions11000'
136
      @@consumer_support.destroy_consumer
137
      @@consumer_support.create_consumer(false)
138
      @consumer_id = ConsumerSupport.consumer_id
139
      bind_repo
140
    end
141

    
142
    def test_applicability
143
      @extension.upload_profile(@consumer_id, 'rpm', [{'name' => 'elephant', 'version' => '0.2', 'release' => '0.7',
144
                                                       'epoch' => 0, 'arch' => 'noarch', 'vendor' => 'Fedora'}])
145
      task = @extension.regenerate_applicability_by_ids([@consumer_id])
146
      RepositorySupport.new.wait_on_response(task)
147
      applicability = @extension.applicable_errata([@consumer_id])
148

    
149
      refute_empty applicability
150
      assert applicability[0]['consumers'].include?(@consumer_id)
151
      refute_empty applicability[0]['applicability']['erratum']
152
    end
153

    
154
    def bind_repo
155
      tasks = @extension.bind_all(@consumer_id, RepositorySupport.repo_id,
156
                                  Runcible::Models::YumDistributor.type_id, :notify_agent => false)
157
      @@repo_support.wait_on_response(tasks.first)
158
    end
159
  end
160
end