def test_expression_resolves_condition(self): expression = Expression('(a = 1)') conditions = expression.to_conditions() self.assertEqual('a', conditions.conditions[0].key) self.assertEqual('=', conditions.conditions[0].operator) self.assertEqual('1', conditions.conditions[0].value)
def test_expression_resolves_nested_compound_condition(self): expression = Expression('(a = 1 or (b = 2 and c = 3))') conditions = expression.to_conditions() self.assertEqual('or', conditions.conditions[1].value) self.assertEqual('c', conditions.conditions[2][2].key) self.assertEqual('=', conditions.conditions[2][2].operator) self.assertEqual('3', conditions.conditions[2][2].value)
def test_expression_resolves_compound_condition(self): expression = Expression('(a = 1 and b = 2)') conditions = expression.to_conditions() self.assertEqual('and', conditions.conditions[1].value) self.assertEqual('b', conditions.conditions[2].key) self.assertEqual('=', conditions.conditions[2].operator) self.assertEqual('2', conditions.conditions[2].value)
def test_that_we_can_filter_todo_by_status_and_date(self): subject = TodoRepository(self.logger, self.database) conditions = Expression( '(status = done and date between 2020-09-21,2020-09-23)' ).to_conditions() todos = subject.fetch_todos(conditions) self.assertEqual(1, len(todos))
def handle(self, command): expression = Expression(command.filter) conditions = expression.to_conditions() return self.todo_repository.fetch_todos(conditions)
def test_expression_raises_badly_terminated_error(self): expression = Expression('(a = 1 or (b = 2 and c = 3)) or') with self.assertRaises(ExpressionBadlyTerminated): expression.to_conditions()
def test_expression_raises_badly_formatted_error(self): expression = Expression('(a = 1 and or (b = 2 and c = 3))') with self.assertRaises(ExpressionBadlyFormatted): expression.to_conditions()