def test_match_type(self):
     config = dict(event_type=["test.foo.bar", "!test.wakka.wakka"])
     criteria = definition.Criteria(config)
     self.assertTrue(criteria.match_type('test.foo.bar'))
     self.assertFalse(criteria.match_type('test.wakka.wakka'))
     self.assertFalse(criteria.match_type('test.foo.baz'))
     config = dict(event_type=["test.foo.*", "!test.wakka.*"])
     criteria = definition.Criteria(config)
     self.assertTrue(criteria.match_type('test.foo.bar'))
     self.assertTrue(criteria.match_type('test.foo.baz'))
     self.assertFalse(criteria.match_type('test.wakka.wakka'))
 def test_event_type_configs(self):
     config = dict(event_type="test.foo.bar")
     criteria = definition.Criteria(config)
     self.assertEqual(len(criteria.included_types), 1)
     self.assertEqual(len(criteria.excluded_types), 0)
     self.assertEqual(criteria.included_types[0], 'test.foo.bar')
     config = dict(event_type="!test.foo.bar")
     criteria = definition.Criteria(config)
     self.assertEqual(len(criteria.included_types), 1)
     self.assertEqual(len(criteria.excluded_types), 1)
     self.assertEqual(criteria.included_types[0], '*')
     self.assertEqual(criteria.excluded_types[0], 'test.foo.bar')
     config = dict(event_type=["test.foo.bar", "!test.wakka.wakka"])
     criteria = definition.Criteria(config)
     self.assertEqual(len(criteria.included_types), 1)
     self.assertEqual(len(criteria.excluded_types), 1)
     self.assertEqual(criteria.included_types[0], 'test.foo.bar')
     self.assertEqual(criteria.excluded_types[0], 'test.wakka.wakka')
 def test_defaults(self):
     criteria = definition.Criteria({})
     self.assertEqual(len(criteria.included_types), 1)
     self.assertEqual(len(criteria.excluded_types), 0)
     self.assertEqual(criteria.included_types[0], '*')
     self.assertEqual(criteria.number, 1)
     self.assertIsNone(criteria.timestamp)
     self.assertEqual(len(criteria.map_distinguished_by), 0)
     self.assertEqual(len(criteria.traits), 0)
 def test_match_for_type(self):
     config = dict(event_type=["test.foo.*", "!test.wakka.*"])
     criteria = definition.Criteria(config)
     event1 = dict(event_type="test.foo.zazz")
     event2 = dict(event_type="test.wakka.zazz")
     event3 = dict(event_type="test.boingy")
     self.assertTrue(criteria.match(event1, self.fake_group))
     self.assertFalse(criteria.match(event2, self.fake_group))
     self.assertFalse(criteria.match(event3, self.fake_group))
 def test_match_for_traits(self):
     config = dict(traits=dict(some_trait="test",
                               launched_at={'datetime': "day"},
                               memory_mb={'int': "> 2048"},
                               test_weight={'float': "< 4.02"},
                               other_trait={'string': 'text here'}))
     criteria = definition.Criteria(config)
     event1 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 1, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 1, 1, 2, 3, 4),
                   some_trait='test',
                   other_trait='text here',
                   memory_mb=4096,
                   test_weight=3.1415)
     event2 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 1, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 1, 1, 2, 3, 4),
                   some_trait='foo',
                   other_trait='text here',
                   memory_mb=4096,
                   test_weight=3.1415)
     event3 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 1, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 1, 1, 2, 3, 4),
                   other_trait='text here',
                   memory_mb=4096,
                   test_weight=3.1415)
     event4 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 1, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 2, 1, 2, 3, 4),
                   some_trait='test',
                   other_trait='text here',
                   memory_mb=4096,
                   test_weight=3.1415)
     event5 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 1, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 1, 1, 2, 3, 4),
                   some_trait='test',
                   other_trait='text here',
                   memory_mb=1024,
                   test_weight=3.1415)
     event6 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 1, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 1, 1, 2, 3, 4),
                   some_trait='test',
                   other_trait='text here',
                   memory_mb=4096,
                   test_weight=6.283)
     self.assertTrue(criteria.match(event1, self.fake_group))
     self.assertFalse(criteria.match(event2, self.fake_group))
     self.assertFalse(criteria.match(event3, self.fake_group))
     self.assertFalse(criteria.match(event4, self.fake_group))
     self.assertFalse(criteria.match(event5, self.fake_group))
     self.assertFalse(criteria.match(event6, self.fake_group))
 def test_match_for_timestamp(self):
     config = dict(timestamp='day($launched_at)')
     criteria = definition.Criteria(config)
     event1 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 1, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 1, 1, 2, 3, 4))
     event2 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 2, 17, 16, 15, 14),
                   launched_at=datetime.datetime(2014, 8, 1, 1, 2, 3, 4))
     event3 = dict(event_type='test.thing',
                   timestamp=datetime.datetime(2014, 8, 2, 17, 16, 15, 14))
     self.assertTrue(criteria.match(event1, self.fake_group))
     self.assertFalse(criteria.match(event2, self.fake_group))
     self.assertFalse(criteria.match(event3, self.fake_group))