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, {})
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"])
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, {})
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'])
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')
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')
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')
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')
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, {})
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, {})
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"])
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'])
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'})
def test_validate_date_with_success(self): validator = SchemaValidator() validator._validate_type_date('test1', '2017-11-22T22:11:33+0000') self.assertEqual(validator._errors, {})
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"])
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"}))
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'}))
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'])