Esempio n. 1
0
    def test_uri_invalid(self):
        validation = ChromaValidation()

        errors = defaultdict(list)

        self.assertTrue(validation.validate_resources([validation.URIInfo("invalid", MockResource)], errors))

        self.assertEqual(errors, {"invalid": ["Resource invalid was not found"]})
Esempio n. 2
0
    def test_uri_valid(self):
        validation = ChromaValidation()

        errors = defaultdict(list)

        self.assertFalse(validation.validate_resources([validation.URIInfo("valid", MockResource)], errors))

        self.assertEqual(errors, {})
Esempio n. 3
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, {})
Esempio n. 4
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']})
Esempio n. 5
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"]})
Esempio n. 6
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, {})