def test_includes_expected_fields(self): variable, value, operator = self.txt(), self.txt(), EqualityOperator() check = Check(variable, value, operator) self.assertEqual( {"variable": variable, "value": value, "operator": operator.SYMBOL}, check.to_dict(), )
def test_calls_operator_with_correct_arguments(self): initial_value = self.txt() operator = MagicMock(return_value=True) check = Check(self.txt(), initial_value, operator) compared_value = self.txt() check.check(compared_value) operator.compare.assert_called_once_with(compared_value, initial_value)
def test_includes_expected_fields(self): variable, value, operator = self.txt(), self.txt(), EqualityOperator() json = {"variable": variable, "value": value, "operator": operator.SYMBOL} check = Check.from_dict(json) self.assertEqual(json, check.to_dict())
def test_returns_instance_of_set_membership_operator(self): check = Check.factory("foo__in", [1]) self.assertIsInstance(check.operator, SetMembershipOperator)
def test_returns_instance_of_negation_operator(self): check = Check.factory("foo__ne", 1) self.assertIsInstance(check.operator, NegationOperator)
def test_returns_instance_of_less_than_or_equal_to_operator(self): check = Check.factory("foo__lte", 1) self.assertIsInstance(check.operator, LessThanOrEqualToOperator)
def test_returns_instance_of_greater_than_or_equal_to_operator(self): check = Check.factory("foo__gte", 1) self.assertIsInstance(check.operator, GreaterThanOrEqualToOperator)
def test_returns_instance_of_equality_operator(self): check = Check.factory("foo", 1) self.assertIsInstance(check.operator, EqualityOperator)
def test_returns_instance_of_check(self): check = Check.factory("foo", 1) self.assertIsInstance(check, Check)
def test_returns_variable_only_when_operator_is_none(self): variable, operator = self.txt(), None key = Check.make_check_key(variable, operator) self.assertEqual(variable, key)
def test_returns_variable_and_operator_with_delimiter(self): variable, operator = self.txt(), "gt" key = Check.make_check_key(variable, operator) self.assertEqual(OPERATOR_DELIMITER.join([variable, operator]), key)