Skip to content

Commit

Permalink
refactor client secret resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Payne committed Jan 26, 2023
1 parent 44d7308 commit 42d17b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 34 deletions.
17 changes: 0 additions & 17 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 5 additions & 17 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
9 changes: 9 additions & 0 deletions tests/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 42d17b3

Please sign in to comment.