-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new test record creation helper function
Adds a function to create a dummy record alongside data. Updates a test to use this.
- Loading branch information
1 parent
35a33ac
commit 78f44bc
Showing
2 changed files
with
32 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
"""HEPData Test Fixtures""" | ||
|
||
import os | ||
import shutil | ||
import time | ||
from unittest import mock | ||
|
||
from invenio_accounts.models import Role, User | ||
|
@@ -37,8 +39,10 @@ | |
from hepdata.modules.dashboard.api import create_record_for_dashboard | ||
from hepdata.modules.records.importer.api import import_records, _download_file | ||
from hepdata.modules.records.utils.common import get_record_by_id | ||
from hepdata.modules.records.utils.submission import get_or_create_hepsubmission | ||
from hepdata.modules.records.utils.data_files import get_data_path_for_record | ||
from hepdata.modules.records.utils.submission import get_or_create_hepsubmission, process_submission_directory | ||
from hepdata.modules.records.utils.workflow import create_record | ||
from hepdata.modules.submission.views import process_submission_payload | ||
|
||
TEST_EMAIL = '[email protected]' | ||
TEST_PWD = 'hello1' | ||
|
@@ -163,17 +167,39 @@ def load_submission(app, load_default_data): | |
|
||
def create_blank_test_record(): | ||
""" | ||
Helper function to create a single, blank record | ||
Helper function to create a single, blank, finished submission | ||
:returns submission: The newly created submission object | ||
""" | ||
record_information = create_record( | ||
{'journal_info': 'Journal', 'title': 'Test Paper'}) | ||
recid = record_information['recid'] | ||
submission = get_or_create_hepsubmission(recid) | ||
# Set overall status to finished so related data appears on dashboard | ||
submission.overall_status = 'finished' | ||
record = get_record_by_id(recid) | ||
user = User(email=f'[email protected]', password='hello1', active=True, | ||
id=1) | ||
test_submissions = {} | ||
create_record_for_dashboard(recid, test_submissions, user) | ||
return submission | ||
|
||
|
||
def create_test_record(file_location): | ||
""" | ||
Helper function to create a dummy record with data. | ||
:param file_location: Path to the data directory. | ||
:returns test_submission: The newly created submission object | ||
""" | ||
record = {'title': 'HEPData Testing', | ||
'reviewer': {'name': 'Testy McTester', 'email': '[email protected]'}, | ||
'uploader': {'name': 'Testy McTester', 'email': '[email protected]'}, | ||
'message': 'This is ready', | ||
'user_id': 1} | ||
# Set up a new test submission | ||
test_submission = process_submission_payload(**record) | ||
# Ensure the status is set to `finished` so the related data can be accessed. | ||
test_submission.overall_status = 'finished' | ||
record_dir = get_data_path_for_record(test_submission.publication_recid, str(int(round(time.time())))) | ||
shutil.copytree(file_location, record_dir) | ||
process_submission_directory(record_dir, os.path.join(record_dir, 'submission.yaml'), | ||
test_submission.publication_recid) | ||
return test_submission |
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 |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
from hepdata.modules.submission.models import DataSubmission, HEPSubmission, RelatedRecid | ||
from hepdata.modules.submission.views import process_submission_payload | ||
from hepdata.config import HEPDATA_DOI_PREFIX | ||
from tests.conftest import create_test_record | ||
|
||
|
||
def test_submission_endpoint(app, client): | ||
|
@@ -332,26 +333,12 @@ def test_related_records(app, admin_idx): | |
{"dir" : "related_submission_3", "related" : None}, | ||
{"dir": "related_submission_4", "related": None} | ||
] | ||
# Dummy record data | ||
record = {'title': 'HEPData Testing', | ||
'reviewer': {'name': 'Testy McTester', 'email': '[email protected]'}, | ||
'uploader': {'name': 'Testy McTester', 'email': '[email protected]'}, | ||
'message': 'This is ready', | ||
'user_id': 1} | ||
base_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
# Begin submission of test submissions | ||
for data in test_data: | ||
# Set up a new test submission | ||
test_sub = process_submission_payload(**record) | ||
data['sub'] = test_sub | ||
# Ensure the status is set to `finished` so the related data can be accessed. | ||
test_sub.overall_status = 'finished' | ||
test_directory = os.path.join(base_dir, test_dir, data['dir']) | ||
record_dir = get_data_path_for_record(test_sub.publication_recid, str(int(round(time.time())))) | ||
shutil.copytree(test_directory, record_dir) | ||
process_submission_directory(record_dir, os.path.join(record_dir, 'submission.yaml'), | ||
test_sub.publication_recid) | ||
location = os.path.join(base_dir, test_dir, data['dir']) | ||
data['sub'] = create_test_record(location) | ||
|
||
# Checking against results in test_data | ||
for data in test_data: | ||
|