Пример #1
0
    def test_load_from_yaml_file_logging(self):
        """Should load logging config from yaml if provided."""
        self._create_mock_yaml({
            "developer_token": self.developer_token,
            "logging": {
                "version": 1,
                "disable_existing_loggers": False,
                "formatters": {
                    "default_fmt": {
                        "format": "[%(asctime)s - %(levelname)s]",
                        "datefmt": "%Y-%m-%d %H:%M:%S",
                    }
                },
                "handlers": {
                    "default_handler": {
                        "class": "logging.StreamHandler",
                        "formatter": "default_fmt",
                    }
                },
                "loggers": {
                    "": {
                        "handlers": ["default_handler"],
                        "level": "DEBUG",
                    }
                },
            },
        })

        result = config.load_from_yaml_file()

        self.assertEqual(result["developer_token"], self.developer_token)
        self.assertIsInstance(result["logging"], dict)
Пример #2
0
    def test_load_from_yaml_file_linked_cid(self):
        """Should load liked_customer_id config from yaml."""
        self._create_mock_yaml({"linked_customer_id": self.linked_customer_id})

        result = config.load_from_yaml_file()

        self.assertEqual(result["linked_customer_id"], self.linked_customer_id)
Пример #3
0
    def test_load_from_yaml_file_login_cid_number(self):
        """Should load login_customer_id key if value is defined as a number."""
        login_cid_num = int(self.login_customer_id)
        self._create_mock_yaml({"login_customer_id": login_cid_num})

        result = config.load_from_yaml_file()

        self.assertEqual(result["login_customer_id"], self.login_customer_id)
Пример #4
0
    def test_load_from_yaml_file_from_env_var(self):
        """Should load yaml file from env var path if defined."""
        env_var_path = os.path.expanduser("/test/from/env/var")
        file_path = os.path.join(env_var_path, "google-ads.yaml")
        self._create_mock_yaml({}, file_path=file_path)

        environ = {"GOOGLE_ADS_CONFIGURATION_FILE_PATH": file_path}
        with mock.patch("os.environ", environ):
            result = config.load_from_yaml_file()
            self.assertEqual(result["developer_token"], self.developer_token)
            self.assertEqual(result["use_proto_plus"], self.use_proto_plus)
Пример #5
0
    def test_load_from_yaml_file_from_env_var(self):
        """Should load from env var path if defined."""
        env_var_path = os.path.expanduser("/test/from/env/var")
        file_path = os.path.join(env_var_path, "google-ads.yaml")
        mock_dev_token = "from env var path"
        self.fs.create_file(
            file_path,
            contents=yaml.safe_dump({"developer_token": mock_dev_token}),
        )

        environ = {"GOOGLE_ADS_CONFIGURATION_FILE_PATH": file_path}
        with mock.patch("os.environ", environ):
            result = config.load_from_yaml_file()
            self.assertEqual(result["developer_token"], mock_dev_token)
Пример #6
0
    def test_load_from_yaml_file_secondary_service_account_keys(self):
        """Should convert secondary keys to primary keys.

        This test should be removed once the secondary service account keys
        are deprecated.
        """
        self._create_mock_yaml({
            "path_to_private_key_file": self.json_key_file_path,
            "delegated_account": self.impersonated_email,
        })

        result = config.load_from_yaml_file()

        self.assertEqual(result["json_key_file_path"], self.json_key_file_path)
        self.assertEqual(result["impersonated_email"], self.impersonated_email)
Пример #7
0
    def test_load_from_yaml_file(self):
        """Should load config from a yaml file in the root directory."""
        self._create_mock_yaml({
            "client_id": self.client_id,
            "client_secret": self.client_secret,
            "refresh_token": self.refresh_token,
        })

        result = config.load_from_yaml_file()

        self.assertEqual(result["developer_token"], self.developer_token)
        self.assertEqual(result["use_proto_plus"], self.use_proto_plus)
        self.assertEqual(result["client_id"], self.client_id)
        self.assertEqual(result["client_secret"], self.client_secret)
        self.assertEqual(result["refresh_token"], self.refresh_token)
Пример #8
0
    def test_load_from_yaml_file_linked_cid(self):
        file_path = os.path.join(os.path.expanduser("~"), "google-ads.yaml")
        self.fs.create_file(
            file_path,
            contents=yaml.safe_dump(
                {
                    "linked_customer_id": self.linked_customer_id,
                    "developer_token": self.developer_token,
                }
            ),
        )

        result = config.load_from_yaml_file()

        self.assertEqual(result["developer_token"], self.developer_token)
        self.assertEqual(result["linked_customer_id"], self.linked_customer_id)
