def test_accepted_count_returns_number_of_accepted_violations(self): violation_one = get_violation(key="123", acceptable=models.ViolationStatus.rejected) violation_two = get_violation(key="ABC", acceptable=models.ViolationStatus.rejected) violation_three = get_violation(key="XYZ", acceptable=models.ViolationStatus.accepted) violation_queryset = [violation_one, violation_two, violation_three] violations = models.ViolationsWrapper(violation_queryset) self.assertEqual(2, violations.rejected_count)
def test_unreviewed_property_returns_unreviewed_violations(self): violation_one = get_violation(key="123", acceptable=models.ViolationStatus.unreviewed) violation_two = get_violation(key="ABC", acceptable=models.ViolationStatus.unreviewed) violation_three = get_violation(key="XYZ", acceptable=models.ViolationStatus.rejected) violation_queryset = [violation_one, violation_two, violation_three] violations = models.ViolationsWrapper(violation_queryset) self.assertEqual([violation_one, violation_two], violations.unreviewed)
def test_iterating_over_wrapper_iterates_over_queryset(self): violation_one = get_violation(key="123") violation_two = get_violation(key="ABC") violation_queryset = [violation_one, violation_two] violations = models.ViolationsWrapper(violation_queryset) for qs, v in zip(violation_queryset, violations): self.assertEqual(qs, v)
def test_save_violation_updates_message_when_violation_already_exists(self): violation = get_violation(message="A new message") existing_violation = get_violation(message="An old message") violation2 = mock.Mock(spec_set=models.Violation()) self.action.save_violations([existing_violation], [violation, violation2]) self.assertEqual(violation.message, existing_violation.message) existing_violation.save.assert_called_once_with()
def test_violations_are_not_equal_when_other_object_is_not_violation_model(self): violation = get_violation() self.assertNotEqual(violation, rule_models.Rule())
def test_violations_are_not_equal_when_violated_fields_doesnt_match(self): violation_one = get_violation(violated_fields={"a_value": 99}) violation_two = get_violation() self.assertNotEqual(violation_two, violation_one)
def test_violations_are_not_equal_when_validation_object_id_doesnt_match(self): violation_one = get_violation(trigger_model_id=99) violation_two = get_violation() self.assertNotEqual(violation_two, violation_one)
def test_violations_are_not_equal_when_content_type_doesnt_match(self): violation_one = get_violation(trigger_content_type=ContentType(pk=99)) violation_two = get_violation() self.assertNotEqual(violation_two, violation_one)
def test_violations_are_not_equal_when_rule_doesnt_match(self): violation_one = get_violation(rule=rule_models.Rule(pk=99)) violation_two = get_violation() self.assertNotEqual(violation_two, violation_one)
def test_violations_are_not_equal_when_key_doesnt_match(self): violation_one = get_violation(key="123") violation_two = get_violation() self.assertNotEqual(violation_two, violation_one)
def test_violations_are_equal_when_validation_object_rule_key_and_fields_match(self): violation_one = get_violation(pk=1) violation_two = get_violation() self.assertEqual(violation_two, violation_one)
def test_max_level_is_ok_when_only_accepted(self): violation_one = get_violation(key="123", acceptable=models.ViolationStatus.accepted) violation_two = get_violation(key="ABC", acceptable=models.ViolationStatus.accepted) violation_queryset = [violation_one, violation_two] violations = models.ViolationsWrapper(violation_queryset) self.assertEqual("ok", violations.max_level)
def test_max_level_is_warn_when_no_rejected_but_has_unreviewed(self): violation_one = get_violation(key="123", acceptable=models.ViolationStatus.unreviewed) violation_two = get_violation(key="ABC", acceptable=models.ViolationStatus.accepted) violation_queryset = [violation_one, violation_two] violations = models.ViolationsWrapper(violation_queryset) self.assertEqual("warn", violations.max_level)
def test_max_level_is_error_when_has_rejected_violations(self): violation_one = get_violation(key="123", acceptable=models.ViolationStatus.rejected) violation_two = get_violation(key="ABC", acceptable=models.ViolationStatus.unreviewed) violation_queryset = [violation_one, violation_two] violations = models.ViolationsWrapper(violation_queryset) self.assertEqual("error", violations.max_level)