diff options
author | Martyn Taylor <mtaylor@redhat.com> | 2014-01-02 11:46:06 +0000 |
---|---|---|
committer | Martyn Taylor <mtaylor@redhat.com> | 2014-02-12 12:45:28 +0000 |
commit | ea72bcb23a4c4af158fb8bfc2b9163cf4c9191ab (patch) | |
tree | 6e0cc4a01a9754ccb67abcbb2d372c836e322d30 | |
parent | 7eb48adc825c0b2ee4884de31e23caaca082022c (diff) | |
download | ironic-ea72bcb23a4c4af158fb8bfc2b9163cf4c9191ab.tar.gz |
Remove POST calls in tests for resource creation
Removes all unnecessary POST calls in tests setup. Any resources needed in
test setup are now created with a direct call to the DB API.
Change-Id: I2b19eeb25e563a658eaf375c8ae83dec9ff68deb
Closes-Bug: #1261398
-rw-r--r-- | ironic/tests/api/test_chassis.py | 23 | ||||
-rw-r--r-- | ironic/tests/api/test_nodes.py | 28 | ||||
-rw-r--r-- | ironic/tests/api/test_ports.py | 40 |
3 files changed, 49 insertions, 42 deletions
diff --git a/ironic/tests/api/test_chassis.py b/ironic/tests/api/test_chassis.py index b6a1d5237..28f35c739 100644 --- a/ironic/tests/api/test_chassis.py +++ b/ironic/tests/api/test_chassis.py @@ -146,7 +146,7 @@ class TestPatch(base.FunctionalTest): def setUp(self): super(TestPatch, self).setUp() cdict = dbutils.get_test_chassis() - self.post_json('/chassis', cdict) + self.dbapi.create_chassis(cdict) self.addCleanup(timeutils.clear_time_override) def test_update_not_found(self): @@ -178,8 +178,9 @@ class TestPatch(base.FunctionalTest): def test_replace_multi(self): extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"} cdict = dbutils.get_test_chassis(extra=extra, - uuid=utils.generate_uuid()) - self.post_json('/chassis', cdict) + uuid=utils.generate_uuid(), + id=None) + self.dbapi.create_chassis(cdict) new_value = 'new value' response = self.patch_json('/chassis/%s' % cdict['uuid'], [{'path': '/extra/foo2', @@ -193,8 +194,9 @@ class TestPatch(base.FunctionalTest): def test_remove_singular(self): cdict = dbutils.get_test_chassis(extra={'a': 'b'}, - uuid=utils.generate_uuid()) - self.post_json('/chassis', cdict) + uuid=utils.generate_uuid(), + id=None) + self.dbapi.create_chassis(cdict) response = self.patch_json('/chassis/%s' % cdict['uuid'], [{'path': '/description', 'op': 'remove'}]) self.assertEqual('application/json', response.content_type) @@ -209,8 +211,9 @@ class TestPatch(base.FunctionalTest): def test_remove_multi(self): extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"} cdict = dbutils.get_test_chassis(extra=extra, description="foobar", - uuid=utils.generate_uuid()) - self.post_json('/chassis', cdict) + uuid=utils.generate_uuid(), + id=None) + self.dbapi.create_chassis(cdict) # Removing one item from the collection response = self.patch_json('/chassis/%s' % cdict['uuid'], @@ -312,7 +315,7 @@ class TestPost(base.FunctionalTest): def test_post_nodes_subresource(self): cdict = dbutils.get_test_chassis() - self.post_json('/chassis', cdict) + self.dbapi.create_chassis(cdict) ndict = dbutils.get_test_node(chassis_id=None) ndict['chassis_uuid'] = cdict['uuid'] response = self.post_json('/chassis/nodes', ndict, @@ -344,7 +347,7 @@ class TestDelete(base.FunctionalTest): def test_delete_chassis(self): cdict = dbutils.get_test_chassis() - self.post_json('/chassis', cdict) + self.dbapi.create_chassis(cdict) self.delete('/chassis/%s' % cdict['uuid']) response = self.get_json('/chassis/%s' % cdict['uuid'], expect_errors=True) @@ -372,7 +375,7 @@ class TestDelete(base.FunctionalTest): def test_delete_nodes_subresource(self): cdict = dbutils.get_test_chassis() - self.post_json('/chassis', cdict) + self.dbapi.create_chassis(cdict) response = self.delete('/chassis/%s/nodes' % cdict['uuid'], expect_errors=True) self.assertEqual(403, response.status_int) diff --git a/ironic/tests/api/test_nodes.py b/ironic/tests/api/test_nodes.py index 4f3a1eb0c..52110cea4 100644 --- a/ironic/tests/api/test_nodes.py +++ b/ironic/tests/api/test_nodes.py @@ -552,8 +552,8 @@ class TestPost(base.FunctionalTest): self.assertTrue(response.json['error_message']) def test_vendor_passthru_ok(self): - ndict = post_get_test_node() - self.post_json('/nodes', ndict) + ndict = dbutils.get_test_node() + self.dbapi.create_node(ndict) uuid = ndict['uuid'] info = {'foo': 'bar'} @@ -568,8 +568,8 @@ class TestPost(base.FunctionalTest): self.assertEqual(202, response.status_code) def test_vendor_passthru_no_such_method(self): - ndict = post_get_test_node() - self.post_json('/nodes', ndict) + ndict = dbutils.get_test_node() + self.dbapi.create_node(ndict) uuid = ndict['uuid'] info = {'foo': 'bar'} @@ -586,8 +586,8 @@ class TestPost(base.FunctionalTest): self.assertEqual(400, response.status_code) def test_vendor_passthru_without_method(self): - ndict = post_get_test_node() - self.post_json('/nodes', ndict) + ndict = dbutils.get_test_node() + self.dbapi.create_node(ndict) response = self.post_json('/nodes/%s/vendor_passthru' % ndict['uuid'], {'foo': 'bar'}, expect_errors=True) self.assertEqual('application/json', response.content_type, ) @@ -595,8 +595,8 @@ class TestPost(base.FunctionalTest): self.assertTrue(response.json['error_message']) def test_post_ports_subresource(self): - ndict = post_get_test_node() - self.post_json('/nodes', ndict) + ndict = dbutils.get_test_node() + self.dbapi.create_node(ndict) pdict = dbutils.get_test_port(node_id=None) pdict['node_uuid'] = ndict['uuid'] response = self.post_json('/nodes/ports', pdict, @@ -635,8 +635,8 @@ class TestDelete(base.FunctionalTest): self.chassis = self.dbapi.create_chassis(cdict) def test_delete_node(self): - ndict = post_get_test_node() - self.post_json('/nodes', ndict) + ndict = dbutils.get_test_node() + self.dbapi.create_node(ndict) self.delete('/nodes/%s' % ndict['uuid']) response = self.get_json('/nodes/%s' % ndict['uuid'], expect_errors=True) @@ -645,16 +645,16 @@ class TestDelete(base.FunctionalTest): self.assertTrue(response.json['error_message']) def test_delete_ports_subresource(self): - ndict = post_get_test_node() - self.post_json('/nodes', ndict) + ndict = dbutils.get_test_node() + self.dbapi.create_node(ndict) response = self.delete('/nodes/%s/ports' % ndict['uuid'], expect_errors=True) self.assertEqual(403, response.status_int) def test_delete_associated(self): - ndict = post_get_test_node( + ndict = dbutils.get_test_node( instance_uuid='aaaaaaaa-1111-bbbb-2222-cccccccccccc') - self.post_json('/nodes', ndict) + self.dbapi.create_node(ndict) response = self.delete('/nodes/%s' % ndict['uuid'], expect_errors=True) self.assertEqual(409, response.status_int) diff --git a/ironic/tests/api/test_ports.py b/ironic/tests/api/test_ports.py index 750db7de5..54b8a4627 100644 --- a/ironic/tests/api/test_ports.py +++ b/ironic/tests/api/test_ports.py @@ -135,8 +135,8 @@ class TestPatch(base.FunctionalTest): super(TestPatch, self).setUp() ndict = dbutils.get_test_node() self.node = self.dbapi.create_node(ndict) - self.pdict = post_get_test_port() - self.post_json('/ports', self.pdict) + self.pdict = dbutils.get_test_port(id=None) + self.dbapi.create_port(self.pdict) self.addCleanup(timeutils.clear_time_override) def test_update_byid(self): @@ -185,13 +185,15 @@ class TestPatch(base.FunctionalTest): self.assertEqual(address, result['address']) def test_replace_address_already_exist(self): - pdict1 = post_get_test_port(address='AA:AA:AA:AA:AA:AA', - uuid=utils.generate_uuid()) - self.post_json('/ports', pdict1) + pdict1 = dbutils.get_test_port(address='aa:aa:aa:aa:aa:aa', + uuid=utils.generate_uuid(), + id=None) + self.dbapi.create_port(pdict1) - pdict2 = post_get_test_port(address='BB:BB:BB:BB:BB:BB', - uuid=utils.generate_uuid()) - self.post_json('/ports', pdict2) + pdict2 = dbutils.get_test_port(address='bb:bb:bb:bb:bb:bb', + uuid=utils.generate_uuid(), + id=None) + self.dbapi.create_port(pdict2) response = self.patch_json('/ports/%s' % pdict1['uuid'], [{'path': '/address', @@ -214,10 +216,11 @@ class TestPatch(base.FunctionalTest): def test_replace_multi(self): extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"} - pdict = post_get_test_port(extra=extra, + pdict = dbutils.get_test_port(extra=extra, address="AA:BB:CC:DD:EE:FF", uuid=utils.generate_uuid()) - self.post_json('/ports', pdict) + self.dbapi.create_port(pdict) + new_value = 'new value' response = self.patch_json('/ports/%s' % pdict['uuid'], [{'path': '/extra/foo2', @@ -231,10 +234,10 @@ class TestPatch(base.FunctionalTest): def test_remove_multi(self): extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"} - pdict = post_get_test_port(extra=extra, + pdict = dbutils.get_test_port(extra=extra, address="aa:bb:cc:dd:ee:ff", uuid=utils.generate_uuid()) - self.post_json('/ports', pdict) + self.dbapi.create_port(pdict) # Removing one item from the collection response = self.patch_json('/ports/%s' % pdict['uuid'], @@ -266,9 +269,10 @@ class TestPatch(base.FunctionalTest): self.assertTrue(response.json['error_message']) def test_remove_mandatory_field(self): - pdict = post_get_test_port(address="AA:BB:CC:DD:EE:FF", + pdict = dbutils.get_test_port(address="AA:BB:CC:DD:EE:FF", uuid=utils.generate_uuid()) - self.post_json('/ports', pdict) + self.dbapi.create_port(pdict) + response = self.patch_json('/ports/%s' % pdict['uuid'], [{'path': '/address', 'op': 'remove'}], expect_errors=True) @@ -306,9 +310,9 @@ class TestPatch(base.FunctionalTest): self.assertTrue(response.json['error_message']) def test_update_address_invalid_format(self): - pdict = post_get_test_port(address="AA:BB:CC:DD:EE:FF", + pdict = dbutils.get_test_port(address="AA:BB:CC:DD:EE:FF", uuid=utils.generate_uuid()) - self.post_json('/ports', pdict) + self.dbapi.create_port(pdict) response = self.patch_json('/ports/%s' % pdict['uuid'], [{'path': '/address', 'value': 'invalid-format', @@ -451,8 +455,8 @@ class TestDelete(base.FunctionalTest): super(TestDelete, self).setUp() ndict = dbutils.get_test_node() self.node = self.dbapi.create_node(ndict) - pdict = post_get_test_port() - self.post_json('/ports', pdict) + pdict = dbutils.get_test_port() + self.dbapi.create_port(pdict) def test_delete_port_byid(self): pdict = dbutils.get_test_port() |