Esempio n. 1
0
 def test_filters(self):
     e1 = EventExpression('request', 'elapsed_ms').eq('path', '/')
     e2 = e1.gt('elapsed_ms', 500)
     self.assertEqual("%s" % Sum(e1),
             "sum(request(elapsed_ms).eq(path, \"/\"))")
     self.assertEqual("%s" % Sum(e2),
             "sum(request(elapsed_ms).eq(path, \"/\").gt(elapsed_ms, 500))")
Esempio n. 2
0
    def test_in_array(self):
        e = EventExpression('test')
        f = e.in_array('foo', ['bar', 'baz'])
        self.assertEqual("%s" % f, 'test.in(foo, ["bar", "baz"])')

        f = e.in_array('foo', 'bar')
        self.assertEqual("%s" % f, 'test.in(foo, ["b", "a", "r"])')
Esempio n. 3
0
 def test_copy(self):
     e1 = EventExpression('request', ['path', 'elapsed_ms'])
     e2 = e1.copy()
     self.assertEqual(e1, e2)
     e1 = e1.eq('path', '/')
     e3 = e1.copy()
     self.assertNotEqual(e1, e2)
     self.assertEqual(e1, e3)
     self.assertNotEqual(e2, e3)
Esempio n. 4
0
 def test_filter_chaining(self):
     e = EventExpression('test')
     e = e.eq('bar', 'baz')
     self.assertTrue(isinstance(e, EventExpression))
     self.assertEqual(len(e.filters), 1)
     e = e.lt('fizz', 'bang')
     self.assertTrue(isinstance(e, EventExpression))
     self.assertEqual(len(e.filters), 2)
     e = e.ge('foo', 4)
     self.assertTrue(isinstance(e, EventExpression))
     self.assertEqual(len(e.filters), 3)
     self.assertEqual("%s" % e,
             'test.eq(bar, "baz").lt(fizz, "bang").ge(foo, 4)')
Esempio n. 5
0
    def test_equality(self):
        e1 = EventExpression('request')
        m1 = MetricExpression('sum', e1)
        m2 = MetricExpression('sum', e1)
        self.assertEqual(m1, m2)

        e2 = EventExpression('other')
        m2 = MetricExpression('sum', e2)
        self.assertNotEqual(m1, m2)

        m1 = MetricExpression('sum', e2)
        self.assertEqual(m1, m2)

        m1 = MetricExpression('min', e2)
        self.assertNotEqual(m1, m2)

        m2 = MetricExpression('min', e2)
        self.assertEqual(m1, m2)
Esempio n. 6
0
 def expression(self, event_properties):
     return EventExpression(self.event_type, event_properties)
Esempio n. 7
0
 def test_contains(self):
     e = EventExpression('test')
     f = e.contains('foo', 'bar')
     self.assertEqual("%s" % f, 'test.re(foo, ".*bar.*")')
Esempio n. 8
0
 def test_endswith(self):
     e = EventExpression('test')
     f = e.endswith('foo', 'bar')
     self.assertEqual("%s" % f, 'test.re(foo, ".*bar$")')
Esempio n. 9
0
 def test_startswith(self):
     e = EventExpression('test')
     f = e.startswith('foo', 'bar')
     self.assertEqual("%s" % f, 'test.re(foo, "^bar")')
Esempio n. 10
0
 def test_invalid_params(self):
     self.assertRaisesRegexp(ValueError,
             "Events for Metrics may only select a single event property",
             Sum, EventExpression('request', ['path', 'user_id']))
     self.assertRaises(TypeError, Sum)
Esempio n. 11
0
 def setUp(self):
     self.e = EventExpression('request')
Esempio n. 12
0
 def setUp(self):
     self.e = EventExpression('test', 'ing')
     self.sum = Sum(self.e)
     self.max = Max(self.e)
     self.min = Min(self.e)