Пример #1
0
    def test_items_missing_optional(self):
        validation = ChromaValidation()

        errors = defaultdict(list)

        self.assertFalse(
            validation.validate_object(
                {"field1": 1}, errors, {
                    "field1": ChromaValidation.Expectation(True),
                    "field2": ChromaValidation.Expectation(False)
                }))

        self.assertEqual(errors, {})
Пример #2
0
    def test_items_extra(self):
        validation = ChromaValidation()

        errors = defaultdict(list)

        self.assertTrue(
            validation.validate_object(
                {"field1": 1, "field2": 2, "field3": 3},
                errors,
                {"field1": ChromaValidation.Expectation(True), "field2": ChromaValidation.Expectation(True)},
            )
        )

        self.assertEqual(errors, {"field3": ["Additional field(s) field3 found in data"]})
Пример #3
0
    def test_items_missing(self):
        validation = ChromaValidation()

        errors = defaultdict(list)

        self.assertTrue(
            validation.validate_object(
                {"field1": 1}, errors, {
                    "field1": ChromaValidation.Expectation(True),
                    "field2": ChromaValidation.Expectation(True)
                }))

        self.assertEqual(errors,
                         {'field2': ['Field field2 not present in data']})
Пример #4
0
    def test_items_present(self):
        validation = ChromaValidation()

        errors = defaultdict(list)

        self.assertFalse(
            validation.validate_object(
                {"field1": 1, "field2": 2},
                errors,
                {"field1": ChromaValidation.Expectation(True), "field2": ChromaValidation.Expectation(True)},
            )
        )

        self.assertEqual(errors, {})