Beispiel #1
0
    def test_global_headers_from_client_overriden_by_gapipy_headers(self):
        """
        The client's "global_http_headers" should be included when generating
        HTTP headers for a request, but are overriden by some required headers
        added by gapipy.
        """
        self.client.api_language = 'human'

        # We'll set up some HTTP headers in our client config...
        header_value = "woob woob woob woob woob woob woob",
        self.client.global_http_headers = {
            'Accept-Language': header_value,
            'User-Agent': header_value,
            'X-Application-Key': header_value,
            'X-Zoidberg': header_value,
        }
        requestor = APIRequestor(self.client, self.resources)

        method = 'METHOD'
        additional_headers = {}

        # ... and ask for some request headers...
        request_headers = requestor._get_headers(method, additional_headers)

        # ... and we should find that gapipy has overridden some of those
        # headers...
        self.assertNotEqual(request_headers['Accept-Language'], header_value)
        self.assertNotEqual(request_headers['User-Agent'], header_value)
        self.assertNotEqual(request_headers['X-Application-Key'], header_value)

        # ... but we still other header values from the config that do not
        # collide with headers gapipy writes
        self.assertEqual(request_headers['X-Zoidberg'], header_value)
Beispiel #2
0
    def test_global_headers_from_client(self):
        """
        The client's "global_http_headers" should be included when generating
        HTTP headers for a request.
        """
        header_name = "x-farnsworth"
        header_value = "here's where I keep assorted lengths of wire",
        self.client.global_http_headers = {header_name: header_value}
        requestor = APIRequestor(self.client, self.resources)

        method = 'METHOD'
        additional_headers = {}
        request_headers = requestor._get_headers(method, additional_headers)

        self.assertIn(header_name, request_headers)
        self.assertEqual(request_headers[header_name], header_value)
Beispiel #3
0
    def test_global_headers_from_client_overriden_by_additional_headers(self):
        """
        The client's "global_http_headers" should be included when generating
        HTTP headers for a request, but are overridable by headers added later.
        """
        header_name = "x-farnsworth"
        header_value = "here's where I keep assorted lengths of wire",
        self.client.global_http_headers = {header_name: header_value}
        requestor = APIRequestor(self.client, self.resources)

        method = 'METHOD'

        # If `_get_headers` is given an `additional_headers` value with the
        # same `header_name` as was in the client configs...
        request_headers = requestor._get_headers(method,
                                                 {header_name: 'good news'})

        # ... the value from `additional_headers` will be the one in the final
        # header-dict
        self.assertIn(header_name, request_headers)
        self.assertEqual(request_headers[header_name], 'good news')