Exemplo n.º 1
0
    def test_basic_evaluation(self):
        """Tests for basic function evaluation."""
        # test for no model
        result = evaluate_functions(self.session, None, [])
        self.assertEqual(result, {})

        # test for no functions
        result = evaluate_functions(self.session, self.Person, [])
        self.assertEqual(result, {})

        # test for summing ages
        functions = [{'name': 'sum', 'field': 'age'}]
        result = evaluate_functions(self.session, self.Person, functions)
        self.assertIn('sum__age', result)
        self.assertEqual(result['sum__age'], 102.0)

        # test for multiple functions
        functions = [{
            'name': 'sum',
            'field': 'age'
        }, {
            'name': 'avg',
            'field': 'other'
        }]
        result = evaluate_functions(self.session, self.Person, functions)
        self.assertIn('sum__age', result)
        self.assertEqual(result['sum__age'], 102.0)
        self.assertIn('avg__other', result)
        self.assertEqual(result['avg__other'], 16.2)
Exemplo n.º 2
0
    def test_basic_evaluation(self):
        """Tests for basic function evaluation."""
        # test for no model
        result = evaluate_functions(self.session, None, [])
        assert result == {}

        # test for no functions
        result = evaluate_functions(self.session, self.Person, [])
        assert result == {}

        # test for summing ages
        functions = [{'name': 'sum', 'field': 'age'}]
        result = evaluate_functions(self.session, self.Person, functions)
        assert 'sum__age' in result
        assert result['sum__age'] == 102.0

        # test for multiple functions
        functions = [{
            'name': 'sum',
            'field': 'age'
        }, {
            'name': 'avg',
            'field': 'other'
        }]
        result = evaluate_functions(self.session, self.Person, functions)
        assert 'sum__age' in result
        assert result['sum__age'] == 102.0
        assert 'avg__other' in result
        assert result['avg__other'] == 16.2
Exemplo n.º 3
0
    def test_poorly_defined_functions(self):
        """Tests that poorly defined functions raise errors."""
        # test for unknown field
        functions = [{'name': 'sum', 'field': 'bogus'}]
        with self.assertRaises(AttributeError):
            evaluate_functions(self.session, self.Person, functions)

        # test for unknown function
        functions = [{'name': 'bogus', 'field': 'age'}]
        with self.assertRaises(OperationalError):
            evaluate_functions(self.session, self.Person, functions)
Exemplo n.º 4
0
    def test_poorly_defined_functions(self):
        """Tests that poorly defined functions raise errors."""
        # test for unknown field
        functions = [{'name': 'sum', 'field': 'bogus'}]
        with self.assertRaises(AttributeError):
            evaluate_functions(self.session, self.Person, functions)

        # test for unknown function
        functions = [{'name': 'bogus', 'field': 'age'}]
        with self.assertRaises(OperationalError):
            evaluate_functions(self.session, self.Person, functions)
Exemplo n.º 5
0
    def test_basic_evaluation(self):
        """Tests for basic function evaluation."""
        # test for no model
        result = evaluate_functions(self.session, None, [])
        assert result == {}

        # test for no functions
        result = evaluate_functions(self.session, self.Person, [])
        assert result == {}

        # test for summing ages
        functions = [{'name': 'sum', 'field': 'age'}]
        result = evaluate_functions(self.session, self.Person, functions)
        assert 'sum__age' in result
        assert result['sum__age'] == 102.0

        # test for multiple functions
        functions = [{'name': 'sum', 'field': 'age'},
                     {'name': 'avg', 'field': 'other'}]
        result = evaluate_functions(self.session, self.Person, functions)
        assert 'sum__age' in result
        assert result['sum__age'] == 102.0
        assert 'avg__other' in result
        assert result['avg__other'] == 16.2
Exemplo n.º 6
0
    def test_basic_evaluation(self):
        """Tests for basic function evaluation."""
        # test for no model
        result = evaluate_functions(self.session, None, [])
        self.assertEqual(result, {})

        # test for no functions
        result = evaluate_functions(self.session, self.Person, [])
        self.assertEqual(result, {})

        # test for summing ages
        functions = [{'name': 'sum', 'field': 'age'}]
        result = evaluate_functions(self.session, self.Person, functions)
        self.assertIn('sum__age', result)
        self.assertEqual(result['sum__age'], 102.0)

        # test for multiple functions
        functions = [{'name': 'sum', 'field': 'age'},
                     {'name': 'avg', 'field': 'other'}]
        result = evaluate_functions(self.session, self.Person, functions)
        self.assertIn('sum__age', result)
        self.assertEqual(result['sum__age'], 102.0)
        self.assertIn('avg__other', result)
        self.assertEqual(result['avg__other'], 16.2)
Exemplo n.º 7
0
 def test_count(self):
     """Tests for counting the number of rows in a query."""
     functions = [{'name': 'count', 'field': 'id'}]
     result = evaluate_functions(self.session, self.Person, functions)
     assert 'count__id' in result
     assert result['count__id'] == 5
Exemplo n.º 8
0
 def test_count(self):
     """Tests for counting the number of rows in a query."""
     functions = [{'name': 'count', 'field': 'id'}]
     result = evaluate_functions(self.session, self.Person, functions)
     assert 'count__id' in result
     assert result['count__id'] == 5
Exemplo n.º 9
0
 def test_count(self):
     """Tests for counting the number of rows in a query."""
     functions = [{'name': 'count', 'field': 'id'}]
     result = evaluate_functions(self.session, self.Person, functions)
     self.assertIn('count__id', result)
     self.assertEqual(result['count__id'], 5)
Exemplo n.º 10
0
 def test_count(self):
     """Tests for counting the number of rows in a query."""
     functions = [{'name': 'count', 'field': 'id'}]
     result = evaluate_functions(self.session, self.Person, functions)
     self.assertIn('count__id', result)
     self.assertEqual(result['count__id'], 5)