yao 0.14.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +2 -2
  3. data/.github/workflows/ubuntu-rvm.yml +1 -1
  4. data/.github/workflows/ubuntu.yml +2 -2
  5. data/lib/yao/resources/base.rb +17 -5
  6. data/lib/yao/resources/flavor.rb +10 -0
  7. data/lib/yao/resources/floating_ip.rb +1 -7
  8. data/lib/yao/resources/loadbalancer_pool.rb +10 -20
  9. data/lib/yao/resources/meter.rb +1 -1
  10. data/lib/yao/resources/network.rb +1 -1
  11. data/lib/yao/resources/old_sample.rb +1 -1
  12. data/lib/yao/resources/port.rb +1 -1
  13. data/lib/yao/resources/project.rb +5 -0
  14. data/lib/yao/resources/{tenant_associationable.rb → project_associationable.rb} +5 -5
  15. data/lib/yao/resources/resource.rb +1 -1
  16. data/lib/yao/resources/restfully_accessible.rb +3 -2
  17. data/lib/yao/resources/role_assignment.rb +37 -5
  18. data/lib/yao/resources/router.rb +19 -10
  19. data/lib/yao/resources/security_group.rb +1 -1
  20. data/lib/yao/resources/server.rb +6 -1
  21. data/lib/yao/resources/subnet.rb +1 -1
  22. data/lib/yao/resources/tenant.rb +5 -0
  23. data/lib/yao/resources/user.rb +6 -1
  24. data/lib/yao/resources/volume.rb +14 -1
  25. data/lib/yao/resources/volume_action.rb +13 -0
  26. data/lib/yao/resources.rb +1 -1
  27. data/lib/yao/version.rb +1 -1
  28. data/test/yao/resources/test_base.rb +21 -0
  29. data/test/yao/resources/test_flavor.rb +67 -33
  30. data/test/yao/resources/test_floating_ip.rb +5 -5
  31. data/test/yao/resources/test_loadbalancer_pool.rb +146 -1
  32. data/test/yao/resources/test_meter.rb +5 -5
  33. data/test/yao/resources/test_network.rb +6 -6
  34. data/test/yao/resources/test_port.rb +6 -6
  35. data/test/yao/resources/test_project.rb +25 -5
  36. data/test/yao/resources/test_restfully_accessible.rb +46 -4
  37. data/test/yao/resources/test_role_assignment.rb +100 -3
  38. data/test/yao/resources/test_router.rb +33 -12
  39. data/test/yao/resources/test_security_group.rb +5 -5
  40. data/test/yao/resources/test_server.rb +52 -6
  41. data/test/yao/resources/test_subnet.rb +6 -6
  42. data/test/yao/resources/test_user.rb +28 -1
  43. data/test/yao/resources/test_volume.rb +81 -1
  44. data/yao.gemspec +1 -1
  45. metadata +7 -6
@@ -46,48 +46,64 @@ class TestFlavor < TestYaoResource
46
46
  assert_equal(512, flavor.memory)
47
47
  end
48
48
 
