-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SFR-2481/save_test_data #543
Changes from 3 commits
70ffcf8
79c57ce
18c34f0
353864a
ad2413f
c1a51de
214d5c3
f19d997
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import os | ||
import pytest | ||
|
||
from datetime import datetime, timezone | ||
import json | ||
from uuid import uuid4 | ||
from processes import ClusterProcess | ||
from model import Record, Item | ||
from logger import create_log | ||
from managers import DBManager | ||
from load_env import load_env_file | ||
|
||
logger = create_log(__name__) | ||
|
||
TEST_SOURCE = 'test_source' | ||
|
||
def pytest_addoption(parser): | ||
parser.addoption('--env', action='store', default='local', help='Environment to use for tests') | ||
|
@@ -16,3 +25,69 @@ def setup_env(pytestconfig, request): | |
|
||
if not running_unit_tests and environment in ['local', 'qa']: | ||
load_env_file(environment, file_string=f'config/{environment}.yaml') | ||
|
||
@pytest.fixture(scope='module') | ||
def db_manager(): | ||
db_manager = DBManager() | ||
db_manager.createSession() | ||
yield db_manager | ||
db_manager.close_connection() | ||
ayan1229 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@pytest.fixture(scope='module') | ||
def seed_test_data(db_manager): | ||
flags = { 'catalog': False, 'download': False, 'reader': False, 'embed': True } | ||
test_data = { | ||
'title': 'test data 1', | ||
'uuid': uuid4(), | ||
'frbr_status': 'complete', | ||
'cluster_status': False, | ||
"source": TEST_SOURCE, | ||
'authors': ['Ayan||true'], | ||
'languages': ['Serbian'], | ||
'dates': ['1907-|publication_date'], | ||
'publisher': ['Project Gutenberg Literary Archive Foundation||'], | ||
'identifiers': [], | ||
'source_id': '4064148285|test', | ||
'contributors': ['Metropolitan Museum of Art (New York, N.Y.)|||contributor','Metropolitan Museum of Art (New York, N.Y.)|||repository','Thomas J. Watson Library|||provider'], | ||
'extent': ('11, 164 p. ;'), | ||
'is_part_of': ['Tauchnitz edition|Vol. 4560|volume'], | ||
'abstract': ['test abstract 1', 'test abstract 2'], | ||
'subjects': ['test subjects 1||'], | ||
'rights': ('hathitrust|public_domain|expiration of copyright term for non-US work with corporate author|Public Domain|2021-10-02 05:25:13'), | ||
'has_part': [f'1|example.com/1.pdf|{TEST_SOURCE}|text/html|{json.dumps(flags)}'] | ||
} | ||
|
||
existing_record = db_manager.session.query(Record).filter_by(source_id=test_data['source_id']).first() | ||
|
||
if existing_record: | ||
for key, value in test_data.items(): | ||
if key != 'uuid' and hasattr(existing_record, key): | ||
setattr(existing_record, key, value) | ||
existing_record.date_modified = datetime.now(timezone.utc).replace(tzinfo=None) | ||
test_data['uuid'] = existing_record.uuid | ||
test_record = existing_record | ||
else: | ||
test_record = Record(**test_data) | ||
db_manager.session.add(test_record) | ||
|
||
db_manager.session.commit() | ||
|
||
ayan1229 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
item = db_manager.session.query(Item).filter_by(record_id=test_record.id).first() | ||
edition_id = str(item.edition_id) if item else None | ||
|
||
return { | ||
'edition_id': edition_id, | ||
'uuid': str(test_data['uuid']) | ||
} | ||
|
||
@pytest.fixture(scope='module') | ||
def seeded_edition_id(request, seed_test_data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to double check but I think because we have seed_test_data here it'll automatically make sure seed_test_data is resolved. Thus, checking the request may not make sense. |
||
if 'functional' in request.keywords or 'integration' in request.keywords: | ||
return seed_test_data['edition_id'] | ||
return None | ||
|
||
@pytest.fixture(scope='module') | ||
def seeded_uuid(request, seed_test_data): | ||
if 'functional' in request.keywords or 'integration' in request.keywords: | ||
return seed_test_data['uuid'] | ||
return None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import pytest | ||
import requests | ||
import json | ||
from .constants import API_URL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so the API_URL will have to change depending in the env. I think we can get this from the config file - DRB_API_HOST |
||
from .utils import assert_response_status | ||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize("endpoint, expected_status", [ | ||
("/editions/1982731", 200), | ||
("/editions/{seeded_edition_id}", 200), | ||
("/editions/00000000-0000-0000-0000-000000000000", 400), | ||
("/editions/invalid_id_format", 400), | ||
("/editions/", 404), | ||
("/editions/%$@!*", 400) | ||
]) | ||
def test_get_edition(endpoint, expected_status): | ||
url = API_URL + endpoint | ||
def test_get_edition(endpoint, expected_status, seeded_edition_id): | ||
url = API_URL + endpoint.format(seeded_edition_id=seeded_edition_id) | ||
ayan1229 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
response = requests.get(url) | ||
|
||
assert response.status_code is not None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question on the module scope. does this run during the unit tests?
we just want to run it during functional and integration tests