def test_to_dict(self): doc = Document(collection='test') doc.creation_date = Field(default=lambda: datetime.now().isoformat()) doc.name = Field() doc.name = 'tomtom' doc_dict = doc.to_dict() assert 'creation_date' in doc_dict assert 'collection' not in doc_dict assert doc_dict['name'] == 'tomtom' assert len(doc_dict) == 2
def test_fields_append(self): doc = Document(collection='test') assert doc.fields == [] doc.name = Field(default=lambda: 'alpha') doc.age = Field(default=lambda: 'bravo') assert doc.fields == ['name', 'age'] assert doc.name == 'alpha' assert doc.age == 'bravo'
def test_update(self): original = Document(collection='test') original.name = Field(value='named test') original.age = Field(value=12) cpy = original.copy() cpy.clear() cpy.update(name='bibou', age=30) assert cpy.name == 'bibou' assert original.name == 'named test' assert original.age == 12 assert cpy.age == 30
def test_copy(self): doc = Document(collection='test', _id='abcdef') doc.name = Field(value='named test', default=lambda: 'tested') cpy = doc.copy() assert doc != cpy assert doc.name == cpy.name cpy.name = None assert cpy.name == 'tested' assert doc.name == 'named test' assert cpy._id is None assert cpy.collection == doc.collection assert doc.raw_attr('name') != cpy.raw_attr('name')