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
This commit is contained in:
Victor Stinner 2015-06-16 00:07:52 +02:00
parent 54b114c428
commit 5087b255bb
3 changed files with 3 additions and 2 deletions

View File

@ -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)

View File

@ -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}}}'

View File

@ -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 \