From bb1e31104032390533a3b4f669fbfe62d42f03d8 Mon Sep 17 00:00:00 2001 From: Malini Kamalambal Date: Thu, 19 May 2016 15:44:40 -0400 Subject: [PATCH] Added config option to skip hypothesis tests. Change-Id: I98a30c72db2a3da4b01c55133123370caa8b61d1 --- tests/api/services/test_analytics.py | 56 +++++++++++++++++++++++++++- tests/api/utils/config.py | 5 +++ tests/etc/api.conf | 1 + 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/tests/api/services/test_analytics.py b/tests/api/services/test_analytics.py index 1c4db9d1..41978206 100644 --- a/tests/api/services/test_analytics.py +++ b/tests/api/services/test_analytics.py @@ -129,6 +129,60 @@ class TestAnalytics(base.TestBase): elif metric_type == 'httpResponseCode_5XX': self.assertSchema(body, analytics.get_httpResponseCode_5XX) + def tearDown(self): + self.client.delete_service(location=self.location) + + if self.test_config.generate_flavors: + self.client.delete_flavor(flavor_id=self.flavor_id) + + super(TestAnalytics, self).tearDown() + + +@ddt.ddt +class TestAnalyticsHypothesis(base.TestBase): + + """Hypothesis Tests for Analytics.""" + + def setUp(self): + super(TestAnalyticsHypothesis, self).setUp() + + if self.test_config.run_hypothesis_tests is False: + self.skipTest( + 'Hypothesis Tests are disabled in configuration') + + self.flavor_id = self.test_flavor + service_name = str(uuid.uuid1()) + + self.domain = self.generate_random_string( + prefix='www.api-test-domain') + '.com' + self.domain_list = [{"domain": self.domain}] + + self.origin_list = [{"origin": self.generate_random_string( + prefix='api-test-origin') + '.com', "port": 80, "ssl": False, + "hostheadertype": "custom", "hostheadervalue": + "www.customweb.com"}] + + self.caching_list = [{"name": "default", "ttl": 3600}, + {"name": "home", "ttl": 1200, + "rules": [{"name": "index", + "request_url": "/index.htm"}]}] + self.log_delivery = {"enabled": False} + + resp = self.client.create_service(service_name=service_name, + domain_list=self.domain_list, + origin_list=self.origin_list, + caching_list=self.caching_list, + flavor_id=self.flavor_id, + log_delivery=self.log_delivery) + + self.location = resp.headers["location"] + self.client.wait_for_service_status( + location=self.location, + status='deployed', + abort_on_status='failed', + retry_interval=self.test_config.status_check_retry_interval, + retry_timeout=self.test_config.status_check_retry_timeout) + @hypothesis.given(strategies.text()) def test_analytics_negative_metric_type(self, metric_type): end_time = datetime.datetime.now() @@ -180,4 +234,4 @@ class TestAnalytics(base.TestBase): if self.test_config.generate_flavors: self.client.delete_flavor(flavor_id=self.flavor_id) - super(TestAnalytics, self).tearDown() + super(TestAnalyticsHypothesis, self).tearDown() diff --git a/tests/api/utils/config.py b/tests/api/utils/config.py index 4388a88d..4638b330 100644 --- a/tests/api/utils/config.py +++ b/tests/api/utils/config.py @@ -82,6 +82,11 @@ class TestConfig(data_interfaces.ConfigSectionInterface): """Flag to indicate if positive tests for SSL cert should run.""" return self.get_boolean('run_ssl_tests') + @property + def run_hypothesis_tests(self): + """Flag to indicate if the hypothesis tests should run.""" + return self.get_boolean('run_hypothesis_tests') + @property def cassandra_consistency_wait_time(self): """Int value in seconds to wait for cassandra consistency.""" diff --git a/tests/etc/api.conf b/tests/etc/api.conf index 84965329..4005dafd 100644 --- a/tests/etc/api.conf +++ b/tests/etc/api.conf @@ -32,6 +32,7 @@ default_flavor=standard generated_provider=fastly project_id_in_url=False run_ssl_tests=False +run_hypothesis_tests=False cassandra_consistency_wait_time=5 [dns]