Пример #9
0
    def test_load_from_yaml_file_with_path_and_env_var(self):
        """Should load yaml file from passed-in path if both are defined."""
        env_var_path = os.path.join(os.path.expanduser("/test/from/env/var"),
                                    "google-ads.yaml")
        passed_in_path = os.path.join(os.path.expanduser("/test/given/path"),
                                      "google-ads.yaml")
        # Create yaml file in location defined by path passed to method
        self._create_mock_yaml({"location": "passed in"},
                               file_path=passed_in_path)
        # Create yaml file in location defined by environment variable
        self._create_mock_yaml({"location": "env var"}, file_path=env_var_path)

        environ = {"GOOGLE_ADS_CONFIGURATION_FILE_PATH": env_var_path}
        with mock.patch("os.environ", environ):
            # Load config and check that it came from path passed to method
            result = config.load_from_yaml_file(path=passed_in_path)
            self.assertEqual(result["location"], "passed in")
Пример #10
0
    def test_load_from_yaml_file(self):
        file_path = os.path.join(os.path.expanduser("~"), "google-ads.yaml")
        self.fs.create_file(
            file_path,
            contents=yaml.safe_dump(
                {
                    "developer_token": self.developer_token,
                    "client_id": self.client_id,
                    "client_secret": self.client_secret,
                    "refresh_token": self.refresh_token,
                }
            ),
        )

        result = config.load_from_yaml_file()

        self.assertEqual(result["developer_token"], self.developer_token)
        self.assertEqual(result["client_id"], self.client_id)
        self.assertEqual(result["client_secret"], self.client_secret)
        self.assertEqual(result["refresh_token"], self.refresh_token)
Пример #11
0
    def test_load_from_yaml_file_secondary_service_account_keys(self):
        """Should convert secondary keys to primary keys.
        This test should be removed once the secondary service account keys
        are deprecated.
        """
        file_path = os.path.join(os.path.expanduser("~"), "google-ads.yaml")
        self.fs.create_file(
            file_path,
            contents=yaml.safe_dump(
                {
                    "developer_token": self.developer_token,
                    "path_to_private_key_file": self.json_key_file_path,
                    "delegated_account": self.impersonated_email,
                }
            ),
        )

        result = config.load_from_yaml_file()
        self.assertEqual(result["json_key_file_path"], self.json_key_file_path)
        self.assertEqual(result["impersonated_email"], self.impersonated_email)
Пример #12
0
    def test_load_from_yaml_file_with_path(self):
        """Should load yaml file from a given path passed in directly."""
        custom_path = os.path.expanduser("/test/custom/path")
        file_path = os.path.join(custom_path, "google-ads.yaml")
        self._create_mock_yaml(
            {
                "client_id": self.client_id,
                "client_secret": self.client_secret,
                "refresh_token": self.refresh_token,
            },
            file_path=file_path,
        )

        result = config.load_from_yaml_file(path=file_path)

        self.assertEqual(result["developer_token"], self.developer_token)
        self.assertEqual(result["use_proto_plus"], self.use_proto_plus)
        self.assertEqual(result["client_id"], self.client_id)
        self.assertEqual(result["client_secret"], self.client_secret)
        self.assertEqual(result["refresh_token"], self.refresh_token)
Пример #13
0
    def test_load_from_yaml_file_logging(self):
        file_path = os.path.join(os.path.expanduser("~"), "google-ads.yaml")
        self.fs.create_file(
            file_path,
            contents=yaml.safe_dump(
                {
                    "developer_token": self.developer_token,
                    "logging": {
                        "version": 1,
                        "disable_existing_loggers": False,
                        "formatters": {
                            "default_fmt": {
                                "format": "[%(asctime)s - %(levelname)s]",
                                "datefmt": "%Y-%m-%d %H:%M:%S",
                            }
                        },
                        "handlers": {
                            "default_handler": {
                                "class": "logging.StreamHandler",
                                "formatter": "default_fmt",
                            }
                        },
                        "loggers": {
                            "": {
                                "handlers": ["default_handler"],
                                "level": "DEBUG",
                            }
                        },
                    },
                }
            ),
        )

        result = config.load_from_yaml_file()

        self.assertEqual(result["developer_token"], self.developer_token)
        self.assertIsInstance(result["logging"], dict)