requests.options

Here are the examples of the python api requests.options taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

Example 1

Project: eavatar-me
Source File: client.py
View license
    def options(self, uri, params=None, headers=None):

        if headers is None:
            headers = dict()
            headers.update(self._headers)

        return requests.options(self._url + uri, params=params, headers=headers)

Example 2

Project: home-assistant
Source File: test_http.py
View license
    def test_cors_preflight_allowed(self):
        """Test cross origin resource sharing preflight (OPTIONS) request."""
        headers = {
            const.HTTP_HEADER_ORIGIN: HTTP_BASE_URL,
            'Access-Control-Request-Method': 'GET',
            'Access-Control-Request-Headers': 'x-ha-access'
        }
        req = requests.options(_url(const.URL_API), headers=headers)

        allow_origin = const.HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
        allow_headers = const.HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS

        assert req.status_code == 200
        assert req.headers.get(allow_origin) == HTTP_BASE_URL
        assert req.headers.get(allow_headers) == \
            const.HTTP_HEADER_HA_AUTH.upper()

Example 3

Project: behave-http
Source File: __init__.py
View license
@behave.when('I make an OPTIONS request to "{url_path_segment}"')
@dereference_step_parameters_and_data
def options_request(context, url_path_segment):
    url = append_path(context.server, url_path_segment)
    context.response = requests.options(
        url, headers=context.headers, auth=context.auth,
        verify=context.verify_ssl)

Example 4

Project: behave-http
Source File: __init__.py
View license
@behave.when('I make an OPTIONS request to "{url_path_segment}"')
@dereference_step_parameters_and_data
def options_request(context, url_path_segment):
    url = append_path(context.server, url_path_segment)
    context.response = requests.options(
        url, headers=context.headers, auth=context.auth,
        verify=context.verify_ssl)

Example 5

Project: requests-mock
Source File: test_mocker.py
View license
    @requests_mock.Mocker()
    def test_mocker_options(self, m):
        mock_obj = m.options(self.URL, text=self.TEXT)
        self.assertResponse(requests.options(self.URL))
        self.assertTrue(mock_obj.called)
        self.assertTrue(mock_obj.called_once)
        self.assertTrue(m.called)
        self.assertTrue(m.called_once)

Example 6

Project: soccermetrics-client-py
Source File: base.py
View license
    def options(self):
        """
        Retrieves documentation of the REST resource representation.

        If the status code is 200 (OK), returns the documentation.  Otherwise,
        returns an error.

        The response is an object with the following attributes:

        +------------+------------------------+
        | Attribute  | Description            |
        +============+========================+
        | headers    | Response headers       |
        +------------+------------------------+
        | data       | Resource documentation |
        +------------+------------------------+

        Link resources are not included in the documentation.

        :returns: Resource documentation data.
        :rtype: ``EasyDict`` object.
        """
        uri = "%s%s" % (self.base_uri, self.endpoint)

        resp = requests.options(uri,params=self.auth)

        if resp.status_code == 200:
            return Response(self.base_uri, self.auth, resp)
        else:
            raise SoccermetricsRestException(resp.status_code,resp.url)

Example 7

Project: fjord
Source File: test_mocker.py
View license
    @requests_mock.Mocker()
    def test_mocker_options(self, m):
        mock_obj = m.options(self.URL, text=self.TEXT)
        self.assertResponse(requests.options(self.URL))
        self.assertTrue(mock_obj.called)

Example 8

Project: fjord
Source File: test_mocker.py
View license
    @requests_mock.Mocker()
    def test_mocker_options(self, m):
        mock_obj = m.options(self.URL, text=self.TEXT)
        self.assertResponse(requests.options(self.URL))
        self.assertTrue(mock_obj.called)