Example #1
0
 def test_authorizedhttp_request_forces_user_agent_no_provided_headers(self):
   authorized_http = transport.AuthorizedHttp(
       self.mock_credentials, http=self.mock_http)
   authorized_http.request(self.test_uri)
   headers = self.mock_http.request.call_args[1]['headers']
   self.assertIn('user-agent', headers)
   self.assertIn(transport.GAM_USER_AGENT, headers['user-agent'])
Example #2
0
    def test_authorizedhttp_request_forces_user_agent_with_another_agent_in_headers(
            self):
        authorized_http = transport.AuthorizedHttp(self.mock_credentials,
                                                   http=self.mock_http)
        headers_with_user_agent = {'user-agent': 'existing-user-agent'}

        authorized_http.request(self.test_uri, headers=headers_with_user_agent)
        final_headers = self.mock_http.request.call_args[1]['headers']
        self.assertIn('user-agent', final_headers)
        self.assertIn('existing-user-agent', final_headers['user-agent'])
        self.assertIn(transport.GAM_USER_AGENT, final_headers['user-agent'])
Example #3
0
    def test_authorizedhttp_request_same_user_agent_already_in_headers(self):
        authorized_http = transport.AuthorizedHttp(self.mock_credentials,
                                                   http=self.mock_http)
        same_user_agent_header = {'user-agent': transport.GAM_USER_AGENT}

        authorized_http.request(self.test_uri, headers=same_user_agent_header)
        final_headers = self.mock_http.request.call_args[1]['headers']
        self.assertIn('user-agent', final_headers)
        self.assertIn(transport.GAM_USER_AGENT, final_headers['user-agent'])
        # Make sure the header wasn't duplicated
        self.assertEqual(len(transport.GAM_USER_AGENT),
                         len(final_headers['user-agent']))
Example #4
0
  def test_authorizedhttp_request_forces_user_agent_no_agent_in_headers(self):
    authorized_http = transport.AuthorizedHttp(
        self.mock_credentials, http=self.mock_http)
    fake_request_headers = {'some-header-thats-not-a-user-agent': 'someData'}

    authorized_http.request(self.test_uri, headers=fake_request_headers)
    final_headers = self.mock_http.request.call_args[1]['headers']
    self.assertIn('user-agent', final_headers)
    self.assertIn(transport.GAM_USER_AGENT, final_headers['user-agent'])
    self.assertIn('some-header-thats-not-a-user-agent', final_headers)
    self.assertEqual('someData',
                     final_headers['some-header-thats-not-a-user-agent'])
Example #5
0
 def test_authorizedhttp_request_returns_response_content(self):
     http = transport.AuthorizedHttp(self.mock_credentials,
                                     http=self.mock_http)
     response, content = http.request(self.test_uri)
     self.assertEqual(self.mock_response, response)
     self.assertEqual(self.mock_content, content)
Example #6
0
 def test_authorizedhttp_is_google_auth_httplib2_compatible(self):
     http = transport.AuthorizedHttp(self.mock_credentials)
     self.assertIsInstance(http, google_auth_httplib2.AuthorizedHttp)