Skip to content

Instantly share code, notes, and snippets.

@NightBlues
Created February 9, 2017 16:45
Show Gist options
  • Save NightBlues/111e1683e36d91ce5d44aba8564297a1 to your computer and use it in GitHub Desktop.
Save NightBlues/111e1683e36d91ce5d44aba8564297a1 to your computer and use it in GitHub Desktop.
marshmallow mongoengine validate
def find_models():
import models
from mongoengine.base.common import _document_registry
def _checker(model_class):
schema_class = getattr(model_class, 'schema_class', None)
return schema_class is not None and issubclass(schema_class, Schema)
return filter(_checker, _document_registry.values())
@pytest.mark.parametrize('model', find_models())
def test_schema_not_overlaps_model(model):
model_class = model
schema_class = model_class.schema_class
schema_fields = schema_class().declared_fields.keys()
model_fields = model_class._fields.keys()
assert set(schema_fields) == set(model_fields)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment