def test_numeric_bucket(self): self.assertEqual( str(Reducer.numeric_bucket('e.properties.x', {'a': 1})), 'mixpanel.reducer.numeric_bucket(function(e){return e.properties.x}, {\'a\': 1})') self.assertEqual( str(Reducer.numeric_bucket('e.properties.x', [1, 2, 3])), 'mixpanel.reducer.numeric_bucket(function(e){return e.properties.x}, [1, 2, 3])') self.assertEqual( str(Reducer.numeric_bucket(raw('e.properties.x'), {'a': 1})), 'mixpanel.reducer.numeric_bucket(e.properties.x, {\'a\': 1})') self.assertEqual( str(Reducer.numeric_bucket(raw('e.properties.x'), [1, 2, 3])), 'mixpanel.reducer.numeric_bucket(e.properties.x, [1, 2, 3])') with self.assertRaises(JQLSyntaxError): Reducer.numeric_bucket(raw('e.properties.x'), 'a')
def _test(self, reducer, expected_function): self.assertEqual( str(reducer('e.properties.some_accessor')), 'mixpanel.reducer.%s(function(e){' 'return e.properties.some_accessor})' % expected_function) self.assertEqual( str(reducer(raw('"a"'))), 'mixpanel.reducer.%s("a")' % expected_function)
def test_numeric_percentiles(self): self.assertEqual( str(Reducer.numeric_percentiles('e.properties.x', 1)), 'mixpanel.reducer.numeric_percentiles(function(e){return e.properties.x}, 1)') self.assertEqual( str(Reducer.numeric_percentiles('e.properties.x', [1, 2, 3])), 'mixpanel.reducer.numeric_percentiles(function(e){return e.properties.x}, [1, 2, 3])') self.assertEqual( str(Reducer.numeric_percentiles(raw('e.properties.x'), 1)), 'mixpanel.reducer.numeric_percentiles(e.properties.x, 1)') self.assertEqual( str(Reducer.numeric_percentiles(raw('e.properties.x'), [1, 2, 3])), 'mixpanel.reducer.numeric_percentiles(e.properties.x, [1, 2, 3])') with self.assertRaises(JQLSyntaxError): Reducer.numeric_percentiles(raw('e.properties.x'), [1, 2, 'a']) with self.assertRaises(JQLSyntaxError): Reducer.numeric_percentiles(raw('e.properties.x'), 'meow')
def _test(self, manipulator, expected_function): manipulator = getattr(self.query, manipulator) self.assertEqual( str(manipulator('e.properties.some_accessor')), 'function main() { return Events({}).' '%s(function(e){' 'return e.properties.some_accessor}); }' % expected_function) self.assertEqual( str(manipulator(raw('"a"'))), 'function main() { return Events({}).%s("a"); }' % expected_function)
def _test(self, grouper, expected_function): grouper = getattr(self.query, grouper) self.assertEqual( str(grouper(['e.a', 'e.b', 'e.c'], 'e.properties.some_accessor')), 'function main() { return Events({}).' '%s([' 'function(e){return e.a}, function(e){return e.b}, function(e){return e.c}' '], function(e){return e.properties.some_accessor}); }' % expected_function) self.assertEqual( str( grouper([raw('e.a'), raw('e.b'), raw('e.c')], raw('e.properties.some_accessor'))), 'function main() { return Events({}).' '%s([e.a, e.b, e.c], e.properties.some_accessor); }' % expected_function) # Non iterable key. self.assertEqual( str(grouper(raw('e.a'), raw('e.properties.some_accessor'))), 'function main() { return Events({}).' '%s([e.a], e.properties.some_accessor); }' % expected_function)
def test_auto_function(self): self.assertEqual(_f(raw("test")), "test") self.assertEqual(_f("test"), "function(e){return test}")