def test_reconnect_if_mongodb_is_down(self): """ Should reconnect if mongodb is down """ accounts_collection = sut.get_collection("accounts") self.assertTrue(bool(accounts_collection)) sut.disconnect() accounts_collection = sut.get_collection("accounts") self.assertTrue(bool(accounts_collection))
def add(self, account_data: AddAccountModel) -> AccountModel: account_collection = MongoHelper.get_collection("accounts") result = account_collection.insert_one(account_data.dict()) account = account_collection.find_one({"_id": result.inserted_id}) return AccountModel(**MongoHelper.map(account))
def log_error(self, stack: str) -> None: error_collection = MongoHelper.get_collection("errors") error_collection.insert_one({"stack": stack, "date": datetime.now()})
def setUp(self) -> None: account_collection = MongoHelper.get_collection("accounts") account_collection.delete_many({})
def setUpClass(cls) -> None: MongoHelper.connect(client_class=MongoClient) cls.errors_collection = MongoHelper.get_collection("errors")