def ping(self) -> StatusResponse: """Checks API status to see if it is up Returns ------- StatusResponse OK 200 means the service is up and running. """ resp = self._get("") return StatusResponse(**resp)
def test_plan_delete(self): with patch("flightplandb.flightplandb.FlightPlanDB", autospec=True) as MockClass: instance = MockClass.return_value instance._delete.return_value = {"message": "OK", "errors": None} sub_instance = PlanAPI(instance) response = sub_instance.delete(62493) # check PlanAPI method made the correct request of FlightPlanDB instance.assert_has_calls([call._delete('/plan/62493')]) correct_response = StatusResponse(message="OK", errors=None) # check PlanAPI method decoded data correctly for given response assert response == correct_response
def test_plan_like(self): with patch("flightplandb.flightplandb.FlightPlanDB", autospec=True) as MockClass: instance = MockClass.return_value instance._post.return_value = {"message": "Not Found", "errors": None} sub_instance = PlanAPI(instance) response = sub_instance.like(42) # check PlanAPI method made the correct request of FlightPlanDB instance.assert_has_calls([call._post('/plan/42/like')]) correct_response = StatusResponse(message='Not Found', errors=None) # check PlanAPI method decoded data correctly for given response assert response == correct_response
def revoke(self) -> StatusResponse: """Revoke the API key in use in the event it is compromised. Requires authentication. Returns ------- StatusResponse If the HTTP response code is 200 and the status message is "OK", then the key has been revoked and any further requests will be rejected. Any other status code or message indicates an error has occurred and the errors array will give further details. """ resp = self._get("/auth/revoke") self._header = resp.headers return StatusResponse(**resp.json())
def has_liked(self, id_: int) -> bool: r"""Fetches your like status for a flight plan. Requires authentication. Parameters ---------- id\_ : int ID of the flightplan to be checked Returns ------- bool ``True``/``False`` to indicate that the plan was liked / not liked """ sr = StatusResponse( **self._fp._get(path=f"/plan/{id_}/like", ignore_statuses=[404])) return sr.message != "Not Found"
def like(self, id_: int) -> StatusResponse: r"""Likes a flight plan. Requires authentication. Parameters ---------- id\_ : int ID of the flightplan to be liked Returns ------- StatusResponse ``message=Created`` means the plan was successfully liked. ``message=OK`` means the plan was already liked. Raises ------ :class:`~flightplandb.exceptions.NotFoundException` No plan with the specified id was found. """ return StatusResponse(**self._fp._post(path=f"/plan/{id_}/like"))
def delete(self, id_: int) -> StatusResponse: r"""Deletes a flight plan that is linked to your account. Requires authentication. Parameters ---------- id\_ : int The ID of the flight plan to delete Returns ------- StatusResponse OK 200 means a successful delete Raises ------ :class:`~flightplandb.exceptions.NotFoundException` No plan with the specified id was found. """ resp = self._fp._delete(path=f"/plan/{id_}") return (StatusResponse(**resp))