Esempio n. 1
0
    def test_validate_mandatory_in_list(self):
        validator = SchemaValidator()
        mandatory = {
            "scheme": {
                "custom_subject": {
                    "required": True
                },
                "category": {
                    "required": True
                }
            }
        }
        field = "scheme"
        value = [
            {
                "name": "DiDFødselsdag",
                "qcode": "DiDFødselsdag",
                "scheme": "category",
                "service": {
                    "d": 1,
                    "i": 1
                }
            },
            {
                "name": "arkeologi",
                "qcode": "01001000",
                "scheme": "custom_subject",
                "parent": "01000000"
            },
        ]
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator.errors, {})
Esempio n. 2
0
 def test_fail_validate_mandatory_in_list_for_subject(self):
     mandatory = {
         "scheme": {
             "custom_subject": {
                 "required": True
             },
             "category": {
                 "required": True
             }
         }
     }
     value = [{
         "name": "DiDFødselsdag",
         "qcode": "DiDFødselsdag",
         "scheme": "category",
         "service": {
             "d": 1,
             "i": 1
         }
     }]
     doc = {"subject": value}
     schema = {"subject": {"type": "list", "mandatory_in_list": mandatory}}
     validator = SchemaValidator(schema)
     self.assertFalse(validator.validate(doc))
     self.assertIn("is a required field",
                   validator.errors["custom_subject"])
Esempio n. 3
0
    def test_validate_mandatory_in_list(self):
        validator = SchemaValidator()
        mandatory = {
            'scheme': {
                'subject': 'subject_custom',
                'category': 'category'
            }
        }
        field = 'scheme'
        value = [{
            'name': 'DiDFødselsdag',
            'qcode': 'DiDFødselsdag',
            'scheme': 'category',
            'service': {
                'd': 1,
                'i': 1
            }
        }, {
            'name': 'arkeologi',
            'qcode': '01001000',
            'scheme': 'subject_custom',
            'parent': '01000000'
        }]
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors, {})
Esempio n. 4
0
 def test_fail_validate_mandatory_in_list_for_subject(self):
     mandatory = {
         'scheme': {
             'custom_subject': {
                 "required": True
             },
             'category': {
                 "required": True
             }
         }
     }
     value = [{
         'name': 'DiDFødselsdag',
         'qcode': 'DiDFødselsdag',
         'scheme': 'category',
         'service': {
             'd': 1,
             'i': 1
         }
     }]
     doc = {'subject': value}
     schema = {'subject': {'type': 'list', 'mandatory_in_list': mandatory}}
     validator = SchemaValidator(schema)
     self.assertFalse(validator.validate(doc))
     self.assertIn('is a required field',
                   validator.errors['custom_subject'])
Esempio n. 5
0
    def test_fail_validate_mandatory_in_list_for_subject_and_category(self):
        validator = SchemaValidator()
        mandatory = {"scheme": {"subject": "custom_subject", "category": "category"}}
        field = "scheme"
        value = []
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors['subject'], 'is a required field')
        self.assertEqual(validator._errors['category'], 'is a required field')
Esempio n. 6
0
    def test_fail_validate_mandatory_in_list_for_subject(self):
        validator = SchemaValidator()
        mandatory = {"scheme": {"subject": "custom_subject", "category": "category"}}
        field = "scheme"
        value = [{"name": "DiDFødselsdag", "qcode": "DiDFødselsdag",
                  "scheme": "category", "service": {"d": 1, "i": 1}}]
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors['subject'], 'is a required field')
Esempio n. 7
0
    def test_fail_validate_mandatory_in_list_for_subject(self):
        validator = SchemaValidator()
        mandatory = {'scheme': {'subject': 'custom_subject', 'category': 'category'}}
        field = 'scheme'
        value = [{'name': 'DiDFødselsdag', 'qcode': 'DiDFødselsdag',
                  'scheme': 'category', 'service': {'d': 1, 'i': 1}}]
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors['subject'], 'is a required field')
Esempio n. 8
0
    def test_fail_validate_mandatory_in_list_for_subject(self):
        validator = SchemaValidator()
        mandatory = {'scheme': {'subject': 'custom_subject', 'category': 'category'}}
        field = 'scheme'
        value = [{'name': 'DiDFødselsdag', 'qcode': 'DiDFødselsdag',
                  'scheme': 'category', 'service': {'d': 1, 'i': 1}}]
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors['subject'], 'is a required field')
Esempio n. 9
0
    def test_fail_validate_mandatory_in_list_for_subject_and_category(self):
        validator = SchemaValidator()
        mandatory = {'scheme': {'subject': 'custom_subject', 'category': 'category'}}
        field = 'scheme'
        value = []
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors['subject'], 'is a required field')
        self.assertEqual(validator._errors['category'], 'is a required field')
