def test_success(self):
        from google.cloud.environment_vars import CREDENTIALS
        from unit_tests._testing import _Monkey
        from unit_tests._testing import _NamedTemporaryFile

        project_id = 'test-project-id'
        payload = '{"%s":"%s"}' % ('project_id', project_id)
        with _NamedTemporaryFile() as temp:
            with open(temp.name, 'w') as creds_file:
                creds_file.write(payload)

            environ = {CREDENTIALS: temp.name}
            with _Monkey(os, getenv=environ.get):
                result = self._callFUT()

            self.assertEqual(result, project_id)
    def test_success(self):
        from google.cloud.environment_vars import CREDENTIALS
        from unit_tests._testing import _Monkey
        from unit_tests._testing import _NamedTemporaryFile

        project_id = 'test-project-id'
        payload = '{"%s":"%s"}' % ('project_id', project_id)
        with _NamedTemporaryFile() as temp:
            with open(temp.name, 'w') as creds_file:
                creds_file.write(payload)

            environ = {CREDENTIALS: temp.name}
            with _Monkey(os, getenv=environ.get):
                result = self._callFUT()

            self.assertEqual(result, project_id)
    def test_windows(self):
        from google.cloud import _helpers as MUT
        from unit_tests._testing import _Monkey
        from unit_tests._testing import _NamedTemporaryFile

        project_id = 'test-project-id'
        with _NamedTemporaryFile() as temp:
            config_value = self.CONFIG_TEMPLATE % (
                MUT._GCLOUD_CONFIG_SECTION,
                MUT._GCLOUD_CONFIG_KEY, project_id)
            with open(temp.name, 'w') as config_file:
                config_file.write(config_value)

            def mock_get_path():
                return temp.name

            with _Monkey(os, name='nt'):
                with _Monkey(MUT, _get_windows_config_path=mock_get_path,
                             _USER_ROOT=None):
                    result = self._callFUT()

            self.assertEqual(result, project_id)
    def test_windows(self):
        from google.cloud import _helpers as MUT
        from unit_tests._testing import _Monkey
        from unit_tests._testing import _NamedTemporaryFile

        project_id = 'test-project-id'
        with _NamedTemporaryFile() as temp:
            config_value = self.CONFIG_TEMPLATE % (
                MUT._GCLOUD_CONFIG_SECTION, MUT._GCLOUD_CONFIG_KEY, project_id)
            with open(temp.name, 'w') as config_file:
                config_file.write(config_value)

            def mock_get_path():
                return temp.name

            with _Monkey(os, name='nt'):
                with _Monkey(MUT,
                             _get_windows_config_path=mock_get_path,
                             _USER_ROOT=None):
                    result = self._callFUT()

            self.assertEqual(result, project_id)