From 4e6fa2fc29b3f86f8a90bc3bb0c9b2a03966cde6 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 11 Mar 2015 17:08:10 -0500 Subject: [PATCH] check some responses in functional tests before using the resp This should make potential functional test failures more clear. Change-Id: Iac67dbcc90459eb0455114a520a7e8ea0bb504b2 --- .../api/v1/behaviors/consumer_behaviors.py | 2 +- functionaltests/api/v1/functional/test_orders.py | 2 +- functionaltests/api/v1/functional/test_secrets.py | 4 ++++ functionaltests/api/v1/smoke/test_orders.py | 12 ++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/functionaltests/api/v1/behaviors/consumer_behaviors.py b/functionaltests/api/v1/behaviors/consumer_behaviors.py index 1fe72b494..f6fdb1326 100644 --- a/functionaltests/api/v1/behaviors/consumer_behaviors.py +++ b/functionaltests/api/v1/behaviors/consumer_behaviors.py @@ -36,7 +36,7 @@ class ConsumerBehaviors(base_behaviors.BaseBehaviors): extra_headers=extra_headers) returned_data = self.get_json(resp) - consumer_data = returned_data['consumers'] + consumer_data = returned_data.get('consumers') return resp, consumer_data diff --git a/functionaltests/api/v1/functional/test_orders.py b/functionaltests/api/v1/functional/test_orders.py index d1954c6ee..9b9432f17 100644 --- a/functionaltests/api/v1/functional/test_orders.py +++ b/functionaltests/api/v1/functional/test_orders.py @@ -159,6 +159,7 @@ class OrdersTestCase(base.TestCase): self.assertEqual(resp.status_code, 202) order_resp = self.behaviors.get_order(order_ref) + self.assertEqual(order_resp.status_code, 200) # PENDING orders may take a moment to be processed by the workers # when running tests with queue enabled @@ -253,7 +254,6 @@ class OrdersTestCase(base.TestCase): test_model.meta['payload_content_encoding'] = "blarg!" resp, order_ref = self.behaviors.create_order(test_model) - print(resp.content) # Make sure we actually get a message back error_msg = json.loads(resp.content).get('title') diff --git a/functionaltests/api/v1/functional/test_secrets.py b/functionaltests/api/v1/functional/test_secrets.py index 01bad9618..981986c59 100644 --- a/functionaltests/api/v1/functional/test_secrets.py +++ b/functionaltests/api/v1/functional/test_secrets.py @@ -100,6 +100,7 @@ class SecretsTestCase(base.TestCase): self.assertEqual(resp.status_code, 201) resp = self.behaviors.get_secret_metadata(secret_ref) + self.assertEqual(resp.status_code, 200) content_types = resp.model.content_types self.assertIsNotNone(content_types) self.assertIn('default', content_types) @@ -381,6 +382,7 @@ class SecretsTestCase(base.TestCase): secret_ref, payload_content_type=test_model.payload_content_type, payload_content_encoding=test_model.payload_content_encoding) + self.assertEqual(get_resp.status_code, 200) self.assertIn(test_model.payload, binascii.b2a_base64(get_resp.content)) @@ -591,6 +593,7 @@ class SecretsTestCase(base.TestCase): secret_ref, payload_content_type=test_model.payload_content_type, payload_content_encoding=payload_content_encoding) + self.assertEqual(get_resp.status_code, 200) if payload_content_encoding == 'base64': self.assertIn(test_model.payload, @@ -630,6 +633,7 @@ class SecretsTestCase(base.TestCase): secret_ref, payload_content_type=test_model.payload_content_type, payload_content_encoding=payload_content_encoding) + self.assertEqual(get_resp.status_code, 200) if payload_content_encoding == 'base64': self.assertIn(test_model.payload, diff --git a/functionaltests/api/v1/smoke/test_orders.py b/functionaltests/api/v1/smoke/test_orders.py index ac5d6cd1b..ed2e7ca7e 100644 --- a/functionaltests/api/v1/smoke/test_orders.py +++ b/functionaltests/api/v1/smoke/test_orders.py @@ -12,6 +12,8 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. +import time + from testtools import testcase from barbican.tests import utils @@ -60,6 +62,14 @@ class OrdersTestCase(base.TestCase): self.behaviors.delete_all_created_orders() super(OrdersTestCase, self).tearDown() + def wait_for_order(self, order_resp, order_ref): + # Make sure we have an active order + time_count = 1 + while order_resp.model.status != "ACTIVE" and time_count <= 4: + time.sleep(1) + time_count += 1 + order_resp = self.behaviors.get_order(order_ref) + @testcase.attr('positive') def test_create_order_defaults(self): """Covers simple order creation.""" @@ -135,6 +145,8 @@ class OrdersTestCase(base.TestCase): # create an order test_model = order_models.OrderModel(**order_create_defaults_data) create_resp, order_ref = self.behaviors.create_order(test_model) + self.assertEqual(create_resp.status_code, 202) + self.assertIsNotNone(order_ref) # delete the order delete_resp = self.behaviors.delete_order(order_ref)