From 42d17b35817fa95f37d832f7d49a0465a3b597fd Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Thu, 26 Jan 2023 13:29:57 +0000 Subject: [PATCH] refactor client secret resource --- tests/conftest.py | 17 ----------------- tests/test_core.py | 22 +++++----------------- tests/utilities.py | 9 +++++++++ 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2f53839..c416bb5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,20 +1,3 @@ """Conftest fixtures.""" -import json -import os - -import pytest - -from .utilities import get_secrets_dict - pytest_plugins = ("singer_sdk.testing.pytest_plugin",) - - -@pytest.fixture(scope="module") -def config(): - """Write secrets file then clean it up after tests.""" - secrets_path = f"{os.path.dirname(__file__)}/test_data/client_secrets.json" - with open(secrets_path, "w") as f: - json.dump(get_secrets_dict(), f) - yield - os.remove(secrets_path) diff --git a/tests/test_core.py b/tests/test_core.py index 0dd6ffc..a71b2db 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -3,12 +3,11 @@ import os from datetime import datetime, timedelta, timezone -import pytest from singer_sdk.testing import get_tap_test_class from tap_google_analytics.tap import TapGoogleAnalytics -from .utilities import get_secrets_dict +from .utilities import get_secrets_dict, setup SAMPLE_CONFIG_SERVICE = { "view_id": "188392047", @@ -24,26 +23,15 @@ "client_secrets": get_secrets_dict(), } +# setup client secrets file +setup() # Run standard built-in tap tests from the SDK with SAMPLE_CONFIG_SERVICE -TapGoogleAnalyticsService = get_tap_test_class( +TestTapGoogleAnalyticsService = get_tap_test_class( tap_class=TapGoogleAnalytics, config=SAMPLE_CONFIG_SERVICE ) - -class TestTapGoogleAnalyticsService(TapGoogleAnalyticsService): - @pytest.fixture - def resource(self, config): - yield - - # Run standard built-in tap tests from the SDK with SAMPLE_CONFIG_CLIENT_SECRETS -TapGoogleAnalyticsClientSecrets = get_tap_test_class( +TestTapGoogleAnalyticsClientSecrets = get_tap_test_class( tap_class=TapGoogleAnalytics, config=SAMPLE_CONFIG_CLIENT_SECRETS ) - - -class TestTapGoogleAnalyticsClientSecrets(TapGoogleAnalyticsClientSecrets): - @pytest.fixture - def resource(self, config): - yield diff --git a/tests/utilities.py b/tests/utilities.py index 42f9e5b..cc6f0e0 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -4,6 +4,15 @@ import os +def setup(): + """Write secrets file then clean it up after tests.""" + secrets_path = f"{os.path.dirname(__file__)}/test_data/client_secrets.json" + with open(secrets_path, "w") as f: + json.dump(get_secrets_dict(), f) + yield + os.remove(secrets_path) + + def get_secrets_dict(): """Return a secrets dictionary of based off the env var.""" secrets_var = os.environ["CLIENT_SECRETS"]