def test_index_page(): file_path = find_dotenv('.env.test', usecwd=True) load_dotenv(file_path, override=True) database_config = DatabaseConfig() auth_config = AuthConfig() flask_config = FlaskConfig() mocked_client = mongomock.MongoClient() mock_db = mocked_client.get_database(database_config.db_name) client = AtlasClient(database_config, mocked_client) login_manager = LoginManager() login_manager.anonymous_user = TestUser #Create the new app. test_app = create_app(client, auth_config, login_manager) test_app.config.from_object(flask_config) test_app.config['LOGIN_DISABLED'] = True mock_item_response = ToDoItem.new_item_as_dict( "Hello form the integration tests") mock_db.get_collection("test_collection_name").insert_one( mock_item_response) response = test_app.test_client().get("/") assert 200 == response.status_code assert "Hello form the integration tests" in response.data.decode()
def test_new_item_as_dict_returns_correct_object(self): dict_to_test = ToDoItem.new_item_as_dict( "Testing static builder method") date_time_obj = datetime.strptime(dict_to_test["last_modified"], '%Y-%m-%d %H:%M:%S.%f') assert "Testing static builder method" == dict_to_test["title"] assert "To Do" == dict_to_test["status"] assert isinstance(date_time_obj, datetime)
def test_get_from_json(self): test_object: dict = ToDoItem.new_item_as_dict( "Testing static constructor method") collection = MongoClient().db.collection collection.insert_one(test_object) returned_object = collection.find_one( {'title': 'Testing static constructor method'}) object_to_test: ToDoItem = ToDoItem.from_json(returned_object) assert isinstance(object_to_test.item_id, str) assert "Testing static constructor method" == object_to_test.title assert "To Do" == object_to_test.status assert isinstance(object_to_test.last_modified, datetime)
def add_item(self, title: str) -> str: return str( self._collection.insert_one( ToDoItem.new_item_as_dict(title)).inserted_id)