From 5087b255bb327342ad525e619df88ebffaef11c1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 16 Jun 2015 00:07:52 +0200 Subject: [PATCH] Port test_complex_query to Python 3 * query.py: the message attribute of Exception was removed in Python 3, replace e.message with e to format the new error message * Fix test_complex_query_scenarios: convert sample_item["metadata"]["util"] to float; "0.5" >= 0.5 is True in Python 2, but it raises a TypeError on Python 3. * tox.ini: add the following API v2 tests to Python 3.4: - test_complex_query_scenarios.TestQueryMetersController.test_query_with_volume_field_name_orderby Change-Id: I112e5564a65db005cf66ce967a8ac3e52fa95267 --- ceilometer/api/controllers/v2/query.py | 2 +- ceilometer/tests/api/v2/test_complex_query_scenarios.py | 2 +- tox.ini | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ceilometer/api/controllers/v2/query.py b/ceilometer/api/controllers/v2/query.py index c9348072..3826294f 100644 --- a/ceilometer/api/controllers/v2/query.py +++ b/ceilometer/api/controllers/v2/query.py @@ -216,7 +216,7 @@ class ValidatedComplexQuery(object): self._validate_orderby(self.orderby) except (ValueError, jsonschema.exceptions.ValidationError) as e: raise base.ClientSideError( - _("Order-by expression not valid: %s") % e.message) + _("Order-by expression not valid: %s") % e) self._convert_orderby_to_lower_case(self.orderby) self._normalize_field_names_in_orderby(self.orderby) diff --git a/ceilometer/tests/api/v2/test_complex_query_scenarios.py b/ceilometer/tests/api/v2/test_complex_query_scenarios.py index 809167f1..f2a048a6 100644 --- a/ceilometer/tests/api/v2/test_complex_query_scenarios.py +++ b/ceilometer/tests/api/v2/test_complex_query_scenarios.py @@ -293,7 +293,7 @@ class TestQueryMetersController(tests_api.FunctionalTest, self.assertEqual(2, len(data.json)) for sample_item in data.json: - self.assertTrue(sample_item["metadata"]["util"] >= 0.5) + self.assertTrue(float(sample_item["metadata"]["util"]) >= 0.5) def test_filter_with_negation(self): filter_expr = '{"not": {">=": {"metadata.util": 0.5}}}' diff --git a/tox.ini b/tox.ini index 8097260e..4b5c4767 100644 --- a/tox.ini +++ b/tox.ini @@ -50,6 +50,7 @@ commands = python -m testtools.run \ ceilometer.tests.api.v2.test_alarm_scenarios.TestAlarms.test_alarms_query_with_timestamp \ ceilometer.tests.api.v2.test_alarm_scenarios.TestAlarms.test_get_alarm_history_constrained_by_alarm_id_failed \ ceilometer.tests.api.v2.test_app \ + ceilometer.tests.api.v2.test_complex_query_scenarios.TestQueryMetersController.test_query_with_volume_field_name_orderby \ ceilometer.tests.api.v2.test_complex_query_scenarios.TestQueryMetersController.test_query_with_isotime \ ceilometer.tests.api.v2.test_event_scenarios.TestEventAPI.test_get_events_filter_datetime_trait \ ceilometer.tests.api.v2.test_list_meters_scenarios.TestListMeters.test_query_samples_with_invalid_field_name_and_eq_operator \