49
- def test_list
50
- stub = stub_request(:get, "https://example.com:12345/flavors/detail").
49
+ def flavor_detail
50
+ JSON.parse(<<~JSON)
51
+ {
52
+ "OS-FLV-DISABLED:disabled": false,
53
+ "disk": 20,
54
+ "OS-FLV-EXT-DATA:ephemeral": 0,
55
+ "os-flavor-access:is_public": true,
56
+ "id": "7",
57
+ "links": [
58
+ {
59
+ "href": "http://openstack.example.com/v2/6f70656e737461636b20342065766572/flavors/7",
60
+ "rel": "self"
61
+ },
62
+ {
63
+ "href": "http://openstack.example.com/6f70656e737461636b20342065766572/flavors/7",
64
+ "rel": "bookmark"
65
+ }
66
+ ],
67
+ "name": "m1.small.description",
68
+ "ram": 2048,
69
+ "swap": 0,
70
+ "vcpus": 1,
71
+ "rxtx_factor": 1.0,
72
+ "description": "test description",
73
+ "extra_specs": {
74
+ "hw:cpu_policy": "shared",
75
+ "hw:numa_nodes": "1"
76
+ }
77
+ }
78
+ JSON
79
+ end
80
+
81
+ def stub_flavors_detail(query=nil)
82
+ url = ['https://example.com:12345/flavors/detail',query].compact.join('?')
83
+ stub_request(:get, url).
51
84
  to_return(
52
85
  status: 200,
53
- body: <<-JSON,
54
- {
55
- "flavors": [
56
- {
57
- "OS-FLV-DISABLED:disabled": false,
58
- "disk": 1,
59
- "OS-FLV-EXT-DATA:ephemeral": 0,
60
- "os-flavor-access:is_public": true,
61
- "id": "1",
62
- "links": [
63
- {
64
- "href": "http://openstack.example.com/v2/6f70656e737461636b20342065766572/flavors/1",
65
- "rel": "self"
66
- },
67
- {
68
- "href": "http://openstack.example.com/6f70656e737461636b20342065766572/flavors/1",
69
- "rel": "bookmark"
70
- }
71
- ],
72
- "name": "m1.tiny",
73
- "ram": 512,
74
- "swap": "",
75
- "vcpus": 1,
76
- "rxtx_factor": 1.0,
77
- "description": null,
78
- "extra_specs": {}
79
- }
80
- ]
81
- }
82
- JSON
86
+ body: { flavors:[flavor_detail] }.to_json,
83
87
  headers: {'Content-Type' => 'application/json'}
84
88
  )
89
+ end
85
90
 
91
+ def stub_flavor(id)
92
+ stub_request(:get, "https://example.com:12345/flavors/#{id}").
93
+ to_return(
94
+ status: 200,
95
+ body: { 'flavor': flavor_detail }.to_json,
96
+ headers: {'Content-Type' => 'application/json'}
97
+ )
98
+ end
99
+
100
+ def test_list
101
+ stub = stub_flavors_detail
86
102
  assert(Yao::Flavor.resources_detail_available)
87
103
 
88
104
  flavors = Yao::Flavor.list
89
105
  assert_instance_of(Yao::Flavor, flavors.first)
90
- assert_equal("m1.tiny", flavors.first.name)
106
+ assert_equal("m1.small.description", flavors.first.name)
91
107
 
92
108
  assert_requested(stub)
93
109
  end
@@ -97,4 +113,22 @@ class TestFlavor < TestYaoResource
97
113
  # see also: https://stackoverflow.com/questions/25883618/how-to-test-method-alias-ruby
98
114
  assert_equal(Yao::Flavor.method(:list), Yao::Flavor.method(:list_detail))
99
115
  end
116
+
117
+ def test_get_by_id
118
+ stub = stub_flavor(7)
119
+ flavor = Yao::Flavor.get('7')
120
+ assert_equal('m1.small.description', flavor.name)
121
+ assert_requested(stub)
122
+ end
123
+
124
+ def test_get_by_name
125
+ stub = stub_request(:get, "https://example.com:12345/flavors/m1.small.description").to_return(status: 404)
126
+ stub2 = stub_flavors_detail
127
+ stub3 = stub_flavor(7)
128
+ flavor = Yao::Flavor.get('m1.small.description')
129
+ assert_equal('7', flavor.id)
130
+ assert_requested(stub)
131
+ assert_requested(stub2)
132
+ assert_requested(stub3)
133
+ end
100
134
  end
@@ -82,14 +82,14 @@ class TestFloatingIP < TestYaoResource
82
82
  assert_requested(stub)
83
83
  end
84
84
 
85
- def test_tenant
85
+ def test_project
86
86
 
87
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
87
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
88
88
  .to_return(
89
89
  status: 200,
90
90
  body: <<-JSON,
91
91
  {
92
- "tenant": {
92
+ "project": {
93
93
  "id": "0123456789abcdef0123456789abcdef"
94
94
  }
95
95
  }
@@ -102,8 +102,8 @@ class TestFloatingIP < TestYaoResource
102
102
  "tenant_id" => "0123456789abcdef0123456789abcdef",
103
103
  )
104
104
 
105
- assert_instance_of(Yao::Tenant, fip.tenant)
106
- assert_instance_of(Yao::Tenant, fip.project)
105
+ assert_instance_of(Yao::Project, fip.tenant)
106
+ assert_instance_of(Yao::Project, fip.project)
107
107
  assert_equal('0123456789abcdef0123456789abcdef', fip.tenant.id)
108
108
 
109
109
  assert_requested(stub)
@@ -13,7 +13,14 @@ class TestLoadBalancerPool < TestYaoResource
13
13
  "type" => "SOURCE_IP"
14
14
  },
