Merge "empty non-string values are returned as string traits"

This commit is contained in:
Jenkins 2015-05-07 00:33:12 +00:00 committed by Gerrit Code Review
commit b89972d74f
2 changed files with 19 additions and 3 deletions

View File

@ -320,13 +320,13 @@ class Connection(base.Connection):
for id_, key, t_date, t_int, t_float, t_text in (
trait_q.order_by('2')).all():
if t_int:
if t_int is not None:
dtype = api_models.Trait.INT_TYPE
val = t_int
elif t_float:
elif t_float is not None:
dtype = api_models.Trait.FLOAT_TYPE
val = t_float
elif t_date:
elif t_date is not None:
dtype = api_models.Trait.DATETIME_TYPE
val = t_date
else:

View File

@ -3668,6 +3668,22 @@ class GetEventTest(EventTestBase):
self.assertTrue(events)
self.assertEqual({'status': {'nested': 'started'}}, events[0].raw)
def test_trait_type_enforced_on_none(self):
new_events = [event_models.Event(
"id_testid", "MessageIDTest", self.start,
[event_models.Trait('text', event_models.Trait.TEXT_TYPE, ''),
event_models.Trait('int', event_models.Trait.INT_TYPE, 0),
event_models.Trait('float', event_models.Trait.FLOAT_TYPE, 0.0)],
{})]
self.event_conn.record_events(new_events)
event_filter = storage.EventFilter(message_id="id_testid")
events = [event for event in self.event_conn.get_events(event_filter)]
options = [(event_models.Trait.TEXT_TYPE, ''),
(event_models.Trait.INT_TYPE, 0.0),
(event_models.Trait.FLOAT_TYPE, 0.0)]
for trait in events[0].traits:
options.remove((trait.dtype, trait.value))
class BigIntegerTest(tests_db.TestBase,
tests_db.MixinTestsWithBackendScenarios):