Example #1
0
 def test_force_register_documents(self):
     doc = create_document('testDocument', fields={'title':schema.CharField()})
     
     doc = create_document('testDocument', fields={'title':schema.CharField(), 'slug':schema.SlugField()})
     force_register_documents(doc._meta.app_label, doc)
     
     doc = get_base_document(doc._meta.collection)
     
     self.assertTrue('slug' in doc._meta.fields)
Example #2
0
def Deserializer(object_list, **options):
    """
    Deserialize simple Python objects back into Django ORM instances.

    It's expected that you pass the Python objects themselves (instead of a
    stream or a string) to the constructor
    """
    # models.get_apps()
    use_natural_keys = options.get("use_natural_keys", True)
    for d in object_list:
        # Look up the model and starting build a dict of data for it.
        doc_cls = get_base_document(d["model"])
        data = d["fields"]
        if use_natural_keys:
            data["@natural_key"] = d["natural_key"]
        else:
            data[doc_cls._meta.pk.attname] = doc_cls._meta.pk.to_python(d["pk"])

        yield base.DeserializedObject(doc_cls.to_python(data), natural_key=d["natural_key"])
Example #3
0
 def get_document(self):
     return get_base_document(self.collection)
Example #4
0
 def test_document_was_registered(self):
     self.assertTrue(SimpleDocument._meta.collection in app_cache.documents)
     get_base_document(SimpleDocument._meta.collection)