15
15
  "operating_status" => "ONLINE",
16
- "name" => "round_robin_pool"
16
+ "name" => "round_robin_pool",
17
+ "members" => [
18
+ {"id" => "957a1ace-1bd2-449b-8455-820b6e4b63f3"},
19
+ ],
20
+ "listeners" => [
21
+ {"id" => "023f2e34-7806-443b-bfae-16c324569a3d"}
22
+ ],
23
+ "healthmonitor_id" => "8ed3c5ac-6efa-420c-bedb-99ba14e58db5",
17
24
  }
18
25
 
19
26
  pool = Yao::Resources::LoadBalancerPool.new(params)
@@ -30,5 +37,143 @@ class TestLoadBalancerPool < TestYaoResource
30
37
  }, pool.session_persistence)
31
38
  assert_equal("ONLINE", pool.operating_status)
32
39
  assert_equal("round_robin_pool", pool.name)
40
+
41
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail#show-member-details
42
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/pools//members/957a1ace-1bd2-449b-8455-820b6e4b63f3")
43
+ .to_return(
44
+ status: 200,
45
+ body: <<-JSON,
46
+ {
47
+ "member": {
48
+ "monitor_port": 8080,
49
+ "project_id": "e3cd678b11784734bc366148aa37580e",
50
+ "name": "web-server-1",
51
+ "weight": 20,
52
+ "backup": false,
53
+ "admin_state_up": true,
54
+ "subnet_id": "bbb35f84-35cc-4b2f-84c2-a6a29bba68aa",
55
+ "created_at": "2017-05-11T17:21:34",
56
+ "provisioning_status": "ACTIVE",
57
+ "monitor_address": null,
58
+ "updated_at": "2017-05-11T17:21:37",
59
+ "address": "192.0.2.16",
60
+ "protocol_port": 80,
61
+ "id": "957a1ace-1bd2-449b-8455-820b6e4b63f3",
62
+ "operating_status": "NO_MONITOR",
63
+ "tags": ["test_tag"]
64
+ }
65
+ }
66
+ JSON
67
+ headers: {'Content-Type' => 'application/json'}
68
+ )
69
+
70
+ assert_instance_of(Yao::LoadBalancerPoolMember, pool.members.first)
71
+ assert_equal("957a1ace-1bd2-449b-8455-820b6e4b63f3", pool.members.first.id)
72
+ assert_equal("web-server-1", pool.members.first.name)
73
+ assert_requested(stub)
74
+
75
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail,show-listener-details-detail,show-pool-details-detail#show-listener-details
76
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/listeners/023f2e34-7806-443b-bfae-16c324569a3d")
77
+ .to_return(
78
+ status: 200,
79
+ body: <<-JSON,
80
+ {
81
+ "listener": {
82
+ "description": "A great TLS listener",
83
+ "admin_state_up": true,
84
+ "project_id": "e3cd678b11784734bc366148aa37580e",
85
+ "protocol": "TERMINATED_HTTPS",
86
+ "protocol_port": 443,
87
+ "provisioning_status": "ACTIVE",
88
+ "default_tls_container_ref": "http://198.51.100.10:9311/v1/containers/a570068c-d295-4780-91d4-3046a325db51",
89
+ "loadbalancers": [
90
+ {
91
+ "id": "607226db-27ef-4d41-ae89-f2a800e9c2db"
92
+ }
93
+ ],
94
+ "insert_headers": {
95
+ "X-Forwarded-Port": "true",
96
+ "X-Forwarded-For": "true"
97
+ },
98
+ "created_at": "2017-02-28T00:42:44",
99
+ "updated_at": "2017-02-28T00:44:30",
100
+ "id": "023f2e34-7806-443b-bfae-16c324569a3d",
101
+ "operating_status": "ONLINE",
102
+ "default_pool_id": "ddb2b28f-89e9-45d3-a329-a359c3e39e4a",
103
+ "sni_container_refs": [
104
+ "http://198.51.100.10:9311/v1/containers/a570068c-d295-4780-91d4-3046a325db51",
105
+ "http://198.51.100.10:9311/v1/containers/aaebb31e-7761-4826-8cb4-2b829caca3ee"
106
+ ],
107
+ "l7policies": [
108
+ {
109
+ "id": "5e618272-339d-4a80-8d14-dbc093091bb1"
110
+ }
111
+ ],
112
+ "name": "great_tls_listener",
113
+ "timeout_client_data": 50000,
114
+ "timeout_member_connect": 5000,
115
+ "timeout_member_data": 50000,
116
+ "timeout_tcp_inspect": 0,
117
+ "tags": ["test_tag"],
118
+ "client_ca_tls_container_ref": "http://198.51.100.10:9311/v1/containers/35649991-49f3-4625-81ce-2465fe8932e5",
119
+ "client_authentication": "MANDATORY",
120
+ "client_crl_container_ref": "http://198.51.100.10:9311/v1/containers/e222b065-b93b-4e2a-9a02-804b7a118c3c",
121
+ "allowed_cidrs": [
122
+ "192.0.2.0/24",
123
+ "198.51.100.0/24"
124
+ ],
125
+ "tls_ciphers": "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256",
126
+ "tls_versions": ["TLSv1.2", "TLSv1.3"],
127
+ "alpn_protocols": ["http/1.1", "http/1.0"]
128
+ }
129
+ }
130
+ JSON
131
+ headers: {'Content-Type' => 'application/json'}
132
+ )
133
+ assert_instance_of(Yao::LoadBalancerListener, pool.listeners.first)
134
+ assert_equal("023f2e34-7806-443b-bfae-16c324569a3d", pool.listeners.first.id)
135
+ assert_equal("great_tls_listener", pool.listeners.first.name)
136
+ assert_requested(stub)
137
+
138
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail,show-listener-details-detail,show-pool-details-detail,show-health-monitor-details-detail#show-health-monitor-details
139
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/healthmonitors/8ed3c5ac-6efa-420c-bedb-99ba14e58db5")
140
+ .to_return(
141
+ status: 200,
142
+ body: <<-JSON,
143
+ {
144
+ "healthmonitor": {
145
+ "project_id": "e3cd678b11784734bc366148aa37580e",
146
+ "name": "super-pool-health-monitor",
147
+ "admin_state_up": true,
148
+ "pools": [
149
+ {
150
+ "id": "4029d267-3983-4224-a3d0-afb3fe16a2cd"
151
+ }
152
+ ],
153
+ "created_at": "2017-05-11T23:53:47",
154
+ "provisioning_status": "ACTIVE",
155
+ "updated_at": "2017-05-11T23:53:47",
156
+ "delay": 10,
157
+ "expected_codes": "200",
158
+ "max_retries": 1,
159
+ "http_method": "GET",
160
+ "timeout": 5,
161
+ "max_retries_down": 3,
162
+ "url_path": "/",
163
+ "type": "HTTP",
164
+ "id": "8ed3c5ac-6efa-420c-bedb-99ba14e58db5",
165
+ "operating_status": "ONLINE",
166
+ "tags": ["test_tag"],
167
+ "http_version": 1.0,
168
+ "domain_name": null
169
+ }
170
+ }
171
+ JSON
172
+ headers: {'Content-Type' => 'application/json'}
173
+ )
174
+ assert_instance_of(Yao::LoadBalancerHealthMonitor, pool.healthmonitor)
175
+ assert_equal("8ed3c5ac-6efa-420c-bedb-99ba14e58db5", pool.healthmonitor.id)
176
+ assert_equal("super-pool-health-monitor", pool.healthmonitor.name)
177
+ assert_requested(stub)
33
178
  end
