def test_simple_expressions(self): e = Expression('name') self.assertEqual('name', e.name)
def test_none_expression(self): with self.assertRaises(ValueError): e = Expression(None)
def test_blank_expression(self): with self.assertRaises(ValueError): e = Expression('')
def test_evaluate(self): obj = Dummy(id=1, name='NAME_1', flag=True, link=Dummy(id=2, name='NAME_2'), objects=EmbeddedManager([ Dummy(id=3, name='NAME_3'), Dummy(id=4, name='NAME_4'), Dummy(id=5, name='NAME_5'), ])) e_id = Expression('id') e_name = Expression('name') e_flag = Expression('flag') e_link = Expression('link') e_link_id = Expression('link.id') e_link_name = Expression('link.name') e_objects = Expression('objects') self.assertEqual(1, e_id.evaluate(obj)) self.assertEqual('NAME_1', e_name.evaluate(obj)) self.assertEqual(True, e_flag.evaluate(obj)) self.assertEqual(2, e_link.evaluate(obj).id) self.assertEqual('NAME_2', e_link.evaluate(obj).name) self.assertEqual(2, e_link_id.evaluate(obj)) self.assertEqual('NAME_2', e_link_name.evaluate(obj)) self.assertEqual(3, e_objects.evaluate(obj).all()[0].id) self.assertEqual('NAME_3', e_objects.evaluate(obj).all()[0].name) self.assertEqual(4, e_objects.evaluate(obj).all()[1].id) self.assertEqual('NAME_4', e_objects.evaluate(obj).all()[1].name) self.assertEqual(5, e_objects.evaluate(obj).all()[2].id) self.assertEqual('NAME_5', e_objects.evaluate(obj).all()[2].name)