def test_load_doc_update_and_save(self): db_doc = store.get_collection().find_one() doc = store.Doc(id_=db_doc[store.ID]) assert len(doc._update) == 0 doc.wins = 42 doc.llh = 2.2 doc.timer = 111 assert len(doc._update) == 3 doc.save() assert len(doc._update) == 0 doc_loaded = store.Doc(id_=db_doc[store.ID]) assert len(doc_loaded._update) == 0 assert doc_loaded.id == db_doc[store.ID] assert doc_loaded.genotype == db_doc["genotype"] assert doc_loaded.wins == 42 assert doc_loaded.model is None assert doc_loaded.llh == 2.2 assert doc_loaded.date is None assert doc_loaded.timer == 111 assert doc_loaded.tickers is None
def test_new_doc_and_save(self): assert store.get_collection().count_documents({}) == 0 genotype = store.Genotype() doc = store.Doc(genotype=genotype) assert store.get_collection().count_documents({}) == 0 assert len(doc._update) == 2 assert isinstance(doc.id, bson.ObjectId) assert doc.genotype is genotype assert doc.wins == 0 assert doc.model is None with pytest.raises(AttributeError) as error: isinstance(doc.llh, bson.ObjectId) assert "object has no attribute 'llh'" in str(error.value) assert doc.date is None assert doc.timer == 0 assert doc.tickers is None doc.save() assert store.get_collection().count_documents({}) == 1 assert len(doc._update) == 0
def __init__( self, *, _id: Optional[bson.ObjectId] = None, genotype: Optional[Genotype] = None, ): self._data = store.Doc(id_=_id, genotype=genotype)
def __init__( self, *, _id: Optional[bson.ObjectId] = None, genotype: Optional[Genotype] = None, ) -> None: """Загружает организм из базы данных.""" self._doc = store.Doc(id_=_id, genotype=genotype)
def test_delete(self): assert store.get_collection().count_documents({}) == 1 db_doc = store.get_collection().find_one() doc = store.Doc(id_=db_doc[store.ID]) doc.delete() assert store.get_collection().count_documents({}) == 0
def test_load_doc(self): db_doc = store.get_collection().find_one() doc = store.Doc(id_=db_doc[store.ID]) assert len(doc._update) == 0 assert doc.id == db_doc[store.ID] assert doc.genotype == db_doc["genotype"] assert doc.wins == 0 assert doc.model is None with pytest.raises(AttributeError) as error: isinstance(doc.llh, bson.ObjectId) assert "object has no attribute 'llh'" in str(error.value) assert doc.date is None assert doc.timer == 0 assert doc.tickers is None
def test_load_wrong_doc(self): id_ = bson.ObjectId() with pytest.raises(store.IdError) as error: store.Doc(id_=id_) assert str(id_) in str(error.value)