Esempio n. 10
0
    def test_fail_validate_mandatory_in_list_for_subject_and_category(self):
        validator = SchemaValidator()
        mandatory = {'scheme': {'subject': 'custom_subject', 'category': 'category'}}
        field = 'scheme'
        value = []
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors['subject'], 'is a required field')
        self.assertEqual(validator._errors['category'], 'is a required field')
Esempio n. 11
0
    def test_validate_mandatory_in_list(self):
        validator = SchemaValidator()
        mandatory = {"scheme": {"subject": "subject_custom", "category": "category"}}
        field = "scheme"
        value = [{"name": "DiDFødselsdag", "qcode": "DiDFødselsdag",
                  "scheme": "category", "service": {"d": 1, "i": 1}},
                 {"name": "arkeologi", "qcode": "01001000", "scheme": "subject_custom", "parent": "01000000"}]
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors, {})
Esempio n. 12
0
    def test_validate_mandatory_in_list(self):
        validator = SchemaValidator()
        mandatory = {'scheme': {'subject': 'subject_custom', 'category': 'category'}}
        field = 'scheme'
        value = [{'name': 'DiDFødselsdag', 'qcode': 'DiDFødselsdag',
                  'scheme': 'category', 'service': {'d': 1, 'i': 1}},
                 {'name': 'arkeologi', 'qcode': '01001000', 'scheme': 'subject_custom', 'parent': '01000000'}]
        validator._validate_mandatory_in_list(mandatory, field, value)

        self.assertEqual(validator._errors, {})
Esempio n. 13
0
 def test_fail_validate_mandatory_in_list_for_subject_and_category(self):
     mandatory = {
         "scheme": {
             "custom_subject": {
                 "required": True
             },
             "category": {
                 "required": True
             }
         }
     }
     doc = {"subject": []}
     schema = {"subject": {"type": "list", "mandatory_in_list": mandatory}}
     validator = SchemaValidator(schema)
     self.assertFalse(validator.validate(doc))
     self.assertIn("is a required field",
                   validator.errors["custom_subject"])
     self.assertIn("is a required field", validator.errors["category"])
Esempio n. 14
0
 def test_fail_validate_mandatory_in_list_for_subject_and_category(self):
     mandatory = {
         'scheme': {
             'custom_subject': {
                 "required": True
             },
             'category': {
                 "required": True
             }
         }
     }
     doc = {'subject': []}
     schema = {'subject': {'type': 'list', 'mandatory_in_list': mandatory}}
     validator = SchemaValidator(schema)
     self.assertFalse(validator.validate(doc))
     self.assertIn('is a required field',
                   validator.errors['custom_subject'])
     self.assertIn('is a required field', validator.errors['category'])
Esempio n. 15
0
 def test_validate_date_with_error(self):
     validator = SchemaValidator()
     validator._validate_type_date('test1', '2017-11-33T22:11:33+0000')
     self.assertEqual(validator._errors, {'test1': 'require a date value'})
Esempio n. 16
0
 def test_validate_date_with_success(self):
     validator = SchemaValidator()
     validator._validate_type_date('test1', '2017-11-22T22:11:33+0000')
     self.assertEqual(validator._errors, {})
Esempio n. 17
0
 def test_validate_date_with_success(self):
     validator = SchemaValidator()
     validator._validate_type_date('test1', '2017-11-22T22:11:33+0000')
     self.assertEqual(validator._errors, {})
Esempio n. 18
0
 def test_validate_date_with_error(self):
     validator = SchemaValidator()
     validator._validate_type_date('test1', '2017-11-33T22:11:33+0000')
     self.assertEqual(validator._errors, {'test1': 'require a date value'})
Esempio n. 19
0
 def test_validate_date_with_error(self):
     validator = SchemaValidator({"test": {"type": "date"}})
     self.assertFalse(
         validator.validate({"test": "2017-11-33T22:11:33+0000"}))
     self.assertIn("must be of date type", validator.errors["test"])
Esempio n. 20
0
 def test_validate_date_with_success(self):
     validator = SchemaValidator({"test": {"type": "date"}})
     print("mapping", validator.types_mapping)
     self.assertTrue(
         validator.validate({"test": "2017-11-22T22:11:33+0000"}))
Esempio n. 21
0
 def test_validate_date_with_success(self):
     validator = SchemaValidator({'test': {'type': 'date'}})
     print('mapping', validator.types_mapping)
     self.assertTrue(
         validator.validate({'test': '2017-11-22T22:11:33+0000'}))
Esempio n. 22
0
 def test_validate_date_with_error(self):
     validator = SchemaValidator({'test': {'type': 'date'}})
     self.assertFalse(
         validator.validate({'test': '2017-11-33T22:11:33+0000'}))
     self.assertIn('must be of date type', validator.errors['test'])