34
179
  end
@@ -88,13 +88,13 @@ class TestMeter < TestYaoResource
88
88
  assert_requested(stub)
89
89
  end
90
90
 
91
- def test_tenant
92
- stub = stub_request(:get, "https://example.com:12345/tenants/00000000-0000-0000-0000-000000000000")
91
+ def test_project
92
+ stub = stub_request(:get, "https://example.com:12345/projects/00000000-0000-0000-0000-000000000000")
93
93
  .to_return(
94
94
  status: 200,
95
95
  body: <<-JSON,
96
96
  {
97
- "tenant": {
97
+ "project": {
98
98
  "id": "00000000-0000-0000-0000-000000000000"
99
99
  }
100
100
  }
@@ -107,8 +107,8 @@ class TestMeter < TestYaoResource
107
107
  }
108
108
 
109
109
  meter = Yao::Meter.new(params)
110
- assert_instance_of(Yao::Tenant, meter.tenant)
111
- assert_equal("00000000-0000-0000-0000-000000000000", meter.tenant.id)
110
+ assert_instance_of(Yao::Project, meter.project)
111
+ assert_equal("00000000-0000-0000-0000-000000000000", meter.project.id)
112
112
 
113
113
  assert_requested(stub)
114
114
  end
@@ -37,14 +37,14 @@ class TestNetwork < TestYaoResource
37
37
  assert_equal(1000, network.segmentation_id)
38
38
  end
39
39
 
40
- def test_tenant
40
+ def test_project
41
41
 
42
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
42
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
43
43
  .to_return(
44
44
  status: 200,
45
45
  body: <<-JSON,
46
46
  {
47
- "tenant": {
47
+ "project": {
48
48
  "id": "0123456789abcdef0123456789abcdef"
49
49
  }
50
50
  }
@@ -57,9 +57,9 @@ class TestNetwork < TestYaoResource
57
57
  "tenant_id" => "0123456789abcdef0123456789abcdef",
58
58
  )
59
59
 
60
- assert_instance_of(Yao::Tenant, network.tenant)
61
- assert_instance_of(Yao::Tenant, network.project)
62
- assert_equal('0123456789abcdef0123456789abcdef', network.tenant.id)
60
+ assert_instance_of(Yao::Project, network.tenant)
61
+ assert_instance_of(Yao::Project, network.project)
62
+ assert_equal('0123456789abcdef0123456789abcdef', network.project.id)
63
63
 
64
64
  assert_requested(stub)
65
65
  end
@@ -77,14 +77,14 @@ class TestPort < TestYaoResource
77
77
  assert_equal("10.0.0.1", port.primary_ip)
78
78
  end
79
79
 
80
- def test_tenant
80
+ def test_project
81
81
 
82
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
82
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
83
83
  .to_return(
84
84
  status: 200,
85
85
  body: <<-JSON,
86
86
  {
87
- "tenant": {
87
+ "project": {
88
88
  "id": "0123456789abcdef0123456789abcdef"
89
89
  }
90
90
  }
@@ -92,9 +92,9 @@ class TestPort < TestYaoResource
92
92
  headers: {'Content-Type' => 'application/json'}
93
93
  )
94
94
 
95
- port = Yao::Port.new('tenant_id' => '0123456789abcdef0123456789abcdef')
96
- assert_instance_of(Yao::Tenant, port.tenant)
97
- assert_equal('0123456789abcdef0123456789abcdef', port.tenant.id)
95
+ port = Yao::Port.new('project_id' => '0123456789abcdef0123456789abcdef')
96
+ assert_instance_of(Yao::Project, port.project)
97
+ assert_equal('0123456789abcdef0123456789abcdef', port.project.id)
98
98
 
99
99
  assert_requested(stub)
100
100
  end
@@ -1,9 +1,4 @@
1
1
  class TestProject < TestYaoResource
2
- def setup
3
- super
4
- Yao.default_client.admin_pool["identity"] = Yao::Client.gen_client("https://example.com:12345/v2.0")
5
- end
6
-
7
2
  # https://docs.openstack.org/api-ref/identity/v3/?expanded=list-projects-detail#projects
8
3
  def test_project
9
4
  params = {
@@ -273,4 +268,29 @@ class TestProject < TestYaoResource
273
268
  usage = project.server_usage
274
269
  assert_equal(1024, usage["total_memory_mb_usage"])
275
270
  end
271
+
272
+ def test_role_assignment
273
+ project_id = 'aaaa166533fd49f3b11b1cdce2430000'
274
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?scope.project.id=#{project_id}").
275
+ to_return(
276
+ status: 200,
277
+ body: <<-JSON,
278
+ {
279
+ "role_assignments": [{
280
+ "scope": {
281
+ "project": {
282
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
283
+ }
284
+ }
285
+ }]
286
+ }
287
+ JSON
288
+ headers: {'Content-Type' => 'application/json'}
289
+ )
290
+
291
+ project = Yao::Project.new('id' => project_id)
292
+ role_assignment = project.role_assignment
293
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
294
+ assert_requested(stub)
295
+ end
276
296
  end
@@ -1,6 +1,18 @@
1
1
  class TestRestfullyAccesible < Test::Unit::TestCase
2
2
  include RestfullyAccessibleStub
3
3
  class Test
4
+ def initialize(data_via_json)
5
+ @data = data_via_json
6
+ end
7
+
8
+ def id
9
+ @data['id']
10
+ end
11
+
12
+ def name
13
+ @data['name']
14
+ end
15
+
4
16
  class << self
5
17
  attr_accessor :client
6
18
  end
@@ -45,7 +57,7 @@ class TestRestfullyAccesible < Test::Unit::TestCase
45
57
 
46
58
  stub_get_request_not_found([@url, @resources_name, name].join('/'))
47
59
  stub_get_request([@url, "#{@resources_name}?name=dummy"].join('/'), @resources_name)
48
- mock(Test).new("dummy_resource") { Struct.new(:id).new(uuid) }
60
+ mock(Test).new("dummy_resource") { Struct.new(:id, :name).new(uuid, name) }
49
61
  stub_get_request([@url, @resources_name, uuid].join('/'), @resources_name)
50
62
  mock(Test).new("dummy_resource") { "OK" }
51
63
 
@@ -60,7 +72,7 @@ class TestRestfullyAccesible < Test::Unit::TestCase
60
72
 
61
73
  stub_get_request_not_found([@url, @resources_name, name].join('/'))
62
74
  stub_get_request_with_json_response([@url, "#{@resources_name}?name=dummy"].join('/'), body)
63
- mock(Test).new("dummy_resources") { Struct.new(:id).new(uuid) }
75
+ mock(Test).new("dummy_resources") { Struct.new(:id, :name).new(uuid, name) }
64
76
  stub_get_request([@url, @resources_name, uuid].join('/'), @resource_name)
65
77
  mock(Test).new("dummy_resource") { "OK" }
66
78
 
@@ -84,8 +96,17 @@ class TestRestfullyAccesible < Test::Unit::TestCase
84
96
 
85
97
  sub_test_case 'get!' do
86
98
  test 'not found' do
87
- stub_get_request_not_found("https://example.com/dummy_resource")
88
- assert_equal(nil, Test.get!("https://example.com/dummy_resource"))
99
+ Test.return_single_on_querying = false
100
+ name = "dummy"
101
+ uuid = "00112233-4455-6677-8899-aabbccddeeff"
102
+ body = {@resources_name => []}
103
+
104
+ stub1 = stub_get_request_not_found([@url, @resources_name, name].join('/'))
105
+ stub2 = stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), body)
106
+
107
+ assert_equal(nil, Test.get!(name))
108
+ assert_requested(stub1)
109
+ assert_requested(stub2)
89
110
  end
90
111
 
91
112
  test 'found' do
@@ -103,6 +124,23 @@ class TestRestfullyAccesible < Test::Unit::TestCase
103
124
  end
104
125
  end
105
126
 
127
+ sub_test_case 'get_by_name' do
128
+ test 'multiple found' do
129
+ name = 'dummy'
130
+ uuid = '00112233-4455-6677-8899-aabbccddeeff'
131
+ list_body = { @resources_name => [
132
+ { 'name' => 'dummy', 'id' => uuid },
133
+ { 'name' => 'dummy2', 'id' => '308cb410-9c84-40ec-a3eb-583001aaa7fd' }
134
+ ]}
135
+ get_body = { @resource_name => { 'name' => 'dummy', 'id' => uuid } }
136
+ stub1 = stub_get_request_not_found([@url, @resources_name, name].join('/'))
137
+ stub2 = stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), list_body)
138
+ stub3 = stub_get_request_with_json_response([@url, @resources_name, name].join('/'), get_body)
139
+
140
+ assert_equal(uuid, Test.send(:get_by_name, 'dummy').body[@resource_name]['id'])
141
+ end
142
+ end
143
+
106
144
  def test_find_by_name
