Skip to content

Commit

Permalink
configuring tests to load env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
kylevillegas93 committed Jan 10, 2025
1 parent d3c7c4d commit 521a120
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 50 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ jobs:
integration-tests:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
NYPL_API_CLIENT_ID: ${{ secrets.NYPL_API_CLIENT_ID }}
NYPL_API_CLIENT_SECRET: ${{ secrets.NYPL_API_CLIENT_SECRET }}
NYPL_API_TOKEN_URL: ${{ secrets.NYPL_API_TOKEN_URL }}
AWS_ACCESS: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ENVIRONMENT: qa
steps:
- uses: actions/checkout@v3
Expand All @@ -37,7 +34,6 @@ jobs:
- name: Install dependencies
run: |
make unit-deps
# TODO: is this the right flow?
- name: Run functional tests
run: |
make functional
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ help:
@echo "make help"

unit:
python -m pytest --cov-report term-missing --cov=. tests/unit
python -m pytest --cov-report term-missing --cov=. tests/unit --env=$(ENV)

allure-test:
python -m pytest --alluredir=./allure-results ./tests/unit
functional:
python -m pytest tests/functional --env=$(ENV)

integration:
python -m pytest tests/integration
python -m pytest tests/integration --env=$(ENV)

up:
$(compose_command) up -d
Expand Down
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import pytest

from load_env import load_env_file


def pytest_addoption(parser):
parser.addoption('--env', action='store', default='local', help='Environment to use for tests')


@pytest.fixture(scope='session', autouse=True)
def setup_env(pytestconfig):
environment = os.environ.get('ENVIRONMENT') or pytestconfig.getoption('--env')

if environment in ['local', 'qa']:
load_env_file(environment, file_string=f'config/{environment}.yaml')
4 changes: 2 additions & 2 deletions tests/functional/processes/ingest/assert_ingested_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def assert_ingested_records(source_name: str):
db_manager.generateEngine()
db_manager.createSession()

doab_records = (
records = (
db_manager.session.query(Record)
.filter(Record.source == source_name)
.filter(Record.date_modified > datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(minutes=5))
.all()
)

assert len(doab_records) > 1
assert len(records) > 1
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from processes import ChicagoISACProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_chigaco_isac_process():
isac_process = ChicagoISACProcess('complete', None, None, None, 5, None)
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/processes/ingest/test_doab_process.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from processes import DOABProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_doab_process():
doab_process = DOABProcess('complete', None, None, None, 5, None)
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/processes/ingest/test_gutenberg_process.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from processes import GutenbergProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_gutenberg_process():
gutenberg_process = GutenbergProcess('complete', None, None, None, 5, None)
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/processes/ingest/test_loc_process.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from processes import LOCProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_loc_process():
loc_process = LOCProcess('complete', None, None, None, 5, None)
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/processes/ingest/test_met_process.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from processes import LOCProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_met_process():
met_process = LOCProcess('complete', None, None, None, 5, None)
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/processes/ingest/test_muse_process.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from processes import MUSEProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_muse_process():
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/processes/ingest/test_nypl_process.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from processes import NYPLProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_nypl_process():
nypl_process = NYPLProcess('complete', None, None, None, 5, None)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from processes import PublisherBacklistProcess
from load_env import load_env_file
from .assert_ingested_records import assert_ingested_records

load_env_file('local', file_string='config/local.yaml')


def test_publisher_backlist_process():
publisher_backlist_project = PublisherBacklistProcess('complete', None, None, None, 5, None)
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/services/sources/test_nypl_bib_service.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from datetime import datetime, timezone, timedelta
import pytest

from load_env import load_env_file
from services import NYPLBibService

class TestNYPLBibService:
@pytest.fixture
def test_instance(self):
load_env_file('local', file_string='config/local.yaml')
return NYPLBibService()

def test_get_records(self, test_instance: NYPLBibService):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from datetime import datetime, timezone, timedelta
import pytest

from load_env import load_env_file
from services import PublisherBacklistService

class TestPublisherBacklistService:
@pytest.fixture
def test_instance(self):
load_env_file('local', file_string='config/local.yaml')
return PublisherBacklistService()

def test_get_records(self, test_instance: PublisherBacklistService):
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/test_google_integration.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os
import pytest
from load_env import load_env_file
from services import GoogleDriveService

load_env_file('local-compose', file_string='config/local-compose.yaml')

class TestGoogleDriveService:
@pytest.fixture
def test_instance(self):
load_env_file('local', file_string='config/local.yaml')
return GoogleDriveService()

def test_get_drive_file(self, test_instance: GoogleDriveService):
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/test_oclc_auth_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from managers.oclc_auth import OCLCAuthManager
from load_env import load_env_file

load_env_file('local-compose', file_string='config/local-compose.yaml')


def test_get_search_token():
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/test_oclc_catalog_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import pytest
from load_env import load_env_file
from managers import OCLCCatalogManager

class TestOCLCCatalogManager:
@pytest.fixture
def test_instance(self):
load_env_file('local-compose', file_string='config/local-compose.yaml')
return OCLCCatalogManager()

def test_query_bibs(self, test_instance: OCLCCatalogManager):
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/test_ssm_service.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
import pytest
from load_env import load_env_file

from services.ssm_service import SSMService

class TestSSMService:
@pytest.fixture
def test_instance(self):
load_env_file('local', file_string='config/local.yaml')
return SSMService()

def test_get_parameter(self, test_instance):
Expand Down

0 comments on commit 521a120

Please sign in to comment.