Exemplo n.º 1
0
 def test_requests_get_called_properly(self, mocked_get: mock.Mock):
     api = HouseCanaryApi("https://example.com", "api_key", "secret")
     _ = api.fetch_home_details("21 Flint st", "02145")
     mocked_get.assert_called_with(
         "https://example.com/property/details",
         auth=("api_key", "secret"),
         params={
             "address": "21 Flint st",
             "zipcode": "02145"
         },
     )
Exemplo n.º 2
0
    def get(self, request: HttpRequest, *_args, **_kwargs) -> JsonResponse:
        """
        Determines whether or not a property has a septic system installed.

        The following query parameters are required: address, zipcode.

        Status Code Meaning:
        ---
        200 -> Request completed successfully and true/false determination was made
        204 -> Request completed successfully; but true/false determination could not be made
        400 -> Request was improperly formatted or has an invalid set of arguments
        500 -> Request failed due internal error: I.e. Could not connect to external API

        Response Formats
        ---
        200 OK:
            Content-Type: application/json
            {"result": <bool>}

        non-200 OK:
            Content-Type: application/json
            {"message": <string>, "data": [<supporting datas>]}

        Example:
            GET /check-septic?address=18 Haskell Rd&zipcode=03087
            => 200 OK
            Content-Type: application/json
            {"result": true}
        """

        try:
            arguments = validate_arguments(request.GET)
        except ValidationError as error:
            return render_validation_response(error)

        api = HouseCanaryApi(
            base_url=settings.HOUSE_CANARY_BASE_URL,
            api_key=settings.HOUSE_CANARY_API_KEY,
            api_secret=settings.HOUSE_CANARY_API_SECRET,
        )

        use_case = CheckSeptic(house_canary_api=api)
        uc_request = use_case.Request.from_dict(arguments)
        result = use_case.execute(uc_request)

        return render_usecase_response(result)
Exemplo n.º 3
0
 def test_fetch_home_details_raises_NotFoundError_for_internal_error(
         self, _mocked_get):
     api = HouseCanaryApi("https://example.com/", "", "")
     with self.assertRaises(UnknownError):
         _ = api.fetch_home_details("1000 doesn't exist", "90210")
Exemplo n.º 4
0
 def test_fetch_home_details_returns_only_property_details(
         self, _mocked_get):
     api = HouseCanaryApi("https://example.com/", "", "")
     url = api.build_url()
     self.assertEqual(url, "https://example.com/property/details")
Exemplo n.º 5
0
 def test_build_url_with_trailing_slash_generates_correct_url(self):
     api = HouseCanaryApi("https://example.com/", "", "")
     url = api.build_url()
     self.assertEqual(url, "https://example.com/property/details")