-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
70ffcf8
SFR-2481/save_test_data
ayan1229 79c57ce
removed seed_test_data and moved to conftest.py
ayan1229 18c34f0
remove test data file and use fixture for using data
ayan1229 353864a
for kyle
ayan1229 ad2413f
reverting quote changes
kylevillegas93 c1a51de
fixing test
kylevillegas93 214d5c3
fixing source priority
kylevillegas93 f19d997
Set env variables in CI
kylevillegas93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,72 @@ 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
|
||
cluster_process = ClusterProcess('complete', None, None, str(test_data['uuid']), None) | ||
cluster_process.runProcess() | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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