Ejemplo n.º 1
0
    def __init__(self,
                 request_handler: RequestHandler,
                 vhost: t.Optional[str] = None) -> None:
        Requestor.__init__(self, request_handler)
        self._request_handler = request_handler

        self._vhost = vhost or "/"
    def __init__(self, request_handler: RequestHandler) -> None:
        """
        :param request_handler: an instance of an object capable of handling http requests, i.e. requests.session()
        """
        Requestor.__init__(self, request_handler)
        self._request_handler = request_handler

        self._url_states = 'api/states/all/'
        self._url_flights_arrival = 'api/flights/arrival/'
        self._url_flights_departure = 'api/flights/departure/'
        self._url_airport = 'api/airports/'
Ejemplo n.º 3
0
def test_process_response__result_is_converted_to_response_class_object(
        data, many, expected_object):
    response = Mock()
    response.status_code = 200
    response.content = data
    response.json = Mock(return_value=data)

    requestor = Requestor(request_handler=Mock())

    processed_response = requestor._process_response(response, TestModel, many)

    assert expected_object == processed_response
    def __init__(self, request_handler: RequestHandler) -> None:
        """
        :param request_handler: an instance of an object capable of handling http requests, i.e. requests.session()
        """
        Requestor.__init__(self, request_handler)

        self._url_uas_zones = self._BASE_URL + 'uas_zones/'
        self._url_uas_zones_filter = self._BASE_URL + 'uas_zones/filter/'
        self._url_uas_zones_by_identifier = self._BASE_URL + 'uas_zones/{uas_zone_identifier}'
        self._url_subscriptions = self._BASE_URL + 'subscriptions/'
        self._url_subscription_by_id = self._BASE_URL + 'subscriptions/{subscription_id}'
        self._url_ping_credentials = self._BASE_URL + 'ping-credentials'
Ejemplo n.º 5
0
    def __init__(self, request_handler: RequestHandler) -> None:
        """
        :param request_handler: an instance of an object capable of handling http requests, i.e. requests.session()
        """
        Requestor.__init__(self, request_handler)
        self._request_handler = request_handler

        self._url_topics = self._BASE_URL + 'topics/'
        self._url_topics_own = self._BASE_URL + 'topics/own'
        self._url_topic_by_id = self._BASE_URL + 'topics/{topic_id}'
        self._url_subscriptions = self._BASE_URL + 'subscriptions/'
        self._url_subscription_by_id = self._BASE_URL + 'subscriptions/{subscription_id}'
        self._url_ping_credentials = self._BASE_URL + 'ping-credentials'
Ejemplo n.º 6
0
def test_do_request__corrent_method_is_called(method):
    mock_request_handler = Mock()
    mock_request_handler.get = Mock()
    mock_request_handler.post = Mock()
    mock_request_handler.put = Mock()
    mock_request_handler.delete = Mock()

    requestor = Requestor(request_handler=mock_request_handler)

    requestor._do_request(method, 'path', {}, {})

    called_method = getattr(mock_request_handler, method.lower())

    called_method.assert_called_once()
Ejemplo n.º 7
0
def test_process_response__error_status_code_should_raise__normal_status_code_should_not(
        status_code, should_raise):
    data = {'a': 1}
    response = Mock()
    response.status_code = status_code
    response.content = data
    response.json = Mock(return_value=data)

    requestor = Requestor(request_handler=Mock())

    if should_raise:
        with pytest.raises(APIError):
            requestor._process_response(response,
                                        response_class=None,
                                        many=False)
    else:
        requestor._process_response(response, response_class=None, many=False)
Ejemplo n.º 8
0
def test_do_request__wrong_method__raises_notimplementederror(method):
    requestor = Requestor(request_handler=Mock())

    with pytest.raises(NotImplementedError) as e:
        requestor._do_request(method, 'path', {}, {})
    assert f"Method {method} is not implemented" == str(e.value)