def test_push_dict(self): class MyModel(Document): events = ListField(DictField()) doc = MyModel(events=[{"a": 1}]).save() raw_doc = get_as_pymongo(doc) expected_raw_doc = {"_id": doc.id, "events": [{"a": 1}]} assert raw_doc == expected_raw_doc MyModel.objects(id=doc.id).update(push__events={}) raw_doc = get_as_pymongo(doc) expected_raw_doc = {"_id": doc.id, "events": [{"a": 1}, {}]} assert raw_doc == expected_raw_doc
def test_storage(self): uid = uuid.uuid4() person = Person(api_key=uid).save() assert get_as_pymongo(person) == { "_id": person.id, "api_key": str(uid) }
def test_storage(self): class Person(Document): admin = BooleanField() person = Person(admin=True) person.save() assert get_as_pymongo(person) == {"_id": person.id, "admin": True}
def test_storage(self): class Person(Document): value = LongField() Person.drop_collection() person = Person(value=5000) person.save() assert get_as_pymongo(person) == {"_id": person.id, "value": 5000}
def test_storage(self): class Person(Document): name = StringField() Person.drop_collection() person = Person(name="test123") person.save() assert get_as_pymongo(person) == {"_id": person.id, "name": "test123"}
def test_storage(self): class BlogPost(Document): info = DictField() BlogPost.drop_collection() info = {'testkey': 'testvalue'} post = BlogPost(info=info).save() self.assertEqual(get_as_pymongo(post), {'_id': post.id, 'info': info})
def test_storage(self): uid = uuid.uuid4() person = Person(api_key=uid).save() self.assertEqual( get_as_pymongo(person), {'_id': person.id, 'api_key': str(uid) } )
def test_storage(self): class BlogPost(Document): info = DictField() BlogPost.drop_collection() info = {"testkey": "testvalue"} post = BlogPost(info=info).save() assert get_as_pymongo(post) == {"_id": post.id, "info": info}
def test_storage(self): class Person(Document): admin = BooleanField() person = Person(admin=True) person.save() self.assertEqual(get_as_pymongo(person), { '_id': person.id, 'admin': True })
def test_push_dict(self): class MyModel(Document): events = ListField(DictField()) doc = MyModel(events=[{'a': 1}]).save() raw_doc = get_as_pymongo(doc) expected_raw_doc = { '_id': doc.id, 'events': [{'a': 1}] } self.assertEqual(raw_doc, expected_raw_doc) MyModel.objects(id=doc.id).update(push__events={}) raw_doc = get_as_pymongo(doc) expected_raw_doc = { '_id': doc.id, 'events': [{'a': 1}, {}] } self.assertEqual(raw_doc, expected_raw_doc)
def test_storage(self): class Person(Document): admin = BooleanField() person = Person(admin=True) person.save() self.assertEqual( get_as_pymongo(person), {'_id': person.id, 'admin': True})
def test_storage(self): class BlogPost(Document): info = DictField() BlogPost.drop_collection() info = {'testkey': 'testvalue'} post = BlogPost(info=info).save() self.assertEqual( get_as_pymongo(post), { '_id': post.id, 'info': info } )
def test_storage(self): model = ModelWithEnum(status=Status.NEW).save() assert get_as_pymongo(model) == {"_id": model.id, "status": "new"}
def test_storage_enum_with_int(self): model = ModelWithColor(color=Color.BLUE).save() assert get_as_pymongo(model) == {"_id": model.id, "color": 2}