def test_filters(self):
     e1 = EventExpression('request', 'elapsed_ms').eq('path', '/')
     e2 = e1.gt('elapsed_ms', 500)
     self.assertEqual("%s" % (Sum(e1) - Min(e2)),
             "(sum(request(elapsed_ms).eq(path, \"/\")) - "\
             "min(request(elapsed_ms).eq(path, \"/\").gt("\
                 "elapsed_ms, 500)))")
 def test_filters(self):
     e1 = EventExpression('request', 'elapsed_ms').eq('path', '/')
     e2 = e1.gt('elapsed_ms', 500)
     self.assertEqual("%s" % (Sum(e1) - Min(e2)),
             "(sum(request(elapsed_ms).eq(path, \"/\")) - "\
             "min(request(elapsed_ms).eq(path, \"/\").gt("\
                 "elapsed_ms, 500)))")
Exemple #3
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"])')
Exemple #4
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)
Exemple #5
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)')
Exemple #6
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)
Exemple #7
0
    def test_no_matching_events(self):
        mock_response = MockResponse(ok=True,
                                     status_code='200',
                                     content="[]",
                                     json=[])
        Query.get = mock_get(mock_response)

        event = EventExpression('test')
        response = self.c.get_event(event, limit=10)
        self.assertEqual(len(response), 0)
Exemple #8
0
 def _test_filter(self, filter_str):
     e = EventExpression('test')
     self.assertTrue(hasattr(e, filter_str))
     f = getattr(e, filter_str)
     filtered = f('elapsed_ms', 500)
     self.assertTrue(isinstance(filtered, EventExpression))
     self.assertTrue(len(filtered.filters), 1)
     self.assertEqual("%s" % filtered,
             "test.{filter_str}(elapsed_ms, 500)".format(
                 filter_str=filter_str))
Exemple #9
0
 def test_equality(self):
     e1 = EventExpression('request')
     e2 = EventExpression('request')
     self.assertEqual(e1, e2)
     e1 = EventExpression('request', 'path')
     self.assertNotEqual(e1, e2)
     e2 = EventExpression('request', 'path')
     self.assertEqual(e1, e2)
     e1 = EventExpression('request', ['path', 'elapsed_ms'])
     self.assertNotEqual(e1, e2)
     e2 = EventExpression('request', ['path', 'elapsed_ms'])
     self.assertEqual(e1, e2)
     e1 = EventExpression('request', ['path', 'elapsed_ms']).eq('path', '/')
     self.assertNotEqual(e1, e2)
     e2 = EventExpression('request', ['path', 'elapsed_ms']).eq('path', '/')
     self.assertEqual(e1, e2)
     e1 = EventExpression('request', ['path', 'elapsed_ms']).eq(
         'path', '/').gt('elapsed_ms', 500)
     self.assertNotEqual(e1, e2)
     e2 = EventExpression('request', ['path', 'elapsed_ms']).eq(
         'path', '/').gt('elapsed_ms', 500)
     self.assertEqual(e1, e2)
Exemple #10
0
    def test_single_matching_event(self):
        timestamp = datetime.utcnow()
        expected_content = '[{"time":"' + timestamp.isoformat() + '"}]'

        mock_response = MockResponse(ok=True,
                                     status_code='200',
                                     content=expected_content,
                                     json=json.loads(expected_content))
        Query.get = mock_get(mock_response)

        event = EventExpression('test')
        response = self.c.get_event(event, limit=1)
        self.assertEqual(len(response), 1)
        self.assertTrue(isinstance(response[0], Event))
        self.assertEqual(response[0].time, timestamp)
 def setUp(self):
     self.e = EventExpression('test', 'ing')
     self.sum = Sum(self.e)
     self.max = Max(self.e)
     self.min = Min(self.e)
Exemple #12
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)
Exemple #13
0
 def setUp(self):
     self.c = Cube('unittest')
     self.e = EventExpression('request')
Exemple #14
0
 def test_contains(self):
     e = EventExpression('test')
     f = e.contains('foo', 'bar')
     self.assertEqual("%s" % f, 'test.re(foo, ".*bar.*")')
Exemple #15
0
 def test_endswith(self):
     e = EventExpression('test')
     f = e.endswith('foo', 'bar')
     self.assertEqual("%s" % f, 'test.re(foo, ".*bar$")')
Exemple #16
0
 def test_startswith(self):
     e = EventExpression('test')
     f = e.startswith('foo', 'bar')
     self.assertEqual("%s" % f, 'test.re(foo, "^bar")')