def test_fields_not_found(self): doc = {'a': 10, 'd': {'bucket': {'a': 'yes!!!'}}, 'b': 20, 's': {extf.KEY: 'key'}, 'd2': {'bucket2': {'a': 'no!!!'}}, 'd3': {'bucket3': {reservedf.BUCKET: 'yes!!!'}}} valid1 = RecursiveValidator(doc, intf.values()) valid2 = SimpleValidator(doc, reservedf.values(), valid1) valid3 = RecursiveValidator(doc, intf.values(), valid2) valid3.validate()
def serialize(cls, key, date): """ :param date: python datetime object, :return: datetime iso format """ iso = date.isoformat() if key and key in reservedf.values(): return iso return {TYPE_FIELD: type_codes.DATE, 'iso': iso}
def test_simple1(self): doc = {'a': 10, 'd': {'bucket': {reservedf.BUCKET: 'yes!!!'}}, 'b': 20, extf.KEY: 'key'} fields = extf + intf + reservedf.values() valid = RecursiveValidator(doc, fields) try: valid.validate() except Exception, e: assert e.message == 'Document contains forbidden fields [%s,%s]' % \ (extf.KEY, reservedf.BUCKET)
def test_chain(self): doc = {'a': 10, reservedf.BUCKET: 'bucket', 'b': 20, extf.KEY: 'key'} valid1 = SimpleValidator(doc, extf.values()) valid2 = SimpleValidator(doc, reservedf.values(), valid1) try: valid2.validate() except Exception, e: assert e.message == 'Document contains forbidden fields [%s,%s]' % \ (extf.KEY, reservedf.BUCKET)
def test_chain_and_duplicate(self): doc = {'a': 10, 'd': {'bucket': {reservedf.BUCKET: 'yes!!!'}}, 'b': 20, extf.KEY: 'key', 'd2': {'bucket2': {reservedf.BUCKET: 'no!!!'}}, 'd3': {'bucket3': {reservedf.BUCKET: 'yes!!!'}}} valid1 = RecursiveValidator(doc, reservedf.values()) valid2 = SimpleValidator(doc, extf.values(), valid1) valid3 = RecursiveValidator(doc, intf.values(), valid2) try: valid3.validate() except Exception, e: assert e.message == 'Document contains forbidden fields [%s,%s]' % \ (extf.KEY, reservedf.BUCKET)
def validate_doc_for_update(update_doc): fields = forbidden_fields.values() + extf.values() + reservedf.values() validate_forbidden_fields(update_doc, fields) validators.UpdateDocumentKeysValidator(update_doc).validate()
def validate_document(document): fields = forbidden_fields.values() + reservedf.values() validate_forbidden_fields(document, fields) validators.SaveDocumentKeysValidator(document).validate()