107
145
  mock(Test).list({"name" => "dummy"}) { "dummy" }
108
146
 
@@ -116,4 +154,8 @@ class TestRestfullyAccesible < Test::Unit::TestCase
116
154
  assert_equal(false, Test.send(:uuid?, "dummy resource"))
117
155
  assert_equal(false, Test.send(:uuid?, "00112233445566778899aabbccddeeff"))
118
156
  end
157
+
158
+ def test_delete
159
+ assert_equal(Test.method(:delete), Test.method(:destroy))
160
+ end
119
161
  end
@@ -32,13 +32,110 @@ class TestRoleAssignment < TestYaoResource
32
32
  assert_equal("313233", role_assignment.user.id)
33
33
  end
34
34
 
35
+ def test_list
36
+ stub = stub_request(:get, "https://example.com:12345/role_assignments").
37
+ to_return(
38
+ status: 200,
39
+ body: <<-JSON,
40
+ {
41
+ "role_assignments": [{
42
+ "scope": {
43
+ "project": {
44
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
45
+ }
46
+ }
47
+ }]
48
+ }
49
+ JSON
50
+ headers: {'Content-Type' => 'application/json'}
51
+ )
52
+ role_assignment = Yao::RoleAssignment.list
53
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
54
+ assert_requested(stub)
55
+ end
56
+
57
+ def test_get_user
58
+ user_id = '123456'
59
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?user.id=#{user_id}").
60
+ to_return(
61
+ status: 200,
62
+ body: <<-JSON,
63
+ {
64
+ "role_assignments": [{
65
+ "scope": {
66
+ "project": {
67
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
68
+ }
69
+ }
70
+ }]
71
+ }
72
+ JSON
73
+ headers: {'Content-Type' => 'application/json'}
74
+ )
75
+
76
+ user = Yao::User.new('id' => user_id)
77
+ role_assignment = Yao::RoleAssignment.get(user: user)
78
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
79
+ assert_requested(stub)
80
+ end
81
+
82
+ def test_get_project
83
+ project_id = 'aaaa166533fd49f3b11b1cdce2430000'
84
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?scope.project.id=#{project_id}").
85
+ to_return(
86
+ status: 200,
87
+ body: <<-JSON,
88
+ {
89
+ "role_assignments": [{
90
+ "scope": {
91
+ "project": {
92
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
93
+ }
94
+ }
95
+ }]
96
+ }
97
+ JSON
98
+ headers: {'Content-Type' => 'application/json'}
99
+ )
100
+
101
+ project = Yao::Project.new('id' => project_id)
102
+ role_assignment = Yao::RoleAssignment.get(project: project)
103
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
104
+ assert_requested(stub)
105
+ end
106
+
107
+ def test_get_tenant
108
+ tenant_id = 'aaaa166533fd49f3b11b1cdce2430000'
109
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?scope.project.id=#{tenant_id}").
110
+ to_return(
111
+ status: 200,
112
+ body: <<-JSON,
113
+ {
114
+ "role_assignments": [{
115
+ "scope": {
116
+ "project": {
117
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
118
+ }
119
+ }
120
+ }]
121
+ }
122
+ JSON
123
+ headers: {'Content-Type' => 'application/json'}
124
+ )
125
+
126
+ tenant = Yao::Project.new('id' => tenant_id)
127
+ role_assignment = Yao::RoleAssignment.get(tenant: tenant)
128
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
129
+ assert_requested(stub)
130
+ end
131
+
35
132
  def test_project
36
- stub = stub_request(:get, "http://example.com:12345/tenants/456789").
133
+ stub = stub_request(:get, "https://example.com:12345/projects/456789").
37
134
  to_return(
38
135
  status: 200,
39
136
  body: <<-JSON,
40
137
  {
41
- "tenant": {
138
+ "project": {
42
139
  "id": "456789"
43
140
  }
44
141
  }
@@ -55,7 +152,7 @@ class TestRoleAssignment < TestYaoResource
55
152
  }
56
153
 
57
154
  role_assignment = Yao::RoleAssignment.new(params)
58
- assert_instance_of(Yao::Resources::Tenant, role_assignment.project)
155
+ assert_instance_of(Yao::Project, role_assignment.project)
59
156
  assert_equal("456789", role_assignment.project.id)
60
157
 
61
158
  assert_requested(stub)