示例#1
0
    def test_database_exception(self, app: pytest.fixture) -> None:
        """
        Confirms the correct response status and safe error message of DatabaseException. The test config settings
        do not have database credentials, therefore an error will be raised when the attempting to process test user
        data.
        """
        client = app.test_client()
        response = client.post("/data", data={'test': 'yes'})

        assert response.status == "503 SERVICE UNAVAILABLE"
        assert DatabaseException.msg in response.data.decode("utf-8")
示例#2
0
    def test_all(self, app: pytest.fixture):

        client = app.test_client()

        @app.route('/test_exception')
        def test_exception():
            raise e.value
        for e in ExceptionRegistry:
            response = client.get('/test_exception')
            assert str(e.value.status_code) in response.status
            assert e.value.msg in response.data.decode()
示例#3
0
    def test_request_exception(self, app: pytest.fixture) -> None:
        """Confirms the correct response status and safe error message of RequestException."""
        monkeypatch = MonkeyPatch()
        monkeypatch.setattr(requests, "get", self.raise_http_error)
        client = app.test_client()
        app.config[
            "MPV_DEV"] = False  # dev_env to False so a mocked request will be made.
        response = client.post("/data")

        assert response.status == "400 BAD REQUEST"
        assert RequestException.msg in response.data.decode("utf-8")
示例#4
0
    def test_mountain_project_api_exception(self, app: pytest.fixture) -> None:
        """Confirms the correct response status and safe error message of MPAPIException."""
        monkeypatch = MonkeyPatch()
        monkeypatch.setattr(requests, "get", self.mock_get_response)
        client = app.test_client()
        app.config[
            "MPV_DEV"] = False  # dev_env to False so a mocked request will be made.
        response = client.post("/data")

        assert response.status == "403 FORBIDDEN"
        assert MPAPIException.msg in response.data.decode("utf-8")
示例#5
0
    def test_404(self, app: pytest.fixture) -> None:
        """
        Makes a GET request to a non-existent endpoint. Confirms the correct response status code is returned
        and that the application handles the error while returning a safe response message to the client.
        """
        client = app.test_client()
        response = client.get('/not_a_page')
        data = response.data.decode("utf-8")
        msg = "The requested URL was not found on the server. If you entered the URL manually please check your " \
              "spelling and try again."

        assert response.status == "404 NOT FOUND"
        assert msg in data
示例#6
0
def client(app: fixture):
    """test client"""
    return app.test_client()
示例#7
0
def test_index(app: pytest.fixture) -> None:
    """Assert that a status code of 200 is returned from /"""
    with app.test_client() as client:
        index = client.get('/')
        assert index.status == '200 OK'