class TestValidator(InvenioTestCase): def setUp(self): from invenio.modules.jsonalchemy.validator import Validator self.validator = Validator() def tearDown(self): del self.validator def test_objectid(self): """Objectid type validation""" self.validator._validate_type_objectid( '_id', 'abcde12345fabcd67890efab') self.assertEqual(self.validator.errors, {}) self.validator._errors = {} self.validator._validate_type_objectid( '_id', 'abcde-12345-fabcd-67890e') self.assertEqual(self.validator.errors, {'_id': 'must be of ObjectId type'}) def test_uuid(self): """Objectid type validation""" _uuid = str(uuid.uuid4()) self.validator._validate_type_uuid( '_id', _uuid) self.assertEqual(self.validator.errors, {}) self.validator._errors = {} self.validator._validate_type_uuid( '_id', _uuid.replace('-', '_')) self.assertEqual(self.validator.errors, {'_id': 'must be of UUID type'})
class TestValidator(InvenioTestCase): def setUp(self): from invenio.modules.jsonalchemy.validator import Validator self.validator = Validator() def tearDown(self): del self.validator def test_objectid(self): """Objectid type validation""" self.validator._validate_type_objectid('_id', 'abcde12345fabcd67890efab') self.assertEqual(self.validator.errors, {}) self.validator._errors = {} self.validator._validate_type_objectid('_id', 'abcde-12345-fabcd-67890e') self.assertEqual(self.validator.errors, {'_id': 'must be of ObjectId type'}) def test_uuid(self): """Objectid type validation""" _uuid = str(uuid.uuid4()) self.validator._validate_type_uuid('_id', _uuid) self.assertEqual(self.validator.errors, {}) self.validator._errors = {} self.validator._validate_type_uuid('_id', _uuid.replace('-', '_')) self.assertEqual(self.validator.errors, {'_id': 'must be of UUID type'})
def setUp(self): from invenio.modules.jsonalchemy.validator import Validator self.validator = Validator()