Пример #1
0
    def test_get_credentials_installed_application(self):
        mock_config = {
            "json_key_file_path": self.json_key_file_path,
            "impersonated_email": self.subject,
        }

        with mock.patch.object(oauth2,
                               "get_service_account_credentials",
                               return_value=None) as mock_initializer:
            oauth2.get_credentials(mock_config)
            mock_initializer.assert_called_once_with(self.json_key_file_path,
                                                     self.subject)
Пример #2
0
    def test_get_credentials_installed_application(self):
        mock_config = {
            "client_id": self.client_id,
            "client_secret": self.client_secret,
            "refresh_token": self.refresh_token,
        }

        with mock.patch.object(oauth2,
                               "get_installed_app_credentials",
                               return_value=None) as mock_initializer:
            oauth2.get_credentials(mock_config)
            mock_initializer.assert_called_once_with(self.client_id,
                                                     self.client_secret,
                                                     self.refresh_token)
Пример #3
0
    def test_get_credentials_with_proxy(self):
        http_proxy = "https://localhost:8000"
        mock_request = mock.Mock()
        mock_session = mock.Mock()
        mock_config = {
            "client_id": self.client_id,
            "client_secret": self.client_secret,
            "refresh_token": self.refresh_token,
            "http_proxy": http_proxy,
        }

        with mock.patch.object(oauth2,
                               "get_installed_app_credentials",
                               return_value=None) as mock_initializer:
            oauth2.get_credentials(mock_config)

            mock_initializer.assert_called_once_with(
                self.client_id,
                self.client_secret,
                self.refresh_token,
                http_proxy=http_proxy,
            )
Пример #4
0
    def _get_client_kwargs(cls, config_data):
        """Converts configuration dict into kwargs required by the client.

        Args:
            config_data: a dict containing client configuration.

        Returns:
            A dict containing kwargs that will be provided to the
            GoogleAdsClient initializer.

        Raises:
            ValueError: If the configuration lacks a required field.
        """
        return {
            "credentials": oauth2.get_credentials(config_data),
            "developer_token": config_data.get("developer_token"),
            "endpoint": config_data.get("endpoint"),
            "login_customer_id": config_data.get("login_customer_id"),
            "logging_config": config_data.get("logging"),
            "linked_customer_id": config_data.get("linked_customer_id"),
        }