diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 60b5d47ac08356a82d051e9fffea588221fbd831..d4a45ae063c6b185382acd230f6f99120f2ad5b6 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -29,23 +29,23 @@ def create_auth_headers(token: str): @pytest.fixture(scope='module') -def admin_user_auth(admin_user: User): - return create_auth_headers(admin_user.user_id) +def user0_auth(user0: User): + return create_auth_headers(user0.user_id) @pytest.fixture(scope='module') -def test_user_auth(test_user: User): - return create_auth_headers(test_user.user_id) +def user1_auth(user1: User): + return create_auth_headers(user1.user_id) @pytest.fixture(scope='module') -def other_test_user_auth(other_test_user: User): - return create_auth_headers(other_test_user.user_id) +def user2_auth(user2: User): + return create_auth_headers(user2.user_id) @pytest.fixture(scope='module') -def yet_test_user_auth(yet_test_user: User): - return create_auth_headers(yet_test_user.user_id) +def user3_auth(user3: User): + return create_auth_headers(user3.user_id) @pytest.fixture(scope='module') @@ -54,21 +54,21 @@ def invalid_user_auth(): @pytest.fixture(scope='module') -def app_token_auth(test_user: User): - app_token = generate_simple_token(test_user.user_id, expires_in=3600) +def app_token_auth(user1: User): + app_token = generate_simple_token(user1.user_id, expires_in=3600) return create_auth_headers(app_token) @pytest.fixture(scope='module') -def test_auth_dict( - admin_user, - test_user, - other_test_user, - yet_test_user, - admin_user_auth, - test_user_auth, - other_test_user_auth, - yet_test_user_auth, +def auth_dict( + user0, + user1, + user2, + user3, + user0_auth, + user1_auth, + user2_auth, + user3_auth, invalid_user_auth, ): """ @@ -76,13 +76,10 @@ def test_auth_dict( contains an example of invalid credentials, and the key None contains (None, None). """ return { - 'admin_user': (admin_user_auth, generate_upload_token(admin_user)), - 'test_user': (test_user_auth, generate_upload_token(test_user)), - 'other_test_user': ( - other_test_user_auth, - generate_upload_token(other_test_user), - ), - 'yet_test_user': (yet_test_user_auth, generate_upload_token(yet_test_user)), + 'user0': (user0_auth, generate_upload_token(user0)), + 'user1': (user1_auth, generate_upload_token(user1)), + 'user2': (user2_auth, generate_upload_token(user2)), + 'user3': (user3_auth, generate_upload_token(user3)), 'invalid': (invalid_user_auth, 'invalid.upload.token'), None: (None, None), } diff --git a/tests/app/test_dcat.py b/tests/app/test_dcat.py index 9fa83c53685969669e3e4d5ee25e732055af39d8..8e5b4b68291cd6e30faf8a9ae4b8b49fea7b4172 100644 --- a/tests/app/test_dcat.py +++ b/tests/app/test_dcat.py @@ -43,23 +43,23 @@ def create_dataset(**kwargs): @pytest.fixture(scope='module') -def data(test_user, other_test_user, elastic_infra, mongo_module): +def data(user1, user2, elastic_infra, mongo_module): example_attrs = dict( entry_id='test-id', upload_id='upload-id', last_processing_time=datetime.now(), - entry_coauthors=[other_test_user], + entry_coauthors=[user2], datasets=[ create_dataset( dataset_id='dataset_1', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='test dataset 1', dataset_type='owned', doi='TEST/DOI', ), create_dataset( dataset_id='dataset_2', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='test dataset 2', dataset_type='owned', ), @@ -67,7 +67,7 @@ def data(test_user, other_test_user, elastic_infra, mongo_module): comment='this is an entry comment', ) - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload( upload_id='upload-id', upload_create_time=datetime(2000, 1, 1), diff --git a/tests/app/test_h5grove.py b/tests/app/test_h5grove.py index fe470f914669c16560e92c78c05cc04343c46ba5..b62e4b0aa808f8b124ae34c8b88f118c5efebf46 100644 --- a/tests/app/test_h5grove.py +++ b/tests/app/test_h5grove.py @@ -38,8 +38,8 @@ def upload_id(): @pytest.fixture -def example_data_nxs(test_user, upload_id): - data = ExampleData(main_author=test_user) +def example_data_nxs(user1, upload_id): + data = ExampleData(main_author=user1) data.create_upload(upload_id) data.create_entry(upload_id=upload_id, entry_id='nexus_test_entry') data.save(with_files=False, with_mongo=True) @@ -50,11 +50,11 @@ def example_data_nxs(test_user, upload_id): [ pytest.param('invalid', 401, 'test.h5', id='invalid-credentials'), pytest.param(None, 401, 'test.h5', id='no-credentials'), - pytest.param('test_user', 404, 'some_other.h5', id='file-not-found'), + pytest.param('user1', 404, 'some_other.h5', id='file-not-found'), pytest.param( - 'test_user', 200, 'test.h5', id='file-in-published' + 'user1', 200, 'test.h5', id='file-in-published' ), # TODO: Implement fetching from published upload - pytest.param('test_user', 200, 'test.h5', id='file-in-staging'), + pytest.param('user1', 200, 'test.h5', id='file-in-staging'), ], ) def test_h5grove( @@ -62,12 +62,12 @@ def test_h5grove( upload_id, proc_infra, example_data_nxs, - test_auth_dict, + auth_dict, user, status_code, file_name, ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] test_file = 'test.h5' file_path = f'{StagingUploadFiles(upload_id=upload_id, create=True)._raw_dir}{os.sep}{test_file}' h5file = h5py.File(file_path, 'w') diff --git a/tests/app/test_optimade.py b/tests/app/test_optimade.py index 0e02c2baf704bc7db27f992e7a344ca956ded094..468ca15fc71851cf4d59eebac174e64913eacedc 100644 --- a/tests/app/test_optimade.py +++ b/tests/app/test_optimade.py @@ -40,9 +40,9 @@ def test_get_entry(published: Upload): def test_no_optimade( - mongo_function, elastic_function, raw_files_function, client, test_user + mongo_function, elastic_function, raw_files_function, client, user1 ): - example_data = ExampleData(main_author=test_user) + example_data = ExampleData(main_author=user1) example_data.create_upload( upload_id='test_upload', published=True, embargo_length=0 ) @@ -57,11 +57,11 @@ def test_no_optimade( @pytest.fixture(scope='module') -def example_structures(elastic_infra, mongo_module, raw_files_infra, test_user): +def example_structures(elastic_infra, mongo_module, raw_files_infra, user1): clear_elastic(elastic_infra) mongo_module.drop_database('test_db') - example_data = ExampleData(main_author=test_user) + example_data = ExampleData(main_author=user1) example_data.create_upload( upload_id='test_upload', upload_create_time='1978-04-08T10:10:00Z', diff --git a/tests/app/v1/routers/common.py b/tests/app/v1/routers/common.py index 3a382797098bd390456560815949bdf7cc3782ea..0a110337de4f0da23349370db68bb96c92ed38ff 100644 --- a/tests/app/v1/routers/common.py +++ b/tests/app/v1/routers/common.py @@ -286,33 +286,21 @@ def owner_test_parameters(): pytest.param('admin', None, 401, -1, -1, -1, id='admin-wo-auth'), pytest.param('shared', None, 401, -1, -1, -1, id='shared-wo-auth'), pytest.param('public', None, 200, 23, 23, 6, id='public-wo-auth'), - pytest.param('user', 'test_user', 200, 32, 30, 13, id='user-test-user'), - pytest.param('staging', 'test_user', 200, 6, 4, 4, id='staging-test-user'), - pytest.param('visible', 'test_user', 200, 32, 30, 13, id='visible-test-user'), - pytest.param('admin', 'test_user', 401, -1, -1, -1, id='admin-test-user'), - pytest.param('shared', 'test_user', 200, 32, 30, 13, id='shared-test-user'), - pytest.param('public', 'test_user', 200, 23, 23, 6, id='public-test-user'), - pytest.param( - 'user', 'other_test_user', 200, 0, 0, 0, id='user-other-test-user' - ), - pytest.param( - 'staging', 'other_test_user', 200, 2, 2, 2, id='staging-other-test-user' - ), - pytest.param( - 'visible', 'other_test_user', 200, 27, 27, 10, id='visible-other-test-user' - ), - pytest.param( - 'shared', 'other_test_user', 200, 4, 4, 4, id='shared-other-test-user' - ), - pytest.param( - 'public', 'other_test_user', 200, 23, 23, 6, id='public-other-test-user' - ), + pytest.param('user', 'user1', 200, 32, 30, 13, id='user-user1'), + pytest.param('staging', 'user1', 200, 6, 4, 4, id='staging-user1'), + pytest.param('visible', 'user1', 200, 32, 30, 13, id='visible-user1'), + pytest.param('admin', 'user1', 401, -1, -1, -1, id='admin-user1'), + pytest.param('shared', 'user1', 200, 32, 30, 13, id='shared-user1'), + pytest.param('public', 'user1', 200, 23, 23, 6, id='public-user1'), + pytest.param('user', 'user2', 200, 0, 0, 0, id='user-user2'), + pytest.param('staging', 'user2', 200, 2, 2, 2, id='staging-user2'), + pytest.param('visible', 'user2', 200, 27, 27, 10, id='visible-user2'), + pytest.param('shared', 'user2', 200, 4, 4, 4, id='shared-user2'), + pytest.param('public', 'user2', 200, 23, 23, 6, id='public-user2'), pytest.param('all', None, 200, 26, 26, 9, id='metadata-all-wo-auth'), - pytest.param('all', 'test_user', 200, 32, 30, 13, id='metadata-all-test-user'), - pytest.param( - 'all', 'other_test_user', 200, 28, 28, 11, id='metadata-all-other-test-user' - ), - pytest.param('admin', 'admin_user', 200, 32, 30, 13, id='admin-admin-user'), + pytest.param('all', 'user1', 200, 32, 30, 13, id='metadata-all-user1'), + pytest.param('all', 'user2', 200, 28, 28, 11, id='metadata-all-user2'), + pytest.param('admin', 'user0', 200, 32, 30, 13, id='admin-user0'), pytest.param('all', 'bad_user', 401, -1, -1, -1, id='bad-credentials'), ] @@ -490,7 +478,7 @@ def aggregation_test_parameters( str['total'], min(str['size'], default_size), 200, - 'test_user', + 'user1', id='terms-str', ), pytest.param( @@ -498,7 +486,7 @@ def aggregation_test_parameters( enum['total'], min(enum['size'], default_size), 200, - 'test_user', + 'user1', id='terms-enum', ), pytest.param( @@ -506,7 +494,7 @@ def aggregation_test_parameters( bool['total'], min(bool['size'], default_size), 200, - 'test_user', + 'user1', id='terms-bool', ), pytest.param( @@ -514,7 +502,7 @@ def aggregation_test_parameters( 0, 0, 200, - 'test_user', + 'user1', id='no-results', ), pytest.param( @@ -522,7 +510,7 @@ def aggregation_test_parameters( default_total, min(default_total, default_size), 200, - 'test_user', + 'user1', id='entries', ), pytest.param( @@ -530,7 +518,7 @@ def aggregation_test_parameters( default_total, min(default_total, default_size), 200, - 'test_user', + 'user1', id='entries-size', ), pytest.param( @@ -538,7 +526,7 @@ def aggregation_test_parameters( -1, -1, 422, - 'test_user', + 'user1', id='bad-entries', ), pytest.param( @@ -554,7 +542,7 @@ def aggregation_test_parameters( str['total'], min(str['size'], default_size), 200, - 'test_user', + 'user1', id='entries-include', ), pytest.param( @@ -570,7 +558,7 @@ def aggregation_test_parameters( str['total'], min(str['size'], default_size), 200, - 'test_user', + 'user1', id='entries-exclude', ), pytest.param( @@ -626,7 +614,7 @@ def aggregation_test_parameters( pagination['total'], min(pagination['size'], default_size), 200, - 'test_user', + 'user1', id='order-direction', ), pytest.param( @@ -639,7 +627,7 @@ def aggregation_test_parameters( pagination['total'], pagination['page_after_value_size'], 200, - 'test_user', + 'user1', id='after', ), pytest.param( @@ -680,7 +668,7 @@ def aggregation_test_parameters( histogram_date['default_size'], histogram_date['default_size'], 200, - 'test-user', + 'user1', id='date-histogram-default', ), pytest.param( @@ -693,7 +681,7 @@ def aggregation_test_parameters( histogram_date['interval_size'], histogram_date['interval_size'], 200, - 'test-user', + 'user1', id='date-histogram-interval', ), pytest.param( @@ -707,7 +695,7 @@ def aggregation_test_parameters( histogram_date['interval_size'], histogram_date['interval_size'], 200, - 'test-user', + 'user1', id='date-histogram-metrics', ), pytest.param( @@ -715,7 +703,7 @@ def aggregation_test_parameters( -1, -1, 422, - 'test-user', + 'user1', id='date-histogram-no-date', ), pytest.param( @@ -723,7 +711,7 @@ def aggregation_test_parameters( -1, -1, 400, - 'test-user', + 'user1', id='date-histogram-bad-interval', ), # Int histogram @@ -750,7 +738,7 @@ def aggregation_test_parameters( histogram_int['bucket_size'], histogram_int['bucket_size'], 200, - 'test-user', + 'user1', id='histogram-buckets', ), pytest.param( @@ -822,7 +810,7 @@ def aggregation_test_parameters( pagination['total'], min(pagination['size'], default_size), 200, - 'test_user', + 'user1', id='order-str', ), pytest.param( @@ -835,7 +823,7 @@ def aggregation_test_parameters( pagination['total'], min(pagination['size'], default_size), 200, - 'test_user', + 'user1', id='order-date', ), pytest.param( @@ -848,7 +836,7 @@ def aggregation_test_parameters( pagination['total'], min(pagination['size'], default_size), 200, - 'test_user', + 'user1', id='order-int', ), pytest.param( @@ -866,7 +854,7 @@ def aggregation_test_parameters( pagination['total'], pagination['page_after_value_size'], 200, - 'test_user', + 'user1', id='after-order', ), ] @@ -1375,7 +1363,7 @@ def assert_query_response(client, test_method, query, total, status_code): def assert_aggregation_response( client, - test_user_auth, + user1_auth, aggregation, total, size, @@ -1385,8 +1373,8 @@ def assert_aggregation_response( ): """Checks that the aggregation response is as expected.""" headers = {} - if user == 'test_user': - headers = test_user_auth + if user == 'user1': + headers = user1_auth agg_id = 'test_agg_name' aggregations = {agg_id: aggregation} @@ -1532,9 +1520,9 @@ def perform_materials_metadata_test(*args, **kwargs): def perform_owner_test( client, - test_user_auth, - other_test_user_auth, - admin_user_auth, + user0_auth, + user1_auth, + user2_auth, owner, user, status_code, @@ -1543,12 +1531,12 @@ def perform_owner_test( test_method, ): headers = None - if user == 'test_user': - headers = test_user_auth - elif user == 'other_test_user': - headers = other_test_user_auth - elif user == 'admin_user': - headers = admin_user_auth + if user == 'user1': + headers = user1_auth + elif user == 'user2': + headers = user2_auth + elif user == 'user0': + headers = user0_auth elif user == 'bad_user': headers = {'Authorization': 'Bearer NOTATOKEN'} diff --git a/tests/app/v1/routers/test_auth.py b/tests/app/v1/routers/test_auth.py index 5d625a192984408c11885fd4f944462978eed307..4d568065108643343ee287331171e013ad04708b 100644 --- a/tests/app/v1/routers/test_auth.py +++ b/tests/app/v1/routers/test_auth.py @@ -34,8 +34,8 @@ def perform_get_token_test(client, http_method, status_code, username, password) @pytest.mark.parametrize('http_method', ['post', 'get']) -def test_get_token(client, test_user, http_method): - perform_get_token_test(client, http_method, 200, test_user.username, 'password') +def test_get_token(client, user1, http_method): + perform_get_token_test(client, http_method, 200, user1.username, 'password') @pytest.mark.parametrize('http_method', ['post', 'get']) @@ -43,8 +43,8 @@ def test_get_token_bad_credentials(client, http_method): perform_get_token_test(client, http_method, 401, 'bad', 'credentials') -def test_get_signature_token(client, test_user_auth): - response = client.get('auth/signature_token', headers=test_user_auth) +def test_get_signature_token(client, user1_auth): + response = client.get('auth/signature_token', headers=user1_auth) assert response.status_code == 200 assert response.json().get('signature_token') is not None @@ -66,9 +66,9 @@ def test_get_signature_token_unauthorized(client, invalid_user_auth): (None, 422), ], ) -def test_get_app_token(client, test_user_auth, expires_in, status_code): +def test_get_app_token(client, user1_auth, expires_in, status_code): response = client.get( - 'auth/app_token', headers=test_user_auth, params={'expires_in': expires_in} + 'auth/app_token', headers=user1_auth, params={'expires_in': expires_in} ) assert response.status_code == status_code if status_code == 200: diff --git a/tests/app/v1/routers/test_datasets.py b/tests/app/v1/routers/test_datasets.py index 1e26124b3d4b39ac78ba789a108626008f987d05..71fc63d57a2d3a9970b1a780cacc0bcfbcfbc00b 100644 --- a/tests/app/v1/routers/test_datasets.py +++ b/tests/app/v1/routers/test_datasets.py @@ -53,10 +53,8 @@ def create_dataset(**kwargs): @pytest.fixture(scope='function') -def data( - elastic_function, raw_files_function, mongo_function, test_user, other_test_user -): - data = ExampleData(main_author=test_user) +def data(elastic_function, raw_files_function, mongo_function, user1, user2): + data = ExampleData(main_author=user1) data.create_upload(upload_id='upload_1', published=True) data.create_entry( upload_id='upload_1', @@ -65,13 +63,13 @@ def data( datasets=[ create_dataset( dataset_id='dataset_1', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='test dataset 1', dataset_type='owned', ), create_dataset( dataset_id='dataset_2', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='test dataset 2', dataset_type='owned', ), @@ -85,13 +83,13 @@ def data( datasets=[ create_dataset( dataset_id='dataset_listed', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='foreign test dataset', dataset_type='foreign', ), create_dataset( dataset_id='dataset_doi', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='foreign test dataset', dataset_type='foreign', doi='test_doi', @@ -238,23 +236,23 @@ def test_dataset(client, data, dataset_id, result, status_code): 'dataset_name, dataset_type, query, entries, user, status_code', [ pytest.param( - 'another test dataset', 'foreign', None, None, 'test_user', 200, id='plain' + 'another test dataset', 'foreign', None, None, 'user1', 200, id='plain' ), pytest.param( 'another test dataset', 'foreign', None, None, None, 401, id='no-user' ), pytest.param( - 'test dataset 1', 'foreign', None, None, 'test_user', 400, id='exists' + 'test dataset 1', 'foreign', None, None, 'user1', 400, id='exists' ), pytest.param( - 'another test dataset', 'owned', None, None, 'test_user', 200, id='owned' + 'another test dataset', 'owned', None, None, 'user1', 200, id='owned' ), pytest.param( 'another test dataset', 'owned', {}, None, - 'test_user', + 'user1', 200, id='owned-owner-query', ), @@ -263,7 +261,7 @@ def test_dataset(client, data, dataset_id, result, status_code): 'owned', {}, None, - 'other_test_user', + 'user2', 200, id='owned-non-owner-query', ), @@ -272,7 +270,7 @@ def test_dataset(client, data, dataset_id, result, status_code): 'owned', None, ['id_01', 'id_02'], - 'test_user', + 'user1', 200, id='owned-owner-entries', ), @@ -281,7 +279,7 @@ def test_dataset(client, data, dataset_id, result, status_code): 'owned', None, ['id_01', 'id_02'], - 'other_test_user', + 'user2', 200, id='owned-non-owner-entries', ), @@ -290,7 +288,7 @@ def test_dataset(client, data, dataset_id, result, status_code): 'foreign', {}, None, - 'test_user', + 'user1', 200, id='foreign-query', ), @@ -299,7 +297,7 @@ def test_dataset(client, data, dataset_id, result, status_code): 'foreign', None, ['id_01', 'id_02'], - 'test_user', + 'user1', 200, id='foreign-entries', ), @@ -309,10 +307,10 @@ def test_post_datasets( client, data, example_data, - test_user, - test_user_auth, - other_test_user, - other_test_user_auth, + user1, + user1_auth, + user2, + user2_auth, dataset_name, dataset_type, query, @@ -326,12 +324,12 @@ def test_post_datasets( if entries is not None: dataset['entries'] = entries auth = None - if user == 'test_user': - auth = test_user_auth - user = test_user - elif user == 'other_test_user': - auth = other_test_user_auth - user = other_test_user + if user == 'user1': + auth = user1_auth + user = user1 + elif user == 'user2': + auth = user2_auth + user = user2 response = client.post('datasets/', headers=auth, json=dataset) assert_response(response, status_code=status_code) @@ -354,21 +352,21 @@ def test_post_datasets( @pytest.mark.parametrize( 'dataset_id, user, status_code', [ - pytest.param('dataset_listed', 'test_user', 200, id='plain'), + pytest.param('dataset_listed', 'user1', 200, id='plain'), pytest.param('dataset_listed', None, 401, id='no-user'), - pytest.param('dataset_listed', 'other_test_user', 401, id='wrong-user'), - pytest.param('DOESNOTEXIST', 'test_user', 404, id='does-not-exist'), - pytest.param('dataset_doi', 'test_user', 400, id='with-doi'), + pytest.param('dataset_listed', 'user2', 401, id='wrong-user'), + pytest.param('DOESNOTEXIST', 'user1', 404, id='does-not-exist'), + pytest.param('dataset_doi', 'user1', 400, id='with-doi'), ], ) def test_delete_dataset( - client, data, test_user_auth, other_test_user_auth, dataset_id, user, status_code + client, data, user1_auth, user2_auth, dataset_id, user, status_code ): auth = None - if user == 'test_user': - auth = test_user_auth - if user == 'other_test_user': - auth = other_test_user_auth + if user == 'user1': + auth = user1_auth + if user == 'user2': + auth = user2_auth response = client.delete('datasets/%s' % dataset_id, headers=auth) assert_response(response, status_code=status_code) @@ -382,25 +380,25 @@ def test_delete_dataset( @pytest.mark.parametrize( 'dataset_id, user, status_code', [ - pytest.param('dataset_1', 'test_user', 200, id='plain'), + pytest.param('dataset_1', 'user1', 200, id='plain'), pytest.param('dataset_1', None, 401, id='no-user'), - pytest.param('dataset_1', 'other_test_user', 401, id='wrong-user'), - pytest.param('dataset_doi', 'test_user', 400, id='with-doi'), - pytest.param('unpublished', 'test_user', 400, id='unpublished'), - pytest.param('empty', 'test_user', 400, id='empty'), + pytest.param('dataset_1', 'user2', 401, id='wrong-user'), + pytest.param('dataset_doi', 'user1', 400, id='with-doi'), + pytest.param('unpublished', 'user1', 400, id='unpublished'), + pytest.param('empty', 'user1', 400, id='empty'), ], ) def test_assign_doi_dataset( client, data, - test_user, - test_user_auth, - other_test_user_auth, + user1, + user1_auth, + user2_auth, dataset_id, user, status_code, ): - more_data = ExampleData(main_author=test_user) + more_data = ExampleData(main_author=user1) more_data.create_upload(upload_id='unpublished', published=False) more_data.create_entry( upload_id='unpublished', @@ -409,7 +407,7 @@ def test_assign_doi_dataset( datasets=[ create_dataset( dataset_id='unpublished', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='test unpublished entries', dataset_type='owned', ) @@ -418,7 +416,7 @@ def test_assign_doi_dataset( create_dataset( dataset_id='empty', - user_id=test_user.user_id, + user_id=user1.user_id, dataset_name='test empty dataset', dataset_type='owned', ) @@ -426,10 +424,10 @@ def test_assign_doi_dataset( more_data.save(with_files=False) auth = None - if user == 'test_user': - auth = test_user_auth - if user == 'other_test_user': - auth = other_test_user_auth + if user == 'user1': + auth = user1_auth + if user == 'user2': + auth = user2_auth response = client.post('datasets/%s/action/doi' % dataset_id, headers=auth) assert_response(response, status_code=status_code) @@ -438,5 +436,5 @@ def test_assign_doi_dataset( json_response = response.json() dataset = json_response['data'] - assert_dataset(dataset, user_id=test_user.user_id) + assert_dataset(dataset, user_id=user1.user_id) assert dataset['doi'] is not None diff --git a/tests/app/v1/routers/test_entries.py b/tests/app/v1/routers/test_entries.py index 60252a7fb5618e273399e53da6227f275f84804a..2bb6e91a66a5cd12ab379ea139fe1d3818912c8a 100644 --- a/tests/app/v1/routers/test_entries.py +++ b/tests/app/v1/routers/test_entries.py @@ -402,12 +402,12 @@ def test_entries_all_metrics(client, example_data): aggregation_test_parameters_default('entries'), ) def test_entries_aggregations( - client, example_data, test_user_auth, aggregation, total, size, status_code, user + client, example_data, user1_auth, aggregation, total, size, status_code, user ): """Tests aggregation calls for regular statically mapped quantities.""" assert_aggregation_response( client, - test_user_auth, + user1_auth, aggregation, total, size, @@ -477,7 +477,7 @@ def test_entries_aggregations_dynamic( plugin_schema, client, example_data_schema_python, - test_user_auth, + user1_auth, aggregation, total, size, @@ -489,7 +489,7 @@ def test_entries_aggregations_dynamic( """ assert_aggregation_response( client, - test_user_auth, + user1_auth, aggregation, total, size, @@ -571,9 +571,7 @@ def test_entries_required(client, example_data, required, status_code, http_meth 'user, entry_id, required, status_code', [ pytest.param(None, 'id_01', {}, 200, id='id'), - pytest.param( - 'test_user', 'id_child_entries_child1', {}, 200, id='id-child-entry' - ), + pytest.param('user1', 'id_child_entries_child1', {}, 200, id='id-child-entry'), pytest.param(None, 'doesnotexist', {}, 404, id='404'), pytest.param( None, 'id_01', {'include': ['entry_id', 'upload_id']}, 200, id='include' @@ -589,9 +587,9 @@ def test_entries_required(client, example_data, required, status_code, http_meth ], ) def test_entry_metadata( - client, example_data, test_auth_dict, user, entry_id, required, status_code + client, example_data, auth_dict, user, entry_id, required, status_code ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.get( 'entries/%s?%s' % (entry_id, urlencode(required, doseq=True)), headers=user_auth ) @@ -609,7 +607,7 @@ def test_entry_metadata( pytest.param(None, None, {}, {}, 23, 5, 200, id='all'), pytest.param(None, None, {'entry_id': 'id_01'}, {}, 1, 5, 200, id='one-entry'), pytest.param( - 'test_user', + 'user1', 'visible', {'upload_id': 'id_child_entries'}, {}, @@ -627,7 +625,7 @@ def test_entry_metadata( def test_entries_rawdir( client, example_data, - test_auth_dict, + auth_dict, user, owner, query, @@ -637,7 +635,7 @@ def test_entries_rawdir( status_code, http_method, ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] perform_entries_rawdir_test( client, owner=owner, @@ -656,7 +654,7 @@ def test_entries_rawdir( [ pytest.param(None, None, {}, {}, 23, 5, 200, id='all'), pytest.param( - 'test_user', + 'user1', 'visible', {'upload_id': 'id_child_entries'}, {}, @@ -725,7 +723,7 @@ def test_entries_rawdir( def test_entries_raw( client, example_data, - test_auth_dict, + auth_dict, user, owner, query, @@ -735,7 +733,7 @@ def test_entries_raw( status_code, http_method, ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] perform_entries_raw_test( client, headers=user_auth, @@ -769,17 +767,15 @@ def test_entries_download_max( 'user, entry_id, files_per_entry, status_code', [ pytest.param(None, 'id_01', 5, 200, id='id'), - pytest.param( - 'test_user', 'id_child_entries_child1', 5, 200, id='child-entries' - ), + pytest.param('user1', 'id_child_entries_child1', 5, 200, id='child-entries'), pytest.param(None, 'id_embargo', -1, 404, id='embargoed'), pytest.param(None, 'doesnotexist', -1, 404, id='bad-entry_id'), ], ) def test_entry_rawdir( - client, example_data, test_auth_dict, user, entry_id, files_per_entry, status_code + client, example_data, auth_dict, user, entry_id, files_per_entry, status_code ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.get('entries/%s/rawdir' % entry_id, headers=user_auth) assert_response(response, status_code) if status_code == 200: @@ -790,9 +786,7 @@ def test_entry_rawdir( 'user, entry_id, files, files_per_entry, status_code', [ pytest.param(None, 'id_01', {}, 5, 200, id='id'), - pytest.param( - 'test_user', 'id_child_entries_child1', {}, 5, 200, id='child-entry' - ), + pytest.param('user1', 'id_child_entries_child1', {}, 5, 200, id='child-entry'), pytest.param(None, 'doesnotexist', {}, -1, 404, id='404'), pytest.param(None, 'id_01', {'glob_pattern': '*.json'}, 1, 200, id='glob'), pytest.param(None, 'id_01', {'re_pattern': '[a-z]*\\.aux'}, 4, 200, id='re'), @@ -807,14 +801,14 @@ def test_entry_rawdir( def test_entry_raw( client, example_data, - test_auth_dict, + auth_dict, user, entry_id, files, files_per_entry, status_code, ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.get( 'entries/%s/raw?%s' % (entry_id, urlencode(files, doseq=True)), headers=user_auth, @@ -834,11 +828,11 @@ def example_data_with_compressed_files( elastic_module, raw_files_module, mongo_module, - test_user, - other_test_user, + user1, + user2, normalized, ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id='with_compr_published', published=True) data.create_entry( @@ -891,7 +885,7 @@ def example_data_with_compressed_files( pytest.param( 'id_child_entries_child1', 'mainfile_w_children.json', - {'user': 'test_user'}, + {'user': 'user1'}, 200, id='child-entry', ), @@ -932,14 +926,14 @@ def example_data_with_compressed_files( pytest.param( 'with_compr_unpublished', 'mainfile.xz', - {'decompress': True, 'user': 'test_user'}, + {'decompress': True, 'user': 'user1'}, 200, id='decompress-xz-unpublished', ), pytest.param( 'with_compr_unpublished', 'mainfile.gz', - {'decompress': True, 'user': 'test_user'}, + {'decompress': True, 'user': 'user1'}, 200, id='decompress-gz-unpublished', ), @@ -950,28 +944,28 @@ def example_data_with_compressed_files( pytest.param( 'id_embargo_1', 'mainfile.json', - {'user': 'other_test_user'}, + {'user': 'user2'}, 404, id='404-embargo-no-access', ), pytest.param( 'id_embargo_1', 'mainfile.json', - {'user': 'test_user'}, + {'user': 'user1'}, 200, id='embargo-main_author', ), pytest.param( 'id_embargo_w_coauthor_1', 'mainfile.json', - {'user': 'other_test_user'}, + {'user': 'user2'}, 200, id='embargo-coauthor', ), pytest.param( 'id_embargo_w_reviewer_1', 'mainfile.json', - {'user': 'other_test_user'}, + {'user': 'user2'}, 200, id='embargo-reviewer', ), @@ -982,14 +976,14 @@ def test_entry_raw_file( example_data, example_data_with_compressed_files, example_mainfile_contents, - test_auth_dict, + auth_dict, entry_id, path, params, status_code, ): user = params.get('user') - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] if user: del params['user'] @@ -1014,7 +1008,7 @@ def test_entry_raw_file( [ pytest.param(None, None, {}, None, {}, 23, 200, id='all'), pytest.param( - 'test_user', + 'user1', 'visible', {'upload_id': 'id_child_entries'}, None, @@ -1034,7 +1028,7 @@ def test_entry_raw_file( def test_entries_archive_download( client, example_data, - test_auth_dict, + auth_dict, user, owner, query, @@ -1044,7 +1038,7 @@ def test_entries_archive_download( status_code, http_method, ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] perform_entries_archive_download_test( client, headers=user_auth, @@ -1080,15 +1074,13 @@ def test_entries_archive(client, example_data, required, status_code): 'user, entry_id, status_code', [ pytest.param(None, 'id_01', 200, id='id'), - pytest.param('test_user', 'id_child_entries_child1', 200, id='child-entry'), + pytest.param('user1', 'id_child_entries_child1', 200, id='child-entry'), pytest.param(None, 'id_02', 404, id='404-not-visible'), pytest.param(None, 'doesnotexist', 404, id='404-does-not-exist'), ], ) -def test_entry_archive( - client, example_data, test_auth_dict, user, entry_id, status_code -): - user_auth, _ = test_auth_dict[user] +def test_entry_archive(client, example_data, auth_dict, user, entry_id, status_code): + user_auth, _ = auth_dict[user] response = client.get('entries/%s/archive' % entry_id, headers=user_auth) assert_response(response, status_code) if status_code == 200: @@ -1100,20 +1092,16 @@ def test_entry_archive( [ pytest.param(None, 'id_01', False, 200, id='id'), pytest.param(None, 'id_01', True, 200, id='id'), - pytest.param( - 'test_user', 'id_child_entries_child1', False, 200, id='child-entry' - ), - pytest.param( - 'test_user', 'id_child_entries_child1', True, 200, id='child-entry' - ), + pytest.param('user1', 'id_child_entries_child1', False, 200, id='child-entry'), + pytest.param('user1', 'id_child_entries_child1', True, 200, id='child-entry'), pytest.param(None, 'id_02', True, 404, id='404-not-visible'), pytest.param(None, 'doesnotexist', False, 404, id='404-does-not-exist'), ], ) def test_entry_archive_download( - client, example_data, test_auth_dict, user, entry_id, ignore_mime_type, status_code + client, example_data, auth_dict, user, entry_id, ignore_mime_type, status_code ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.get( f'entries/{entry_id}/archive/download' + ('?ignore_mime_type=true' if ignore_mime_type else ''), @@ -1138,7 +1126,7 @@ def test_entry_archive_download( [ pytest.param(None, 'id_01', '*', 200, id='full'), pytest.param( - 'test_user', 'id_child_entries_child1', '*', 200, id='full-child-entry' + 'user1', 'id_child_entries_child1', '*', 200, id='full-child-entry' ), pytest.param(None, 'id_02', '*', 404, id='404'), pytest.param(None, 'id_01', {'metadata': '*'}, 200, id='partial'), @@ -1170,9 +1158,9 @@ def test_entry_archive_download( ], ) def test_entry_archive_query( - client, example_data, test_auth_dict, user, entry_id, required, status_code + client, example_data, auth_dict, user, entry_id, required, status_code ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.post( 'entries/%s/archive/query' % entry_id, json={'required': required}, @@ -1357,9 +1345,9 @@ def test_entries_get_query_dynamic( def test_entries_owner( client, example_data, - test_user_auth, - other_test_user_auth, - admin_user_auth, + user0_auth, + user1_auth, + user2_auth, owner, user, status_code, @@ -1376,9 +1364,9 @@ def test_entries_owner( ) perform_owner_test( client, - test_user_auth, - other_test_user_auth, - admin_user_auth, + user0_auth, + user1_auth, + user2_auth, owner, user, status_code, diff --git a/tests/app/v1/routers/test_entries_edit.py b/tests/app/v1/routers/test_entries_edit.py index f4909725241aab7a1d75ad4ab1090077d72415dd..c8a55729bc9e71c3f6b1485e5b9a84e2c78439c6 100644 --- a/tests/app/v1/routers/test_entries_edit.py +++ b/tests/app/v1/routers/test_entries_edit.py @@ -44,26 +44,26 @@ class TestEditRepo: self.api = client @pytest.fixture(autouse=True) - def example_datasets(self, test_user, other_test_user, mongo_function): + def example_datasets(self, user1, user2, mongo_function): self.example_dataset = Dataset( dataset_id='example_ds', dataset_name='example_ds', - user_id=test_user.user_id, + user_id=user1.user_id, ) self.example_dataset.a_mongo.create() self.other_example_dataset = Dataset( dataset_id='other_example_ds', dataset_name='other_example_ds', - user_id=other_test_user.user_id, + user_id=user2.user_id, ) self.other_example_dataset.a_mongo.create() @pytest.fixture(autouse=True) def example_data( self, - test_user, - other_test_user, + user1, + user2, raw_files_function, elastic_function, mongo_function, @@ -72,24 +72,24 @@ class TestEditRepo: example_data = ExampleData() example_data.create_upload( - 'upload_1', main_author=test_user, published=True, embargo_length=0 + 'upload_1', main_author=user1, published=True, embargo_length=0 ) example_data.create_entry(upload_id='upload_1') example_data.create_upload( - 'upload_2', main_author=test_user, published=True, embargo_length=36 + 'upload_2', main_author=user1, published=True, embargo_length=36 ) example_data.create_entry(upload_id='upload_2') example_data.create_entry(upload_id='upload_2') example_data.create_upload( - 'upload_3', main_author=other_test_user, published=True, embargo_length=0 + 'upload_3', main_author=user2, published=True, embargo_length=0 ) example_data.create_entry(upload_id='upload_3') example_data.save() @pytest.fixture(autouse=True) - def auth(self, test_user_auth): - self.test_user_auth = test_user_auth + def auth(self, user1_auth): + self.user_auth = user1_auth def perform_edit(self, query=None, verify=False, **kwargs): actions = {} @@ -105,7 +105,7 @@ class TestEditRepo: if verify: data.update(verify=verify) - return self.api.post('entries/edit_v0', headers=self.test_user_auth, json=data) + return self.api.post('entries/edit_v0', headers=self.user_auth, json=data) def assert_edit( self, rv, quantity: str, success: bool, message: bool, status_code: int = 200 @@ -161,10 +161,10 @@ class TestEditRepo: lambda id: search(owner=None, query=dict(entry_id=id)).data ) - def test_edit_all_properties(self, test_user, other_test_user): + def test_edit_all_properties(self, user1, user2): edit_data = dict( - # reviewers=[other_test_user.user_id], # TODO: need to set on upload level - # entry_coauthors=[other_test_user.user_id] # Not editable any more + # reviewers=[user2.user_id], # TODO: need to set on upload level + # entry_coauthors=[user2.user_id] # Not editable any more comment='test_edit_props', references=['http://test', 'http://test2'], ) @@ -183,13 +183,13 @@ class TestEditRepo: assert self.mongo(1, comment='test_edit_props') assert self.mongo(1, references=['http://test', 'http://test2']) - # assert self.mongo(1, entry_coauthors=[other_test_user.user_id]) - # assert self.mongo(1, reviewers=[other_test_user.user_id]) TODO: need to be set on upload level + # assert self.mongo(1, entry_coauthors=[user2.user_id]) + # assert self.mongo(1, reviewers=[user2.user_id]) TODO: need to be set on upload level self.assert_elastic(1, comment='test_edit_props') self.assert_elastic(1, references=['http://test', 'http://test2']) - self.assert_elastic(1, authors=[test_user.user_id]) - # self.assert_elastic(1, viewers=[test_user.user_id, other_test_user.user_id]) + self.assert_elastic(1, authors=[user1.user_id]) + # self.assert_elastic(1, viewers=[user1.user_id, user2.user_id]) edit_data = dict( comment='', @@ -215,8 +215,8 @@ class TestEditRepo: self.assert_elastic(1, comment=None) self.assert_elastic(1, references=[]) - self.assert_elastic(1, authors=[test_user.user_id]) - self.assert_elastic(1, viewers=[test_user.user_id]) + self.assert_elastic(1, authors=[user1.user_id]) + self.assert_elastic(1, viewers=[user1.user_id]) def test_edit_all(self): rv = self.perform_edit(comment='test_edit_all') @@ -253,22 +253,22 @@ class TestEditRepo: self.assert_edit(rv, quantity='comment', success=True, message=False) assert not self.mongo(1, comment='test_edit_verify', edited=False) - def test_edit_empty_list(self, other_test_user): + def test_edit_empty_list(self, user2): rv = self.perform_edit(references=['a'], query=self.query('upload_1')) self.assert_edit(rv, quantity='references', success=True, message=False) rv = self.perform_edit(references=[], query=self.query('upload_1')) self.assert_edit(rv, quantity='references', success=True, message=False) assert self.mongo(1, references=[]) - def test_edit_duplicate_value(self, other_test_user): + def test_edit_duplicate_value(self, user2): rv = self.perform_edit(references=['a', 'a'], query=self.query('upload_1')) self.assert_edit( rv, status_code=400, quantity='references', success=False, message=True ) - def test_edit_main_author_as_coauthor(self, test_user): + def test_edit_main_author_as_coauthor(self, user1): pass - # rv = self.perform_edit(entry_coauthors=[test_user.user_id], query=self.query('upload_1')) + # rv = self.perform_edit(entry_coauthors=[user1.user_id], query=self.query('upload_1')) # self.assert_edit(rv, status_code=400, quantity='entry_coauthors', success=False, message=True) def test_edit_ds(self): @@ -286,7 +286,7 @@ class TestEditRepo: assert rv.status_code == 200 rv = self.api.post( 'datasets/%s/action/doi' % self.example_dataset.dataset_name, - headers=self.test_user_auth, + headers=self.user_auth, ) assert rv.status_code == 200 rv = self.perform_edit(datasets=[], query=self.query('upload_1')) @@ -312,7 +312,7 @@ class TestEditRepo: is None ) - def test_edit_ds_user_namespace(self, test_user): + def test_edit_ds_user_namespace(self, user1): assert ( Dataset.m_def.a_mongo.objects( dataset_name=self.other_example_dataset.dataset_name @@ -328,17 +328,17 @@ class TestEditRepo: self.assert_edit(rv, quantity='datasets', success=True, message=True) new_dataset = Dataset.m_def.a_mongo.objects( dataset_name=self.other_example_dataset.dataset_name, - user_id=test_user.user_id, + user_id=user1.user_id, ).first() assert new_dataset is not None assert self.mongo(1, datasets=[new_dataset.dataset_id]) - def test_edit_new_ds(self, test_user): + def test_edit_new_ds(self, user1): rv = self.perform_edit(datasets=['new_dataset'], query=self.query('upload_1')) self.assert_edit(rv, quantity='datasets', success=True, message=True) new_dataset = Dataset.m_def.a_mongo.objects(dataset_name='new_dataset').first() assert new_dataset is not None - assert new_dataset.user_id == test_user.user_id + assert new_dataset.user_id == user1.user_id assert self.mongo(1, datasets=[new_dataset.dataset_id]) def test_edit_bad_user(self): @@ -346,16 +346,16 @@ class TestEditRepo: # rv = self.perform_edit(entry_coauthors=['bad_user'], query=self.query('upload_1')) # self.assert_edit(rv, status_code=400, quantity='entry_coauthors', success=False, message=True) - def test_edit_user(self, other_test_user): + def test_edit_user(self, user2): pass - # rv = self.perform_edit(entry_coauthors=[other_test_user.user_id], query=self.query('upload_1')) + # rv = self.perform_edit(entry_coauthors=[user2.user_id], query=self.query('upload_1')) # self.assert_edit(rv, quantity='entry_coauthors', success=True, message=False) @pytest.mark.skip( reason='Not necessary during transition. Fails because main_author is not editable anyways.' ) - def test_admin_only(self, other_test_user): - rv = self.perform_edit(main_author=other_test_user.user_id) + def test_admin_only(self, user2): + rv = self.perform_edit(main_author=user2.user_id) assert rv.status_code != 200 @@ -363,7 +363,7 @@ class TestEditRepo: 'user, kwargs', [ pytest.param( - 'test_user', + 'user1', dict( query={'upload_id': 'id_unpublished_w'}, metadata=all_coauthor_entry_metadata, @@ -372,7 +372,7 @@ class TestEditRepo: id='edit-all', ), pytest.param( - 'admin_user', + 'user0', dict( query={'upload_id': 'id_published_w'}, owner='all', @@ -382,7 +382,7 @@ class TestEditRepo: id='protected-admin', ), pytest.param( - 'test_user', + 'user1', dict( query={'upload_id': 'id_unpublished_w'}, metadata=all_admin_entry_metadata, @@ -391,7 +391,7 @@ class TestEditRepo: id='protected-not-admin', ), pytest.param( - 'admin_user', + 'user0', dict( query={'upload_id': 'id_published_w'}, owner='all', @@ -401,7 +401,7 @@ class TestEditRepo: id='published-admin', ), pytest.param( - 'test_user', + 'user1', dict( query={'upload_id': 'id_published_w'}, metadata=dict(comment='test comment'), @@ -430,7 +430,7 @@ class TestEditRepo: id='invalid-credentials', ), pytest.param( - 'other_test_user', + 'user2', dict( query={'upload_id': 'id_unpublished_w'}, metadata=dict(comment='test comment'), @@ -439,7 +439,7 @@ class TestEditRepo: id='no-access', ), pytest.param( - 'other_test_user', + 'user2', dict( query={'upload_id': 'id_unpublished_w'}, metadata=dict(comment='test comment'), @@ -449,7 +449,7 @@ class TestEditRepo: id='coauthor-access', ), pytest.param( - 'test_user', + 'user1', dict( query={ 'and': [ @@ -463,7 +463,7 @@ class TestEditRepo: id='compound-query-ok', ), pytest.param( - 'test_user', + 'user1', dict( query={'upload_id': 'id_unpublished_w'}, metadata=dict(upload_name='a test name'), @@ -472,7 +472,7 @@ class TestEditRepo: id='query-cannot-edit-upload-data', ), pytest.param( - 'test_user', + 'user1', dict( query={'upload_create_time:lt': '2021-01-01'}, metadata=dict(comment='a test comment'), @@ -487,8 +487,8 @@ def test_post_entries_edit( proc_infra, example_data_writeable, example_datasets, - test_auth_dict, - test_users_dict, + auth_dict, + users_dict, user, kwargs, ): @@ -497,8 +497,8 @@ def test_post_entries_edit( `MetadataEditRequestHandler.edit_metadata`, we only do very simple verification here, the more extensive testnig is done in `tests.processing.test_edit_metadata`. """ - user_auth, _token = test_auth_dict[user] - user = test_users_dict.get(user) + user_auth, _token = auth_dict[user] + user = users_dict.get(user) query = kwargs.get('query') owner = kwargs.get('owner', 'visible') metadata = kwargs.get('metadata') diff --git a/tests/app/v1/routers/test_graph.py b/tests/app/v1/routers/test_graph.py index 99f65bcca18d078a30b403a4f50afce8cf55e84a..41d6092f28ca3a00424de4b26d128c9581344520 100644 --- a/tests/app/v1/routers/test_graph.py +++ b/tests/app/v1/routers/test_graph.py @@ -42,8 +42,8 @@ def assert_path_exists(path, response): raise KeyError -def test_graph_query_random(client, test_auth_dict, example_data): - user_auth, _ = test_auth_dict['test_user'] +def test_graph_query_random(client, auth_dict, example_data): + user_auth, _ = auth_dict['user1'] response = client.post( 'graph/raw_query', json={ @@ -71,36 +71,30 @@ def test_graph_query_random(client, test_auth_dict, example_data): @pytest.mark.parametrize( 'upload_id,entry_id,user,status_code', [ - pytest.param('id_embargo', 'id_embargo_1', 'test_user', 200, id='ok'), + pytest.param('id_embargo', 'id_embargo_1', 'user1', 200, id='ok'), pytest.param( 'id_child_entries', 'id_child_entries_child1', - 'test_user', + 'user1', 200, id='child-entry', ), - pytest.param( - 'id_embargo', 'id_embargo_1', 'admin_user', 200, id='admin-access' - ), + pytest.param('id_embargo', 'id_embargo_1', 'user0', 200, id='admin-access'), pytest.param('id_embargo', 'id_embargo_1', None, 401, id='no-credentials'), pytest.param( 'id_embargo', 'id_embargo_1', 'invalid', 401, id='invalid-credentials' ), + pytest.param('id_embargo', 'id_embargo_1', 'user2', 404, id='no-access'), pytest.param( - 'id_embargo', 'id_embargo_1', 'other_test_user', 404, id='no-access' - ), - pytest.param( - 'silly_value', 'id_embargo_1', 'test_user', 404, id='invalid-upload_id' - ), - pytest.param( - 'id_embargo', 'silly_value', 'test_user', 404, id='invalid-entry_id' + 'silly_value', 'id_embargo_1', 'user1', 404, id='invalid-upload_id' ), + pytest.param('id_embargo', 'silly_value', 'user1', 404, id='invalid-entry_id'), ], ) def test_graph_query( - client, test_auth_dict, example_data, upload_id, entry_id, user, status_code + client, auth_dict, example_data, upload_id, entry_id, user, status_code ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.post( 'graph/query', json={Token.UPLOADS: {upload_id: {Token.ENTRIES: {entry_id: '*'}}}}, @@ -128,12 +122,10 @@ def test_graph_query( pytest.param({'DOESNOTEXIST': '*'}, 422, id='bad-required-3'), ], ) -def test_graph_archive_query( - client, example_data, required, status_code, test_user_auth -): +def test_graph_archive_query(client, example_data, required, status_code, user1_auth): response = client.post( 'graph/archive/query', - headers=test_user_auth, + headers=user1_auth, json={'owner': 'user', 'required': required}, ) @@ -219,8 +211,8 @@ def example_archive(): @pytest.fixture(scope='function') -def example_upload(example_archive, test_user, mongo_function, elastic_function): - data = ExampleData(main_author=test_user) +def example_upload(example_archive, user1, mongo_function, elastic_function): + data = ExampleData(main_author=user1) data.create_upload( upload_id='test_id', upload_name='name_published', published=True ) @@ -256,7 +248,7 @@ def example_upload(example_archive, test_user, mongo_function, elastic_function) ), pytest.param( dict( - user='other_test_user', + user='user2', expected_upload_ids=[ 'id_embargo_w_coauthor', 'id_embargo_w_reviewer', @@ -264,7 +256,7 @@ def example_upload(example_archive, test_user, mongo_function, elastic_function) 'id_unpublished_w_reviewer', ], ), - id='other_test_user', + id='user2', ), pytest.param(dict(user=None, expected_status_code=401), id='no-credentials'), pytest.param( @@ -390,13 +382,13 @@ def example_upload(example_archive, test_user, mongo_function, elastic_function) ], ) @pytest.mark.skipif(simulationworkflowschema is None, reason=SCHEMA_IMPORT_ERROR) -def test_get_uploads_graph(client, test_auth_dict, example_data, kwargs): - user = kwargs.get('user', 'test_user') +def test_get_uploads_graph(client, auth_dict, example_data, kwargs): + user = kwargs.get('user', 'user1') query_params = kwargs.get('query_params', None) pagination = kwargs.get('pagination', None) expected_status_code = kwargs.get('expected_status_code', 200) expected_upload_ids = kwargs.get('expected_upload_ids', None) - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] query_body = {Token.UPLOADS: {'m_request': {}}} @@ -523,8 +515,8 @@ def test_get_uploads_graph(client, test_auth_dict, example_data, kwargs): ), ], ) -def test_fs_graph(client, test_auth_dict, example_data, depth, result): - user_auth, _ = test_auth_dict['test_user'] +def test_fs_graph(client, auth_dict, example_data, depth, result): + user_auth, _ = auth_dict['user1'] response = client.post( 'graph/query', @@ -592,9 +584,9 @@ def test_fs_graph(client, test_auth_dict, example_data, depth, result): ) @pytest.mark.skipif(simulationworkflowschema is None, reason=SCHEMA_IMPORT_ERROR) def test_entry_reader_with_reference( - example_archive, required, error, test_user, example_upload + example_archive, required, error, user1, example_upload ): - with EntryReader({Token.ARCHIVE: required}, user=test_user) as reader: + with EntryReader({Token.ARCHIVE: required}, user=user1) as reader: results = reader.read('test_id') if error: @@ -674,9 +666,9 @@ def test_entry_reader_with_reference( ], ) def test_graph_query_archive_functionality( - client, test_auth_dict, example_upload, required, result + client, auth_dict, example_upload, required, result ): - user_auth, _ = test_auth_dict['test_user'] + user_auth, _ = auth_dict['user1'] response = client.post( 'graph/query', json={'uploads': {'test_id': {'entries': {'test_id': {'archive': required}}}}}, diff --git a/tests/app/v1/routers/test_groups.py b/tests/app/v1/routers/test_groups.py index d44a99e3526cdc9cf02e647cda2e3fb879fa4dd1..cbaa8eb5bd696e4d0ed0e7319d2cde699ff5fa3e 100644 --- a/tests/app/v1/routers/test_groups.py +++ b/tests/app/v1/routers/test_groups.py @@ -36,8 +36,8 @@ def assert_group(group, ref_group, keys=None): @pytest.mark.parametrize( 'user_label, expected_status_code', [ - pytest.param('test_user', 200, id='test-user'), - pytest.param('other_test_user', 200, id='other-test-user'), + pytest.param('user1', 200, id='user1'), + pytest.param('user2', 200, id='user2'), pytest.param('invalid', 200, id='invalid-user'), pytest.param(None, 200, id='guest-user'), ], @@ -45,12 +45,12 @@ def assert_group(group, ref_group, keys=None): def test_get_groups( client, mongo_module, - test_auth_dict, + auth_dict, user_groups_module, user_label, expected_status_code, ): - user_auth, _ = test_auth_dict[user_label] + user_auth, _ = auth_dict[user_label] response = perform_get(client, base_url, user_auth) assert_response(response, expected_status_code) @@ -64,21 +64,21 @@ def test_get_groups( @pytest.mark.parametrize( 'user_label, expected_status_code', [ - pytest.param('test_user', 200, id='test-user'), - pytest.param('other_test_user', 200, id='other-test-user'), + pytest.param('user1', 200, id='user1'), + pytest.param('user2', 200, id='user2'), pytest.param('invalid', 200, id='invalid-user'), pytest.param(None, 200, id='guest-user'), ], ) def test_get_group( client, - test_auth_dict, + auth_dict, user_groups_module, user_label, expected_status_code, ): - user_auth, _ = test_auth_dict[user_label] - ref_group = user_groups_module['other_owner_group'] + user_auth, _ = auth_dict[user_label] + ref_group = user_groups_module['group2'] response = perform_get(client, f'{base_url}/{ref_group.group_id}', user_auth) assert_response(response, expected_status_code) @@ -92,8 +92,8 @@ def test_get_group( @pytest.mark.parametrize( 'user_label, expected_status_code', [ - pytest.param('test_user', 404, id='test-user'), - pytest.param('other_test_user', 404, id='other-test-user'), + pytest.param('user1', 404, id='user1'), + pytest.param('user2', 404, id='user2'), pytest.param('invalid', 404, id='invalid-user'), pytest.param(None, 404, id='guest-user'), ], @@ -101,12 +101,12 @@ def test_get_group( def test_get_group_invalid( client, mongo_module, - test_auth_dict, + auth_dict, user_groups_module, user_label, expected_status_code, ): - user_auth, _ = test_auth_dict[user_label] + user_auth, _ = auth_dict[user_label] response = perform_get(client, f'{base_url}/invalid-group-id', user_auth) assert_response(response, expected_status_code) @@ -115,16 +115,14 @@ def test_get_group_invalid( @pytest.mark.parametrize( 'user_label, new_group_label, ref_group_label, expected_status_code', [ - pytest.param('test_user', 'new_group', 'new_group', 201, id='test-user'), - pytest.param( - 'other_test_user', 'new_group', 'new_group', 201, id='other-test-user' - ), + pytest.param('user1', 'new_group', 'new_group', 201, id='user1'), + pytest.param('user2', 'new_group', 'new_group', 201, id='user2'), pytest.param('invalid', 'new_group', None, 401, id='invalid-user'), pytest.param(None, 'new_group', None, 401, id='guest-user'), - pytest.param('test_user', 'short_name', None, 422, id='short-name-fails'), - pytest.param('test_user', 'long_name', None, 422, id='long-name-fails'), + pytest.param('user1', 'short_name', None, 422, id='short-name-fails'), + pytest.param('user1', 'long_name', None, 422, id='long-name-fails'), pytest.param( - 'test_user', + 'user1', 'double_member', 'double_member_ref', 201, @@ -136,15 +134,15 @@ def test_create_group( client, mongo_function, request, - test_auth_dict, - test_user_group_molds, + auth_dict, + group_molds, user_label, new_group_label, ref_group_label, expected_status_code, ): - user_auth, _ = test_auth_dict[user_label] - new_group = test_user_group_molds[new_group_label] + user_auth, _ = auth_dict[user_label] + new_group = group_molds[new_group_label] response = perform_post(client, base_url, user_auth, json=new_group) assert_response(response, expected_status_code) @@ -155,7 +153,7 @@ def test_create_group( response_group = UserGroup.parse_raw(response.content) group = get_user_group(response_group.group_id) assert_group(group, response_group) - ref_group = test_user_group_molds[ref_group_label] + ref_group = group_molds[ref_group_label] assert_group(group, ref_group, ref_group.keys()) @@ -164,13 +162,13 @@ def test_create_group( [ pytest.param(None, 'new_group', None, 401, id='guest-fails'), pytest.param('invalid', 'new_group', None, 401, id='faker-fails'), - pytest.param('other_test_user', 'new_group', None, 401, id='other-fails'), - pytest.param('test_user', 'new_group', 'new_group', 200, id='edit-ok'), - pytest.param('test_user', 'short_name', None, 422, id='short-name-fails'), - pytest.param('test_user', 'long_name', None, 422, id='long-name-fails'), - pytest.param('test_user', 'special_char', None, 422, id='special-chars-fails'), + pytest.param('user2', 'new_group', None, 401, id='other-fails'), + pytest.param('user1', 'new_group', 'new_group', 200, id='edit-ok'), + pytest.param('user1', 'short_name', None, 422, id='short-name-fails'), + pytest.param('user1', 'long_name', None, 422, id='long-name-fails'), + pytest.param('user1', 'special_char', None, 422, id='special-chars-fails'), pytest.param( - 'test_user', + 'user1', 'double_member', 'double_member_ref', 200, @@ -181,18 +179,18 @@ def test_create_group( def test_update_user_group( client, mongo_function, - test_auth_dict, - test_user_group_molds, + auth_dict, + group_molds, user_groups_function, - user_owner_group, + group1, user_label, group_edit_label, ref_group_label, expected_status_code, ): - user_auth, _ = test_auth_dict[user_label] - group_before = get_user_group(user_owner_group.group_id) - group_edit = test_user_group_molds[group_edit_label] + user_auth, _ = auth_dict[user_label] + group_before = get_user_group(group1.group_id) + group_edit = group_molds[group_edit_label] url = f'{base_url}/{group_before.group_id}/edit' response = perform_post(client, url, user_auth, json=group_edit) @@ -205,62 +203,60 @@ def test_update_user_group( response_group = UserGroup.parse_raw(response.content) assert_group(group_after, response_group) - ref_group = test_user_group_molds[ref_group_label] + ref_group = group_molds[ref_group_label] assert_group(group_after, ref_group, ref_group.keys()) @pytest.mark.parametrize( 'user_label, expected_status_code', [ - pytest.param('test_user', 204, id='test-user'), - pytest.param('other_test_user', 401, id='other-test-user'), + pytest.param('user1', 204, id='user1'), + pytest.param('user2', 401, id='user2'), pytest.param('invalid', 401, id='invalid-user'), pytest.param(None, 401, id='guest-user'), ], ) def test_delete_group( + auth_dict, client, - other_owner_group, - test_auth_dict, + group1, + group2, user_groups_function, - user_owner_group, user_label, expected_status_code, ): - user_auth, _ = test_auth_dict[user_label] + user_auth, _ = auth_dict[user_label] - response = client.delete( - f'{base_url}/{user_owner_group.group_id}', headers=user_auth - ) + response = client.delete(f'{base_url}/{group1.group_id}', headers=user_auth) assert_response(response, expected_status_code) if response.status_code != 204: - assert user_group_exists(user_owner_group.group_id) + assert user_group_exists(group1.group_id) return - assert not user_group_exists(user_owner_group.group_id) - assert user_group_exists(other_owner_group.group_id) + assert not user_group_exists(group1.group_id) + assert user_group_exists(group2.group_id) @pytest.mark.parametrize( 'user_label, expected_status_code', [ - pytest.param('test_user', 404, id='test-user'), - pytest.param('other_test_user', 404, id='other-test-user'), + pytest.param('user1', 404, id='user1'), + pytest.param('user2', 404, id='user2'), pytest.param('invalid', 401, id='invalid-user'), pytest.param(None, 401, id='guest-user'), ], ) def test_delete_group_invalid( client, - test_auth_dict, + auth_dict, user_groups_function, - user_owner_group, + group1, user_label, expected_status_code, ): - user_auth, _ = test_auth_dict[user_label] + user_auth, _ = auth_dict[user_label] response = client.delete(f'{base_url}/invalid-group-id', headers=user_auth) assert_response(response, expected_status_code) - assert user_group_exists(user_owner_group.group_id) + assert user_group_exists(group1.group_id) diff --git a/tests/app/v1/routers/test_materials.py b/tests/app/v1/routers/test_materials.py index f10cfd6fecd887f76e677d2f6f98de676be2f8f2..84882bdbfc1a5ed5d08862f0bfa403a004345c4f 100644 --- a/tests/app/v1/routers/test_materials.py +++ b/tests/app/v1/routers/test_materials.py @@ -66,11 +66,11 @@ n_code_names = results.Simulation.program_name.a_elasticsearch[ aggregation_test_parameters_default('materials'), ) def test_materials_aggregations( - client, example_data, test_user_auth, aggregation, total, size, status_code, user + client, example_data, user1_auth, aggregation, total, size, status_code, user ): assert_aggregation_response( client, - test_user_auth, + user1_auth, aggregation, total, size, @@ -328,9 +328,9 @@ def test_materials_get_query(client, example_data, query, status_code, total): def test_materials_owner( client, example_data, - test_user_auth, - other_test_user_auth, - admin_user_auth, + user0_auth, + user1_auth, + user2_auth, owner, user, status_code, @@ -342,9 +342,9 @@ def test_materials_owner( ): perform_owner_test( client, - test_user_auth, - other_test_user_auth, - admin_user_auth, + user0_auth, + user1_auth, + user2_auth, owner, user, status_code, diff --git a/tests/app/v1/routers/test_metainfo.py b/tests/app/v1/routers/test_metainfo.py index a8208b976cc4b4d27bf8d2f6e43ffbbaade5a24a..b2a65ab51175cdc09e5498c113ef1567e0edd254 100644 --- a/tests/app/v1/routers/test_metainfo.py +++ b/tests/app/v1/routers/test_metainfo.py @@ -67,7 +67,7 @@ def test_metainfo_section_id_endpoint(metainfo_data, mongo_module, client): def test_upload_and_download( - client, test_user, proc_infra, mongo_module, no_warn, monkeypatch, tmp + client, user1, proc_infra, mongo_module, no_warn, monkeypatch, tmp ): monkeypatch.setattr('nomad.config.process.store_package_definition_in_mongo', True) monkeypatch.setattr('nomad.config.process.add_definition_id_to_reference', True) @@ -141,7 +141,7 @@ def test_upload_and_download( zipObj.write(data_path, arcname=data_file_name) processed = run_processing( - (create_uuid(), archive_path), test_user, publish_directly=True + (create_uuid(), archive_path), user1, publish_directly=True ) return processed.upload_id @@ -280,7 +280,7 @@ def example_upload_two_schemas(): def test_two_schemas( - example_upload_two_schemas, client, test_user, proc_infra, no_warn, monkeypatch + example_upload_two_schemas, client, user1, proc_infra, no_warn, monkeypatch ): monkeypatch.setattr('nomad.config.process.store_package_definition_in_mongo', True) monkeypatch.setattr('nomad.config.process.add_definition_id_to_reference', True) @@ -303,7 +303,7 @@ def test_two_schemas( processed = run_processing( (archive_name.replace('.zip', ''), tmp(archive_name)), - test_user, + user1, publish_directly=True, ) diff --git a/tests/app/v1/routers/test_suggestions.py b/tests/app/v1/routers/test_suggestions.py index ff96e3a951f44e28550439c2d34e414cd5465615..937aad115af73b98413d9863cb7a857940bd35f2 100644 --- a/tests/app/v1/routers/test_suggestions.py +++ b/tests/app/v1/routers/test_suggestions.py @@ -37,11 +37,11 @@ def example_data_suggestions( elastic_module, raw_files_module, mongo_module, - test_user, - other_test_user, + user1, + user2, normalized, ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) upload_id = 'suggestions_upload' data.create_upload(upload_id=upload_id, published=True) diff --git a/tests/app/v1/routers/test_systems.py b/tests/app/v1/routers/test_systems.py index ff72a70040bf9cd8fa4351abb043a6387fc74c01..e9cfbc31b09f8109b3ef87645f71ffdd0617b7d7 100644 --- a/tests/app/v1/routers/test_systems.py +++ b/tests/app/v1/routers/test_systems.py @@ -126,8 +126,8 @@ atoms_wrap_mode_no_pbc.periodic = [False, False, False] @pytest.fixture(scope='module') -def example_data_systems(elastic_module, mongo_module, test_user): - data = ExampleData(main_author=test_user) +def example_data_systems(elastic_module, mongo_module, user1): + data = ExampleData(main_author=user1) upload_id = 'systems_upload' data.create_upload(upload_id=upload_id, published=True) diff --git a/tests/app/v1/routers/test_users.py b/tests/app/v1/routers/test_users.py index 2267c6b83a59b9051b55bcd1d1253ceb68ee515d..8cb91a7fba84bc2f3bc2057f34dbea6904aab4d3 100644 --- a/tests/app/v1/routers/test_users.py +++ b/tests/app/v1/routers/test_users.py @@ -17,8 +17,8 @@ # import pytest -from tests.fixtures.users import test_users as conf_test_users -from tests.utils import test_user_uuid as conf_test_user_uuid +from tests.fixtures.users import users +from tests.utils import fake_user_uuid def assert_user(user, expected_user): @@ -27,8 +27,8 @@ def assert_user(user, expected_user): assert 'email' not in user -def test_me(client, test_user_auth, app_token_auth): - response = client.get('users/me', headers=test_user_auth) +def test_me(client, user1_auth, app_token_auth): + response = client.get('users/me', headers=user1_auth) assert response.status_code == 200 response = client.get('users/me', headers=app_token_auth) assert response.status_code == 200 @@ -44,10 +44,10 @@ def test_me_auth_bad_token(client): assert response.status_code == 401 -def test_invite(client, test_user_auth, no_warn): +def test_invite(client, user1_auth, no_warn): rv = client.put( 'users/invite', - headers=test_user_auth, + headers=user1_auth, json={ 'first_name': 'John', 'last_name': 'Doe', @@ -68,28 +68,28 @@ def test_invite(client, test_user_auth, no_warn): pytest.param( dict(prefix='Sheldon'), 200, - conf_test_users[conf_test_user_uuid(1)], + users[fake_user_uuid(1)], id='search-user', ), pytest.param( - dict(user_id=conf_test_user_uuid(1)), + dict(user_id=fake_user_uuid(1)), 200, - conf_test_users[conf_test_user_uuid(1)], + users[fake_user_uuid(1)], id='one-user-id', ), pytest.param( - dict(user_id=[conf_test_user_uuid(1), conf_test_user_uuid(2)]), + dict(user_id=[fake_user_uuid(1), fake_user_uuid(2)]), 200, [ - conf_test_users[conf_test_user_uuid(1)], - conf_test_users[conf_test_user_uuid(2)], + users[fake_user_uuid(1)], + users[fake_user_uuid(2)], ], id='multi-user-id', ), pytest.param( - dict(user_id=[conf_test_user_uuid(1), conf_test_user_uuid(9)]), + dict(user_id=[fake_user_uuid(1), fake_user_uuid(9)]), 200, - [conf_test_users[conf_test_user_uuid(1)]], + [users[fake_user_uuid(1)]], id='wrong-user-id', ), ], @@ -132,9 +132,9 @@ def test_users(client, args, expected_status_code, expected_content): 'args, expected_status_code, expected_content', [ pytest.param( - dict(user_id=conf_test_user_uuid(1)), + dict(user_id=fake_user_uuid(1)), 200, - conf_test_users[conf_test_user_uuid(1)], + users[fake_user_uuid(1)], id='valid-user', ) ], diff --git a/tests/app/v1/routers/uploads/test_basic_uploads.py b/tests/app/v1/routers/uploads/test_basic_uploads.py index c2687f05fb2bae0b97a6d0ce34b26db203744f36..4c60d95db251a88fcb907062211909490e2eb830 100644 --- a/tests/app/v1/routers/uploads/test_basic_uploads.py +++ b/tests/app/v1/routers/uploads/test_basic_uploads.py @@ -147,7 +147,7 @@ def assert_file_upload_and_processing( url, mode, user, - test_auth_dict, + auth_dict, upload_id, source_paths, target_path, @@ -167,7 +167,7 @@ def assert_file_upload_and_processing( source_paths = source_paths or [] if isinstance(source_paths, str): source_paths = [source_paths] - user_auth, token = test_auth_dict[user] + user_auth, token = auth_dict[user] # Use either token or bearer token for the post operation (never both) user_auth_action = user_auth if use_upload_token: @@ -457,7 +457,7 @@ def get_upload_entries_metadata( ), pytest.param( dict( - user='other_test_user', + user='user2', expected_upload_ids=[ 'id_embargo_w_coauthor', 'id_embargo_w_reviewer', @@ -465,7 +465,7 @@ def get_upload_entries_metadata( 'id_unpublished_w_reviewer', ], ), - id='other_test_user', + id='user2', ), pytest.param(dict(user=None, expected_status_code=401), id='no-credentials'), pytest.param( @@ -627,7 +627,7 @@ def get_upload_entries_metadata( ), pytest.param( dict( - user='other_test_user', + user='user2', query_params={'roles': 'coauthor'}, expected_pagination={'total': 2}, ), @@ -635,7 +635,7 @@ def get_upload_entries_metadata( ), pytest.param( dict( - user='other_test_user', + user='user2', query_params={'roles': 'reviewer'}, expected_pagination={'total': 2}, ), @@ -643,7 +643,7 @@ def get_upload_entries_metadata( ), pytest.param( dict( - user='test_user', + user='user1', query_params={'roles': 'main_author'}, expected_pagination={'total': 10}, ), @@ -651,7 +651,7 @@ def get_upload_entries_metadata( ), pytest.param( dict( - user='other_test_user', + user='user2', query_params={'roles': ['reviewer', 'coauthor']}, expected_pagination={'total': 4}, ), @@ -659,15 +659,15 @@ def get_upload_entries_metadata( ), ], ) -def test_get_uploads(client, mongo_module, test_auth_dict, example_data, kwargs): +def test_get_uploads(client, mongo_module, auth_dict, example_data, kwargs): """Makes a get request to uploads in various different ways.""" # Extract kwargs - user = kwargs.get('user', 'test_user') + user = kwargs.get('user', 'user1') query_params = kwargs.get('query_params', {}) expected_status_code = kwargs.get('expected_status_code', 200) expected_upload_ids = kwargs.get('expected_upload_ids', None) expected_pagination = kwargs.get('expected_pagination', {}) - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] # Api call response = perform_get(client, 'uploads', user_auth=user_auth, **query_params) # Verify result @@ -691,27 +691,27 @@ def test_get_uploads(client, mongo_module, test_auth_dict, example_data, kwargs) @pytest.mark.parametrize( 'user, upload_id, expected_status_code', [ - pytest.param('test_user', 'id_unpublished', 200, id='valid-upload_id'), + pytest.param('user1', 'id_unpublished', 200, id='valid-upload_id'), pytest.param( - 'test_user', 'id_child_entries', 200, id='valid-upload_id-w-child-entries' + 'user1', 'id_child_entries', 200, id='valid-upload_id-w-child-entries' ), - pytest.param('test_user', 'silly_value', 404, id='invalid-upload_id'), + pytest.param('user1', 'silly_value', 404, id='invalid-upload_id'), pytest.param(None, 'id_unpublished', 401, id='no-credentials'), pytest.param('invalid', 'id_unpublished', 401, id='invalid-credentials'), - pytest.param('other_test_user', 'id_unpublished', 401, id='no-access'), - pytest.param('admin_user', 'id_unpublished', 200, id='admin-access'), + pytest.param('user2', 'id_unpublished', 401, id='no-access'), + pytest.param('user0', 'id_unpublished', 200, id='admin-access'), ], ) def test_get_upload( client, mongo_module, - test_auth_dict, + auth_dict, user, upload_id, expected_status_code, ): """Tests the endpoint for getting an upload by upload_id.""" - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_get(client, f'uploads/{upload_id}', user_auth) assert_response(response, expected_status_code) if expected_status_code == 200: @@ -760,10 +760,8 @@ def test_get_upload( pytest.param( dict(user='invalid', expected_status_code=401), id='invalid-credentials' ), - pytest.param( - dict(user='other_test_user', expected_status_code=401), id='no-access' - ), - pytest.param(dict(user='admin_user', expected_data_len=1), id='admin-access'), + pytest.param(dict(user='user2', expected_status_code=401), id='no-access'), + pytest.param(dict(user='user0', expected_data_len=1), id='admin-access'), pytest.param( dict(upload_id='silly_value', expected_status_code=404), id='invalid-upload_id', @@ -915,19 +913,19 @@ def test_get_upload( ), ], ) -def test_get_upload_entries(client, mongo_module, test_auth_dict, example_data, kwargs): +def test_get_upload_entries(client, mongo_module, auth_dict, example_data, kwargs): """ Fetches the entries for a specific upload, by calling uploads/{upload_id}/entries, with the provided query paramters, and checks the result. """ upload_id = kwargs.get('upload_id', 'id_embargo') - user = kwargs.get('user', 'test_user') + user = kwargs.get('user', 'user1') query_args = kwargs.get('query_args', {}) expected_status_code = kwargs.get('expected_status_code', 200) expected_data_len = kwargs.get('expected_data_len', 1) expected_response = kwargs.get('expected_response', {}) expected_pagination = kwargs.get('expected_pagination', {}) - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_get( client, f'uploads/{upload_id}/entries', user_auth, **query_args @@ -953,11 +951,11 @@ def test_get_upload_entries(client, mongo_module, test_auth_dict, example_data, @pytest.mark.parametrize( 'upload_id, entry_id, user, expected_status_code', [ - pytest.param('id_embargo', 'id_embargo_1', 'test_user', 200, id='ok'), + pytest.param('id_embargo', 'id_embargo_1', 'user1', 200, id='ok'), pytest.param( 'id_child_entries', 'id_child_entries_child1', - 'test_user', + 'user1', 200, id='child-entry', ), @@ -965,24 +963,18 @@ def test_get_upload_entries(client, mongo_module, test_auth_dict, example_data, pytest.param( 'id_embargo', 'id_embargo_1', 'invalid', 401, id='invalid-credentials' ), + pytest.param('id_embargo', 'id_embargo_1', 'user2', 401, id='no-access'), + pytest.param('id_embargo', 'id_embargo_1', 'user0', 200, id='admin-access'), pytest.param( - 'id_embargo', 'id_embargo_1', 'other_test_user', 401, id='no-access' - ), - pytest.param( - 'id_embargo', 'id_embargo_1', 'admin_user', 200, id='admin-access' - ), - pytest.param( - 'silly_value', 'id_embargo_1', 'test_user', 404, id='invalid-upload_id' - ), - pytest.param( - 'id_embargo', 'silly_value', 'test_user', 404, id='invalid-entry_id' + 'silly_value', 'id_embargo_1', 'user1', 404, id='invalid-upload_id' ), + pytest.param('id_embargo', 'silly_value', 'user1', 404, id='invalid-entry_id'), ], ) def test_get_upload_entry( client, mongo_module, - test_auth_dict, + auth_dict, example_data, upload_id, entry_id, @@ -992,7 +984,7 @@ def test_get_upload_entry( """ Fetches an entry via a call to uploads/{upload_id}/entries/{entry_id} and checks it. """ - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_get(client, f'uploads/{upload_id}/entries/{entry_id}', user_auth) assert_response(response, expected_status_code) if expected_status_code == 200: @@ -1007,7 +999,7 @@ def test_get_upload_entry( [ pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', ), 200, @@ -1015,19 +1007,19 @@ def test_get_upload_entry( id='published-file', ), pytest.param( - dict(user='test_user', upload_id='id_unpublished'), + dict(user='user1', upload_id='id_unpublished'), 400, None, id='unpublished-file', ), pytest.param( - dict(user='other_test_user', upload_id='id_embargo'), + dict(user='user2', upload_id='id_embargo'), 401, None, id='embargo-file', ), pytest.param( - dict(user='test_user', upload_id='silly_value'), + dict(user='user1', upload_id='silly_value'), 404, None, id='bad-upload-id', @@ -1037,14 +1029,14 @@ def test_get_upload_entry( def test_get_upload_raw( client, example_data, - test_auth_dict, + auth_dict, args, expected_status_code, expected_content, ): user = args['user'] upload_id = args['upload_id'] - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_get(client, f'uploads/{upload_id}/raw', user_auth=user_auth) @@ -1064,7 +1056,7 @@ def test_get_upload_raw( [ pytest.param( dict( - user='test_user', + user='user1', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', ), @@ -1075,7 +1067,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', ignore_mime_type=True, @@ -1087,7 +1079,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='other_test_user', + user='user2', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', ), @@ -1098,7 +1090,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='admin_user', + user='user0', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', ), @@ -1109,7 +1101,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01/mainfile.json', ), @@ -1120,7 +1112,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01/mainfile.json', ignore_mime_type=True, @@ -1132,7 +1124,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='admin_user', + user='user0', upload_id='id_published', path='test_content/subdir/test_entry_01/1.aux', ), @@ -1143,7 +1135,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', compress=True, @@ -1155,7 +1147,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_unpublished', path='test_content/id_unpublished_1/', compress=True, @@ -1166,7 +1158,7 @@ def test_get_upload_raw( id='unpublished-dir-compressed', ), pytest.param( - dict(user='test_user', upload_id='id_unpublished', path='', compress=True), + dict(user='user1', upload_id='id_unpublished', path='', compress=True), 200, 'application/zip', [ @@ -1178,7 +1170,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01/1.aux', compress=True, @@ -1190,7 +1182,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01', compress=True, @@ -1201,7 +1193,7 @@ def test_get_upload_raw( id='published-dir-compressed', ), pytest.param( - dict(user='test_user', upload_id='id_published', path='', compress=True), + dict(user='user1', upload_id='id_published', path='', compress=True), 200, 'application/zip', ['test_content', 'test_content/subdir/test_entry_01/1.aux'], @@ -1209,7 +1201,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='silly_value', path='test_content/subdir/test_entry_01/1.aux', compress=True, @@ -1221,7 +1213,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/silly_name', compress=True, @@ -1233,7 +1225,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', offset=2, @@ -1245,7 +1237,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', offset=2, @@ -1258,7 +1250,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01/1.aux', offset=2, @@ -1270,7 +1262,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01/1.aux', offset=2, @@ -1283,7 +1275,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01/1.aux', offset=-3, @@ -1295,7 +1287,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='test_user', + user='user1', upload_id='id_published', path='test_content/subdir/test_entry_01/1.aux', offset=3, @@ -1330,7 +1322,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='other_test_user', + user='user2', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', ), @@ -1341,7 +1333,7 @@ def test_get_upload_raw( ), pytest.param( dict( - user='admin_user', + user='user0', upload_id='id_unpublished', path='test_content/id_unpublished_1/1.aux', ), @@ -1355,7 +1347,7 @@ def test_get_upload_raw( def test_get_upload_raw_path( client, example_data, - test_auth_dict, + auth_dict, args, expected_status_code, expected_mime_type, @@ -1370,7 +1362,7 @@ def test_get_upload_raw_path( offset = args.get('offset', None) length = args.get('length', None) ignore_mime_type = args.get('ignore_mime_type', None) - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] query_args = dict( ignore_mime_type=ignore_mime_type, compress=compress, @@ -1443,7 +1435,7 @@ def test_get_upload_raw_path( 'user, upload_id, path, query_args, expected_status_code, expected_content, expected_file_metadata, expected_pagination', [ pytest.param( - 'test_user', + 'user1', 'id_published', 'test_content/subdir/silly_value', {}, @@ -1454,7 +1446,7 @@ def test_get_upload_raw_path( id='bad-path', ), pytest.param( - 'test_user', + 'user1', 'id_published', 'test_content/subdir/test_entry_01', {}, @@ -1465,7 +1457,7 @@ def test_get_upload_raw_path( id='published-dir', ), pytest.param( - 'test_user', + 'user1', 'id_published', 'test_content/subdir/test_entry_01', {'include_entry_info': True}, @@ -1476,7 +1468,7 @@ def test_get_upload_raw_path( id='published-dir-include_entry_info', ), pytest.param( - 'test_user', + 'user1', 'id_published', 'test_content/subdir/test_entry_01', {'include_entry_info': True, 'page_size': 2, 'page': 3}, @@ -1487,7 +1479,7 @@ def test_get_upload_raw_path( id='published-dir-include_entry_info-page3', ), pytest.param( - 'test_user', + 'user1', 'id_published', '', {}, @@ -1498,7 +1490,7 @@ def test_get_upload_raw_path( id='published-dir-root', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished', 'test_content/id_unpublished_1/', {}, @@ -1509,7 +1501,7 @@ def test_get_upload_raw_path( id='unpublished-dir', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished', 'test_content/id_unpublished_1/', {'page_size': 3, 'page': 1}, @@ -1520,7 +1512,7 @@ def test_get_upload_raw_path( id='unpublished-dir-page1', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished', 'test_content/id_unpublished_1/', {'page_size': 2, 'page': 4}, @@ -1531,7 +1523,7 @@ def test_get_upload_raw_path( id='unpublished-dir-page-out-of-range', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished', 'test_content/id_unpublished_1/', {'include_entry_info': True}, @@ -1542,7 +1534,7 @@ def test_get_upload_raw_path( id='unpublished-dir-include_entry_info', ), pytest.param( - 'test_user', + 'user1', 'id_child_entries', 'test_content', {'include_entry_info': True}, @@ -1553,7 +1545,7 @@ def test_get_upload_raw_path( id='dir-child-entries-include_entry_info', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished', '', {}, @@ -1564,7 +1556,7 @@ def test_get_upload_raw_path( id='unpublished-dir-root', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished', 'test_content/id_unpublished_1/2.aux', {'include_entry_info': True}, @@ -1575,7 +1567,7 @@ def test_get_upload_raw_path( id='unpublished-aux-file', ), pytest.param( - 'test_user', + 'user1', 'id_published', 'test_content/subdir/test_entry_01/mainfile.json', {'include_entry_info': True}, @@ -1591,7 +1583,7 @@ def test_get_upload_raw_path( id='published-main-file', ), pytest.param( - 'other_test_user', + 'user2', 'id_unpublished', 'test_content/id_unpublished_1', {}, @@ -1602,7 +1594,7 @@ def test_get_upload_raw_path( id='unpublished-no-access', ), pytest.param( - 'other_test_user', + 'user2', 'id_embargo', 'test_content/id_embargo_1', {}, @@ -1613,7 +1605,7 @@ def test_get_upload_raw_path( id='embargoed-no-access', ), pytest.param( - 'other_test_user', + 'user2', 'id_embargo_w_coauthor', 'test_content/id_embargo_w_coauthor_1', {}, @@ -1628,7 +1620,7 @@ def test_get_upload_raw_path( def test_get_upload_rawdir_path( client, example_data, - test_auth_dict, + auth_dict, user, upload_id, path, @@ -1638,7 +1630,7 @@ def test_get_upload_rawdir_path( expected_file_metadata, expected_pagination, ): - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_get( client, f'uploads/{upload_id}/rawdir/{path}', user_auth=user_auth, **query_args @@ -1713,14 +1705,14 @@ def test_get_upload_rawdir_path( pytest.param( 'id_unpublished', 'test_content/id_unpublished_1/mainfile.json', - 'test_user', + 'user1', 200, id='auth', ), pytest.param( 'id_child_entries', 'test_content/mainfile_w_children.json', - 'test_user', + 'user1', 200, id='entry-w-child-entries', ), @@ -1729,13 +1721,13 @@ def test_get_upload_rawdir_path( def test_get_upload_entry_archive_mainfile( client, example_data, - test_auth_dict, + auth_dict, upload_id: str, mainfile: str, user: str, status_code: int, ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.get( f'uploads/{upload_id}/archive/mainfile/{mainfile}', headers=user_auth ) @@ -1751,11 +1743,11 @@ def test_get_upload_entry_archive_mainfile( pytest.param('id_published', 'doesnotexist', None, 404, id='bad-entry-id'), pytest.param('id_doesnotexist', 'id_01', None, 404, id='bad-upload-id'), pytest.param('id_unpublished', 'id_unpublished_1', None, 401, id='unpublished'), - pytest.param('id_unpublished', 'id_unpublished_1', 'test_user', 200, id='auth'), + pytest.param('id_unpublished', 'id_unpublished_1', 'user1', 200, id='auth'), pytest.param( 'id_child_entries', 'id_child_entries_child1', - 'test_user', + 'user1', 200, id='child-entry', ), @@ -1764,13 +1756,13 @@ def test_get_upload_entry_archive_mainfile( def test_get_upload_entry_archive( client, example_data, - test_auth_dict, + auth_dict, upload_id: str, entry_id: str, user: str, status_code: int, ): - user_auth, _ = test_auth_dict[user] + user_auth, _ = auth_dict[user] response = client.get(f'uploads/{upload_id}/archive/{entry_id}', headers=user_auth) assert_response(response, status_code) if status_code == 200: @@ -1834,7 +1826,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'admin_user', + 'user0', 'id_published_w', example_file_aux, '', @@ -1847,7 +1839,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'admin_user', + 'user0', 'id_processing_w', example_file_aux, '', @@ -1860,7 +1852,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'other_test_user', + 'user2', 'silly_value', example_file_aux, '', @@ -1873,7 +1865,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'other_test_user', + 'user2', 'examples_template', example_file_aux, '', @@ -1886,7 +1878,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', None, '', @@ -1899,7 +1891,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'local_path', - 'test_user', + 'user1', 'examples_template', example_file_aux, '', @@ -1912,7 +1904,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_aux, '', @@ -1925,7 +1917,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'id_unpublished_w', example_file_aux, 'test_content/test_embargo_entry', @@ -1938,7 +1930,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'id_unpublished_w', None, 'test_content/test_embargo_entry', @@ -1955,7 +1947,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', example_file_aux, '', @@ -1968,7 +1960,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', None, '', @@ -1985,7 +1977,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', None, '', @@ -2002,7 +1994,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', None, '', @@ -2019,7 +2011,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', None, '', @@ -2036,7 +2028,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_aux, '', @@ -2049,7 +2041,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'local_path', - 'admin_user', + 'user0', 'examples_template', example_file_aux, '', @@ -2062,7 +2054,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_aux, '', @@ -2075,7 +2067,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_aux, 'dir1/dir2/dir3', @@ -2088,7 +2080,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_vasp_with_binary, 'dir1/dir2', @@ -2105,7 +2097,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_aux, 'examples_template', @@ -2118,7 +2110,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_vasp_with_binary, '', @@ -2135,7 +2127,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'stream', - 'test_user', + 'user1', 'examples_template', example_file_corrupt_zip, '', @@ -2148,7 +2140,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', example_file_aux, 'examples_template', @@ -2161,7 +2153,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', example_file_mainfile_different_atoms, 'dir1/dir2', @@ -2174,7 +2166,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', example_file_mainfile_different_atoms, 'dir1/dir2', @@ -2187,7 +2179,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', example_file_mainfile_different_atoms, 'examples_template', @@ -2200,7 +2192,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', example_file_unparsable, 'examples_template', @@ -2213,7 +2205,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', example_file_vasp_with_binary, 'examples_template', @@ -2226,7 +2218,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', [example_file_vasp_with_binary, example_file_aux], 'dir1', @@ -2243,7 +2235,7 @@ def test_get_upload_entry_archive( ), pytest.param( 'multipart', - 'test_user', + 'user1', 'examples_template', [example_file_aux, example_file_corrupt_zip], 'dir1', @@ -2261,7 +2253,7 @@ def test_put_upload_raw_path( proc_infra, non_empty_processed, example_data_writeable, - test_auth_dict, + auth_dict, mode, user, upload_id, @@ -2289,7 +2281,7 @@ def test_put_upload_raw_path( url, mode, user, - test_auth_dict, + auth_dict, upload_id, source_paths, target_path, @@ -2337,14 +2329,14 @@ def test_put_upload_raw_path( @pytest.mark.parametrize( 'mode, user, expected_status_code', - [pytest.param('multipart', 'test_user', 409, id='conflict_in_concurrent_editing')], + [pytest.param('multipart', 'user1', 409, id='conflict_in_concurrent_editing')], ) def test_editing_raw_file( client, proc_infra, non_empty_processed, example_data_writeable, - test_auth_dict, + auth_dict, mode, user, expected_status_code, @@ -2354,7 +2346,7 @@ def test_editing_raw_file( action = 'PUT' url = f'uploads/{upload_id}/raw/{target_path}' path = 'examples_template/template.json' - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] # Get an existing upload with entries response = perform_get( @@ -2377,7 +2369,7 @@ def test_editing_raw_file( url, mode, user, - test_auth_dict, + auth_dict, upload_id, example_file_mainfile_different_atoms, target_path, @@ -2403,7 +2395,7 @@ def test_editing_raw_file( url, mode, user, - test_auth_dict, + auth_dict, upload_id, example_file_mainfile_different_atoms, target_path, @@ -2438,7 +2430,7 @@ def test_editing_raw_file( url, mode, user, - test_auth_dict, + auth_dict, upload_id, example_file_mainfile_different_atoms, target_path, @@ -2477,7 +2469,7 @@ def test_editing_raw_file( url, mode, user, - test_auth_dict, + auth_dict, upload_id, example_file_mainfile_different_atoms, target_path, @@ -2496,41 +2488,41 @@ def test_editing_raw_file( 'user, upload_id, path, expected_status_code', [ pytest.param( - 'test_user', 'id_published_w', 'test_content/newdir', 401, id='published' + 'user1', 'id_published_w', 'test_content/newdir', 401, id='published' ), pytest.param( None, 'id_unpublished_w', 'test_content/newdir', 401, id='no-credentials' ), pytest.param( - 'other_test_user', + 'user2', 'id_unpublished_w', 'test_content/newdir', 401, id='no-access', ), pytest.param( - 'admin_user', + 'user0', 'id_unpublished_w', 'test_content/newdir', 200, id='admin-access', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', 'test_content/test_embargo_entry/newdir', 200, id='ok', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', 'test_content/chars?! "\'@#$%&\\()[]{}=+`´^~*,.;:|<>', 200, id='special-chars', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', 'test_content/test_embargo_entry/mainfile.json/newdir', 400, @@ -2542,13 +2534,13 @@ def test_post_upload_raw_create_dir_path( client, proc_infra, example_data_writeable, - test_auth_dict, + auth_dict, user, upload_id, path, expected_status_code, ): - user_auth, _token = test_auth_dict[user] + user_auth, _token = auth_dict[user] response = client.post( f'uploads/{upload_id}/raw-create-dir/{requests.utils.quote(path)}', headers=user_auth, @@ -2564,7 +2556,7 @@ def test_post_upload_raw_create_dir_path( 'user, upload_id, path, use_upload_token, expected_status_code, expected_mainfiles', [ pytest.param( - 'test_user', + 'user1', 'examples_template', 'examples_template/1.aux', False, @@ -2573,7 +2565,7 @@ def test_post_upload_raw_create_dir_path( id='delete-aux-file', ), pytest.param( - 'test_user', + 'user1', 'examples_template', 'examples_template/template.json', False, @@ -2582,10 +2574,10 @@ def test_post_upload_raw_create_dir_path( id='delete-main-file', ), pytest.param( - 'test_user', 'examples_template', '', False, 200, [], id='delete-root' + 'user1', 'examples_template', '', False, 200, [], id='delete-root' ), pytest.param( - 'test_user', + 'user1', 'examples_template', 'examples_template', False, @@ -2594,7 +2586,7 @@ def test_post_upload_raw_create_dir_path( id='delete-subfolder', ), pytest.param( - 'test_user', + 'user1', 'examples_template', 'examples_template/1.aux', True, @@ -2603,7 +2595,7 @@ def test_post_upload_raw_create_dir_path( id='delete-token-access', ), pytest.param( - 'admin_user', + 'user0', 'examples_template', 'examples_template/1.aux', False, @@ -2612,7 +2604,7 @@ def test_post_upload_raw_create_dir_path( id='delete-admin-access', ), pytest.param( - 'other_test_user', + 'user2', 'examples_template', 'examples_template/1.aux', False, @@ -2648,7 +2640,7 @@ def test_post_upload_raw_create_dir_path( id='invalid-credentials-token', ), pytest.param( - 'test_user', + 'user1', 'id_published_w', 'examples_template/1.aux', False, @@ -2657,7 +2649,7 @@ def test_post_upload_raw_create_dir_path( id='published', ), pytest.param( - 'test_user', + 'user1', 'id_processing_w', 'examples_template/1.aux', False, @@ -2672,7 +2664,7 @@ def test_delete_upload_raw_path( proc_infra, non_empty_processed, example_data_writeable, - test_auth_dict, + auth_dict, user, upload_id, path, @@ -2680,7 +2672,7 @@ def test_delete_upload_raw_path( expected_status_code, expected_mainfiles, ): - user_auth, token = test_auth_dict[user] + user_auth, token = auth_dict[user] # Use either token or bearer token for the post operation (never both) user_auth_action = user_auth if use_upload_token: @@ -2717,13 +2709,13 @@ def test_delete_upload_raw_path( 'user, upload_id, kwargs', [ pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', dict(metadata=all_coauthor_metadata), id='edit-all', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', dict( metadata=dict(coauthors='unknown'), @@ -2732,19 +2724,19 @@ def test_delete_upload_raw_path( id='edit-coauthor-unknown-fails', ), pytest.param( - 'test_user', + 'user1', 'id_published_w', dict(metadata=dict(embargo_length=0)), id='lift-embargo', ), pytest.param( - 'admin_user', + 'user0', 'id_published_w', dict(metadata=all_admin_metadata), id='protected-admin', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', dict( metadata=dict(main_author='lhofstadter'), @@ -2753,7 +2745,7 @@ def test_delete_upload_raw_path( id='protected-not-admin', ), pytest.param( - 'test_user', + 'user1', 'silly_value', dict( metadata=dict(upload_name='test_name'), @@ -2762,13 +2754,13 @@ def test_delete_upload_raw_path( id='bad-upload_id', ), pytest.param( - 'admin_user', + 'user0', 'id_published_w', dict(metadata=dict(upload_name='test_name')), id='published-admin', ), pytest.param( - 'test_user', + 'user1', 'id_published_w', dict(metadata=dict(upload_name='test_name')), id='published-not-admin', @@ -2786,7 +2778,7 @@ def test_delete_upload_raw_path( id='invalid-credentials', ), pytest.param( - 'other_test_user', + 'user2', 'id_unpublished_w', dict( metadata=dict(upload_name='test_name'), @@ -2795,19 +2787,19 @@ def test_delete_upload_raw_path( id='no-access', ), pytest.param( - 'other_test_user', + 'user2', 'id_unpublished_w', dict(metadata=dict(upload_name='test_name'), add_coauthor=True), id='coauthor-access', ), pytest.param( - 'test_user', + 'user1', 'id_empty_w', dict(metadata=dict(upload_name='test_name')), id='empty-upload-ok', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', dict( query={ @@ -2822,7 +2814,7 @@ def test_delete_upload_raw_path( id='query-ok', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', dict( query={ @@ -2838,7 +2830,7 @@ def test_delete_upload_raw_path( id='query-cannot-edit-upload-data', ), pytest.param( - 'test_user', + 'user1', 'id_unpublished_w', dict( query={'upload_create_time:lt': '2021-01-01'}, @@ -2855,8 +2847,8 @@ def test_post_upload_edit( proc_infra, example_data_writeable, example_datasets, - test_auth_dict, - test_users_dict, + auth_dict, + users_dict, user, upload_id, kwargs, @@ -2866,8 +2858,8 @@ def test_post_upload_edit( `MetadataEditRequestHandler.edit_metadata`, we only do very simple verification here, the more extensive testnig is done in `tests.processing.test_edit_metadata`. """ - user_auth, _token = test_auth_dict[user] - user = test_users_dict.get(user) + user_auth, _token = auth_dict[user] + user = users_dict.get(user) query = kwargs.get('query') owner = kwargs.get('owner') metadata = kwargs.get('metadata') @@ -2917,7 +2909,7 @@ def test_post_upload_edit( 'multipart', example_file_vasp_with_binary, dict(upload_name='test_name'), - 'test_user', + 'user1', False, False, True, @@ -2928,7 +2920,7 @@ def test_post_upload_edit( 'multipart', example_file_vasp_with_binary, dict(), - 'test_user', + 'user1', False, False, True, @@ -2939,7 +2931,7 @@ def test_post_upload_edit( 'multipart', example_file_vasp_with_binary, dict(upload_name='test_name'), - 'test_user', + 'user1', True, False, True, @@ -2950,7 +2942,7 @@ def test_post_upload_edit( 'stream', example_file_vasp_with_binary, dict(embargo_length=0, upload_name='test_name'), - 'test_user', + 'user1', False, False, True, @@ -2961,7 +2953,7 @@ def test_post_upload_edit( 'stream', example_file_vasp_with_binary, dict(embargo_length=7), - 'test_user', + 'user1', False, False, True, @@ -2972,7 +2964,7 @@ def test_post_upload_edit( 'stream', example_file_vasp_with_binary, dict(embargo_length=37), - 'test_user', + 'user1', False, False, True, @@ -2983,7 +2975,7 @@ def test_post_upload_edit( 'stream', example_file_vasp_with_binary, dict(upload_name='test_name'), - 'test_user', + 'user1', True, False, True, @@ -2994,7 +2986,7 @@ def test_post_upload_edit( 'local_path', example_file_vasp_with_binary, dict(), - 'admin_user', + 'user0', False, False, True, @@ -3005,7 +2997,7 @@ def test_post_upload_edit( 'local_path', example_file_vasp_with_binary, dict(), - 'test_user', + 'user1', False, False, True, @@ -3016,7 +3008,7 @@ def test_post_upload_edit( 'stream', example_file_vasp_with_binary, dict(), - 'test_user', + 'user1', False, False, False, @@ -3060,7 +3052,7 @@ def test_post_upload_edit( 'stream', [], dict(upload_name='test_name'), - 'test_user', + 'user1', False, False, True, @@ -3071,7 +3063,7 @@ def test_post_upload_edit( 'stream', example_file_aux, dict(file_name='1.aux'), - 'test_user', + 'user1', False, False, True, @@ -3082,7 +3074,7 @@ def test_post_upload_edit( 'stream', example_file_aux, dict(), - 'test_user', + 'user1', False, False, True, @@ -3093,7 +3085,7 @@ def test_post_upload_edit( 'stream', example_file_vasp_with_binary, dict(upload_name='test_name', publish_directly=True), - 'test_user', + 'user1', False, False, True, @@ -3104,7 +3096,7 @@ def test_post_upload_edit( 'stream', empty_file, dict(upload_name='test_name', publish_directly=True), - 'test_user', + 'user1', False, False, True, @@ -3115,7 +3107,7 @@ def test_post_upload_edit( 'stream', example_file_vasp_with_binary, dict(upload_name='test_name'), - 'test_user', + 'user1', False, True, True, @@ -3126,7 +3118,7 @@ def test_post_upload_edit( 'multipart', example_file_corrupt_zip, dict(), - 'test_user', + 'user1', False, False, True, @@ -3137,7 +3129,7 @@ def test_post_upload_edit( 'multipart', [example_file_aux, example_file_mainfile_different_atoms], dict(), - 'test_user', + 'user1', False, False, True, @@ -3148,7 +3140,7 @@ def test_post_upload_edit( 'multipart', [example_file_aux, example_file_corrupt_zip], dict(), - 'test_user', + 'user1', False, False, True, @@ -3162,7 +3154,7 @@ def test_post_upload( mongo_function, proc_infra, monkeypatch, - test_auth_dict, + auth_dict, empty_upload, non_empty_example_upload, mode, @@ -3197,7 +3189,7 @@ def test_post_upload( url, mode, user, - test_auth_dict, + auth_dict, upload_id, source_paths, target_path, @@ -3228,7 +3220,7 @@ def test_post_upload( assert not upload_proc.published else: assert_gets_published( - client, upload_id, test_auth_dict['test_user'][0], **query_args + client, upload_id, auth_dict['user1'][0], **query_args ) @@ -3266,20 +3258,18 @@ def test_post_upload( pytest.param( dict(user='invalid', expected_status_code=401), id='invalid-credentials' ), - pytest.param( - dict(user='other_test_user', expected_status_code=401), id='no-access' - ), + pytest.param(dict(user='user2', expected_status_code=401), id='no-access'), ], ) def test_post_upload_action_publish( - client, proc_infra, example_data_writeable, test_auth_dict, kwargs + client, proc_infra, example_data_writeable, auth_dict, kwargs ): """Tests the publish action with various arguments.""" upload_id = kwargs.get('upload_id', 'id_unpublished_w') query_args = kwargs.get('query_args', {}) expected_status_code = kwargs.get('expected_status_code', 200) - user = kwargs.get('user', 'test_user') - user_auth, __token = test_auth_dict[user] + user = kwargs.get('user', 'user1') + user_auth, __token = auth_dict[user] response = perform_post_upload_action( client, user_auth, upload_id, 'publish', **query_args @@ -3316,8 +3306,8 @@ def test_post_upload_action_publish_to_central_nomad( proc_infra, monkeypatch, oasis_publishable_upload, - test_users_dict, - test_auth_dict, + users_dict, + auth_dict, import_settings, query_args, ): @@ -3326,8 +3316,8 @@ def test_post_upload_action_publish_to_central_nomad( query_args['to_central_nomad'] = True embargo_length = query_args.get('embargo_length') expected_status_code = 200 - user = 'admin_user' - user_auth, __token = test_auth_dict[user] + user = 'user0' + user_auth, __token = auth_dict[user] old_upload = Upload.get(upload_id) import_settings = config.bundle_import.default_settings.customize(import_settings) @@ -3396,24 +3386,16 @@ def test_post_upload_action_publish_to_central_nomad( @pytest.mark.parametrize( 'upload_id, publish, user, expected_status_code', [ - pytest.param( - 'examples_template', True, 'admin_user', 200, id='published-admin' - ), - pytest.param( - 'examples_template', True, 'test_user', 401, id='published-not-admin' - ), - pytest.param('examples_template', False, 'test_user', 200, id='not-published'), + pytest.param('examples_template', True, 'user0', 200, id='published-admin'), + pytest.param('examples_template', True, 'user1', 401, id='published-not-admin'), + pytest.param('examples_template', False, 'user1', 200, id='not-published'), pytest.param('examples_template', False, None, 401, id='no-credentials'), pytest.param( 'examples_template', False, 'invalid', 401, id='invalid-credentials' ), - pytest.param( - 'examples_template', False, 'other_test_user', 401, id='no-access' - ), - pytest.param( - 'id_processing_w', False, 'test_user', 400, id='already-processing' - ), - pytest.param('silly_value', False, 'test_user', 404, id='invalid-upload_id'), + pytest.param('examples_template', False, 'user2', 401, id='no-access'), + pytest.param('id_processing_w', False, 'user1', 400, id='already-processing'), + pytest.param('silly_value', False, 'user1', 404, id='invalid-upload_id'), ], ) def test_post_upload_action_process( @@ -3424,7 +3406,7 @@ def test_post_upload_action_process( example_data_writeable, non_empty_processed, internal_example_user_metadata, - test_auth_dict, + auth_dict, upload_id, publish, user, @@ -3440,7 +3422,7 @@ def test_post_upload_action_process( monkeypatch.setattr('nomad.config.meta.version', 're_process_test_version') monkeypatch.setattr('nomad.config.meta.commit', 're_process_test_commit') - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_post_upload_action(client, user_auth, upload_id, 'process') assert_response(response, expected_status_code) @@ -3448,7 +3430,7 @@ def test_post_upload_action_process( assert_processing( client, upload_id, - test_auth_dict['test_user'][0], + auth_dict['user1'][0], check_files=False, published=True, ) @@ -3459,7 +3441,7 @@ def test_post_upload_action_process( [ pytest.param( 'id_published_w', - 'admin_user', + 'user0', None, {'entry_id': 'id_published_w_entry'}, False, @@ -3470,7 +3452,7 @@ def test_post_upload_action_process( ), pytest.param( 'id_unpublished_w', - 'other_test_user', + 'user2', None, {'entry_id': 'id_unpublished_w_entry'}, False, @@ -3481,7 +3463,7 @@ def test_post_upload_action_process( ), pytest.param( 'id_unpublished_w', - 'test_user', + 'user1', None, None, False, @@ -3492,7 +3474,7 @@ def test_post_upload_action_process( ), pytest.param( 'id_unpublished_w', - 'test_user', + 'user1', None, {'entry_id': ['id_unpublished_w_entry', 'silly']}, False, @@ -3503,7 +3485,7 @@ def test_post_upload_action_process( ), pytest.param( 'id_unpublished_w', - 'test_user', + 'user1', None, {'entry_id': 'id_unpublished_w_entry'}, True, @@ -3514,7 +3496,7 @@ def test_post_upload_action_process( ), pytest.param( 'id_unpublished_w', - 'admin_user', + 'user0', 'admin', {'entry_id': 'id_unpublished_w_entry'}, False, @@ -3530,7 +3512,7 @@ def test_post_upload_action_delete_entry_files( mongo_function, proc_infra, example_data_writeable, - test_auth_dict, + auth_dict, upload_id, user, owner, @@ -3540,7 +3522,7 @@ def test_post_upload_action_delete_entry_files( expect_exists, expect_not_exists, ): - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] json = {} if include_parent_folders is not None: json.update(include_parent_folders=include_parent_folders) @@ -3569,30 +3551,28 @@ def test_post_upload_action_delete_entry_files( @pytest.mark.parametrize( 'upload_id, user, preprocess, expected_status_code', [ - pytest.param('id_published_w', 'test_user', None, 200, id='ok'), - pytest.param('id_published_w', 'other_test_user', None, 401, id='no-access'), - pytest.param( - 'id_published_w', 'other_test_user', 'make-coauthor', 200, id='ok-coauthor' - ), + pytest.param('id_published_w', 'user1', None, 200, id='ok'), + pytest.param('id_published_w', 'user2', None, 401, id='no-access'), + pytest.param('id_published_w', 'user2', 'make-coauthor', 200, id='ok-coauthor'), pytest.param('id_published_w', None, None, 401, id='no-credentials'), pytest.param('id_published_w', 'invalid', None, 401, id='invalid-credentials'), - pytest.param('id_unpublished_w', 'test_user', None, 400, id='not-published'), - pytest.param('id_published_w', 'test_user', 'lift', 400, id='already-lifted'), + pytest.param('id_unpublished_w', 'user1', None, 400, id='not-published'), + pytest.param('id_published_w', 'user1', 'lift', 400, id='already-lifted'), ], ) def test_post_upload_action_lift_embargo( client, proc_infra, example_data_writeable, - test_auth_dict, - test_users_dict, + auth_dict, + users_dict, upload_id, user, preprocess, expected_status_code, ): - user_auth, __token = test_auth_dict[user] - user = test_users_dict.get(user) + user_auth, __token = auth_dict[user] + user = users_dict.get(user) if preprocess: if preprocess == 'lift': @@ -3614,16 +3594,14 @@ def test_post_upload_action_lift_embargo( @pytest.mark.parametrize( 'upload_id, user, expected_status_code', [ - pytest.param('id_unpublished_w', 'test_user', 200, id='delete-own'), + pytest.param('id_unpublished_w', 'user1', 200, id='delete-own'), + pytest.param('id_unpublished_w', 'user2', 401, id='delete-others-not-admin'), + pytest.param('id_unpublished_w', 'user0', 200, id='delete-others-admin'), + pytest.param('id_published_w', 'user1', 401, id='delete-own-published'), pytest.param( - 'id_unpublished_w', 'other_test_user', 401, id='delete-others-not-admin' + 'id_published_w', 'user0', 200, id='delete-others-published-admin' ), - pytest.param('id_unpublished_w', 'admin_user', 200, id='delete-others-admin'), - pytest.param('id_published_w', 'test_user', 401, id='delete-own-published'), - pytest.param( - 'id_published_w', 'admin_user', 200, id='delete-others-published-admin' - ), - pytest.param('silly_value', 'test_user', 404, id='invalid-upload_id'), + pytest.param('silly_value', 'user1', 404, id='invalid-upload_id'), pytest.param('id_unpublished_w', None, 401, id='no-credentials'), pytest.param('id_unpublished_w', 'invalid', 401, id='invalid-credentials'), ], @@ -3632,51 +3610,45 @@ def test_delete_upload( client, proc_infra, example_data_writeable, - test_auth_dict, + auth_dict, upload_id, user, expected_status_code, ): """Uploads a file, and then tries to delete it, with different parameters and users.""" - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = client.delete(f'uploads/{upload_id}', headers=user_auth) assert_response(response, expected_status_code) if expected_status_code == 200: - assert_upload_does_not_exist(client, upload_id, test_auth_dict['test_user'][0]) + assert_upload_does_not_exist(client, upload_id, auth_dict['user1'][0]) @pytest.mark.parametrize( 'upload_id, user, query_args, expected_status_code', [ - pytest.param('id_published_w', 'test_user', dict(), 200, id='published-owner'), - pytest.param('id_published_w', 'admin_user', dict(), 200, id='published-admin'), - pytest.param( - 'id_published_w', 'other_test_user', dict(), 401, id='published-not-owner' - ), + pytest.param('id_published_w', 'user1', dict(), 200, id='published-owner'), + pytest.param('id_published_w', 'user0', dict(), 200, id='published-admin'), + pytest.param('id_published_w', 'user2', dict(), 401, id='published-not-owner'), pytest.param( 'id_published_w', - 'test_user', + 'user1', dict(include_raw_files=False), 200, id='published-owner-exclude-raw', ), pytest.param( 'id_published_w', - 'test_user', + 'user1', dict(include_archive_files=False), 200, id='published-owner-exclude-archive', ), - pytest.param( - 'id_unpublished_w', 'test_user', dict(), 200, id='unpublished-owner' - ), - pytest.param( - 'id_unpublished_w', 'admin_user', dict(), 200, id='unpublished-admin' - ), + pytest.param('id_unpublished_w', 'user1', dict(), 200, id='unpublished-owner'), + pytest.param('id_unpublished_w', 'user0', dict(), 200, id='unpublished-admin'), pytest.param( 'id_unpublished_w', - 'other_test_user', + 'user2', dict(), 401, id='unpublished-not-owner', @@ -3687,7 +3659,7 @@ def test_get_upload_bundle( client, proc_infra, example_data_writeable, - test_auth_dict, + auth_dict, upload_id, user, query_args, @@ -3697,7 +3669,7 @@ def test_get_upload_bundle( include_archive_files = query_args.get('include_archive_files', True) url = build_url(f'uploads/{upload_id}/bundle', query_args) - response = perform_get(client, url, user_auth=test_auth_dict[user][0]) + response = perform_get(client, url, user_auth=auth_dict[user][0]) assert_response(response, expected_status_code) if expected_status_code == 200: with zipfile.ZipFile(io.BytesIO(response.content)) as zip_file: @@ -3719,16 +3691,12 @@ def test_get_upload_bundle( @pytest.mark.parametrize( 'publish, test_duplicate, user, export_args, query_args, expected_status_code', [ + pytest.param(True, False, 'user0', dict(), dict(), 200, id='published-admin'), pytest.param( - True, False, 'admin_user', dict(), dict(), 200, id='published-admin' - ), - pytest.param( - False, False, 'admin_user', dict(), dict(), 200, id='unpublished-admin' - ), - pytest.param(True, True, 'admin_user', dict(), dict(), 400, id='duplicate'), - pytest.param( - True, False, 'other_test_user', dict(), dict(), 401, id='not-oasis-admin' + False, False, 'user0', dict(), dict(), 200, id='unpublished-admin' ), + pytest.param(True, True, 'user0', dict(), dict(), 400, id='duplicate'), + pytest.param(True, False, 'user2', dict(), dict(), 401, id='not-oasis-admin'), pytest.param(True, False, None, dict(), dict(), 401, id='no-credentials'), ], ) @@ -3737,7 +3705,7 @@ def test_post_upload_bundle( proc_infra, non_empty_processed, internal_example_user_metadata, - test_auth_dict, + auth_dict, publish, test_duplicate, user, @@ -3767,7 +3735,7 @@ def test_post_upload_bundle( # Delete the upload so we can import the bundle without id collisions upload.delete_upload_local() # Finally, import the bundle - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_post_put_file( client, 'POST', 'uploads/bundle', 'stream', export_path, user_auth, **query_args ) @@ -3782,11 +3750,11 @@ def test_post_upload_bundle( 'authorized, expected_status_code', [pytest.param(True, 200, id='ok'), pytest.param(False, 401, id='not-authorized')], ) -def test_get_command_examples(client, test_user_auth, authorized, expected_status_code): +def test_get_command_examples(client, user1_auth, authorized, expected_status_code): response = perform_get( client, 'uploads/command-examples', - user_auth=test_user_auth if authorized else None, + user_auth=user1_auth if authorized else None, ) assert_response(response, expected_status_code) if expected_status_code == 200: diff --git a/tests/app/v1/routers/uploads/test_group_uploads.py b/tests/app/v1/routers/uploads/test_group_uploads.py index bae0908536458e531f9470a5b5346d8379e00197..cce72a9e3aa6be574b1cb94f012ddf76896d6cd0 100644 --- a/tests/app/v1/routers/uploads/test_group_uploads.py +++ b/tests/app/v1/routers/uploads/test_group_uploads.py @@ -11,31 +11,31 @@ from .common import assert_upload pytest.param(None, {}, [], 401, id='guest-user'), pytest.param('invalid', {}, [], 401, id='invalid-user'), pytest.param( - 'other_test_user', + 'user2', {}, [ - 'id_coauthor_other', - 'id_reviewer_other', - 'id_coauthor_mixed', - 'id_reviewer_mixed', + 'id_coauthor_group2', + 'id_reviewer_group2', + 'id_coauthor_group012', + 'id_reviewer_group012', 'id_reviewer_all', ], 200, id='no-args', ), pytest.param( - 'other_test_user', + 'user2', {'roles': 'coauthor'}, - ['id_coauthor_other', 'id_coauthor_mixed'], + ['id_coauthor_group2', 'id_coauthor_group012'], 200, id='coauthor', ), pytest.param( - 'other_test_user', + 'user2', {'roles': 'reviewer'}, [ - 'id_reviewer_other', - 'id_reviewer_mixed', + 'id_reviewer_group2', + 'id_reviewer_group012', 'id_reviewer_all', ], 200, @@ -46,13 +46,13 @@ from .common import assert_upload def test_get_group_uploads( client, example_data_groups, - test_auth_dict, + auth_dict, user, query_params, expected_upload_ids, expected_status_code, ): - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_get(client, 'uploads', user_auth=user_auth, **query_params) assert_response(response, expected_status_code) @@ -70,26 +70,30 @@ def test_get_group_uploads( @pytest.mark.parametrize( 'user, upload_id, expected_status_code', [ - pytest.param('other_test_user', 'id_coauthor_other', 200, id='coauthor-other'), - pytest.param('invalid', 'id_coauthor_other', 401, id='coauthor-other-invalid'), - pytest.param(None, 'id_coauthor_other', 401, id='coauthor-other-guest'), - pytest.param('other_test_user', 'id_reviewer_other', 200, id='reviewer-other'), - pytest.param('invalid', 'id_reviewer_other', 401, id='reviewer-other-invalid'), - pytest.param(None, 'id_reviewer_other', 401, id='reviewer-other-guest'), - pytest.param('other_test_user', 'id_coauthor_mixed', 200, id='coauthor-mixed'), - pytest.param('other_test_user', 'id_reviewer_mixed', 200, id='reviewer-mixed'), - pytest.param('other_test_user', 'id_reviewer_all', 200, id='reviewer-all'), + pytest.param('user2', 'id_coauthor_group2', 200, id='coauthor-group2'), + pytest.param( + 'invalid', 'id_coauthor_group2', 401, id='coauthor-group2-invalid' + ), + pytest.param(None, 'id_coauthor_group2', 401, id='coauthor-group2-guest'), + pytest.param('user2', 'id_reviewer_group2', 200, id='reviewer-group2'), + pytest.param( + 'invalid', 'id_reviewer_group2', 401, id='reviewer-group2-invalid' + ), + pytest.param(None, 'id_reviewer_group2', 401, id='reviewer-group2-guest'), + pytest.param('user2', 'id_coauthor_group012', 200, id='coauthor-group012'), + pytest.param('user2', 'id_reviewer_group012', 200, id='reviewer-group012'), + pytest.param('user2', 'id_reviewer_all', 200, id='reviewer-all'), ], ) def test_get_group_upload( client, example_data_groups, - test_auth_dict, + auth_dict, user, upload_id, expected_status_code, ): - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] response = perform_get(client, f'uploads/{upload_id}', user_auth) assert_response(response, expected_status_code) if expected_status_code == 200: @@ -101,69 +105,69 @@ def test_get_group_upload( [ pytest.param( 'upload_no_group', - 'test_user', - {'coauthor_groups': 'other_owner_group'}, + 'user1', + {'coauthor_groups': 'group2'}, 200, - ['other_owner_group'], - id='coauthor-other-group', + ['group2'], + id='coauthor-group2', ), pytest.param( 'upload_no_group', - 'test_user', + 'user1', { 'coauthor_groups': [ - 'user_owner_group', - 'other_owner_group', - 'mixed_group', + 'group1', + 'group2', + 'group012', ] }, 200, - ['user_owner_group', 'other_owner_group', 'mixed_group'], + ['group1', 'group2', 'group012'], id='coauthor-multiple-groups', ), pytest.param( 'upload_no_group', - 'test_user', - {'reviewer_groups': ['other_owner_group', 'other_owner_group']}, + 'user1', + {'reviewer_groups': ['group2', 'group2']}, 200, - ['other_owner_group'], - id='reviewer-other-double', + ['group2'], + id='reviewer-group2-double', ), pytest.param( - 'upload_coauthor_other_and_mixed_group', - 'test_user', - {'coauthor_groups': {'add': 'other_owner_group'}}, + 'upload_coauthor_group2_and_group012', + 'user1', + {'coauthor_groups': {'add': 'group2'}}, 200, - ['other_owner_group', 'mixed_group'], + ['group2', 'group012'], id='coauthor-add-existing', ), pytest.param( - 'upload_coauthor_other_and_mixed_group', - 'test_user', + 'upload_coauthor_group2_and_group012', + 'user1', {'coauthor_groups': 'unknown_group'}, 422, - ['other_owner_group', 'mixed_group'], + ['group2', 'group012'], id='coauthor-set0-unknown-fails', ), pytest.param( - 'upload_coauthor_other_and_mixed_group', - 'test_user', + 'upload_coauthor_group2_and_group012', + 'user1', {'coauthor_groups': {'set': 'unknown_group'}}, 422, - ['other_owner_group', 'mixed_group'], + ['group2', 'group012'], id='coauthor-set1-unknown-fails', ), pytest.param( - 'upload_coauthor_other_and_mixed_group', - 'test_user', + 'upload_coauthor_group2_and_group012', + 'user1', {'coauthor_groups': {'add': 'unknown_group'}}, 422, - ['other_owner_group', 'mixed_group'], + ['group2', 'group012'], id='coauthor-add-unknown-fails', ), pytest.param( 'upload_reviewer_all_group', - 'test_user', + 'user1', {'reviewer_groups': 'unknown_group'}, 422, ['all'], @@ -171,7 +175,7 @@ def test_get_group_upload( ), pytest.param( 'upload_reviewer_all_group', - 'test_user', + 'user1', {'reviewer_groups': {'set': 'unknown_group'}}, 422, ['all'], @@ -179,7 +183,7 @@ def test_get_group_upload( ), pytest.param( 'upload_reviewer_all_group', - 'test_user', + 'user1', {'reviewer_groups': {'add': 'unknown_group'}}, 422, ['all'], @@ -187,15 +191,15 @@ def test_get_group_upload( ), pytest.param( 'upload_no_group', - 'test_user', - {'reviewer_groups': ['other_owner_group']}, + 'user1', + {'reviewer_groups': ['group2']}, 200, - ['other_owner_group'], - id='reviewer-other-group', + ['group2'], + id='reviewer-group2', ), pytest.param( 'upload_no_group', - 'test_user', + 'user1', {'reviewer_groups': ['all']}, 200, ['all'], @@ -203,7 +207,7 @@ def test_get_group_upload( ), pytest.param( 'upload_no_group', - 'test_user', + 'user1', {'coauthor_groups': ['all']}, 422, [], @@ -211,8 +215,8 @@ def test_get_group_upload( ), pytest.param( 'upload_no_group', - 'other_test_user', - {'reviewer_groups': ['other_owner_group']}, + 'user2', + {'reviewer_groups': ['group2']}, 422, [], id='other-user-fails', @@ -226,13 +230,13 @@ def test_add_groups_to_upload( proc_infra, convert_group_labels_to_ids, upload_fixture, - test_auth_dict, + auth_dict, user, expected_status_code, metadata, expected_groups, ): - user_auth, __token = test_auth_dict[user] + user_auth, __token = auth_dict[user] upload_fixture = request.getfixturevalue(upload_fixture) upload_id = list(upload_fixture.uploads)[0] group_quantity = list(metadata)[0] @@ -254,29 +258,27 @@ def test_add_groups_to_upload( @pytest.mark.parametrize( 'user, metadata, expected_status_code, expected_groups', [ + pytest.param('user1', {'coauthor_groups': []}, 200, [], id='user1-empty'), pytest.param( - 'test_user', {'coauthor_groups': []}, 200, [], id='test-user-empty' - ), - pytest.param( - 'test_user', + 'user1', {'coauthor_groups': {'set': []}}, 200, [], - id='test-user-set-empty', + id='user1-set-empty', ), pytest.param( - 'test_user', - {'coauthor_groups': {'remove': 'mixed_group'}}, + 'user1', + {'coauthor_groups': {'remove': 'group012'}}, 200, - ['other_owner_group'], - id='test-user-remove-other', + ['group2'], + id='user1-remove-single', ), pytest.param( - 'yet_test_user', - {'reviewer_groups': ['yet_owner_group']}, + 'user3', + {'reviewer_groups': ['group3']}, 422, - ['other_owner_group', 'mixed_group'], - id='yet-user-fails', + ['group2', 'group012'], + id='user3-fails', ), ], ) @@ -285,15 +287,15 @@ def test_remove_groups_from_upload( user_groups_function, proc_infra, convert_group_labels_to_ids, - upload_coauthor_other_and_mixed_group, - test_auth_dict, + upload_coauthor_group2_and_group012, + auth_dict, user, metadata, expected_status_code, expected_groups, ): - user_auth, __token = test_auth_dict[user] - upload_id = list(upload_coauthor_other_and_mixed_group.uploads)[0] + user_auth, __token = auth_dict[user] + upload_id = list(upload_coauthor_group2_and_group012.uploads)[0] url = f'uploads/{upload_id}/edit' metadata = convert_group_labels_to_ids(metadata) diff --git a/tests/archive/test_archive.py b/tests/archive/test_archive.py index 317c8b2cf0f69eea0b0a85216b6b86b3fa57a0f8..122ec3d998919e052ae02635439f40b2c866c403 100644 --- a/tests/archive/test_archive.py +++ b/tests/archive/test_archive.py @@ -886,13 +886,13 @@ def test_required_reader( @pytest.fixture(scope='function') -def example_data_with_reference(proc_infra, test_user, json_dict): +def example_data_with_reference(proc_infra, user1, json_dict): """ Provides a couple of entries with references. Only used in test_required_reader_with_remote_reference. """ - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload( upload_id='id_published_with_ref', upload_name='name_published', published=True @@ -1062,7 +1062,7 @@ def test_required_reader_with_remote_reference( remote_reference_required, resolve_inplace, example_data_with_reference, - test_user, + user1, entry_id, inplace_result, ): @@ -1081,7 +1081,7 @@ def test_required_reader_with_remote_reference( with read_archive(BytesIO(packed_archive)) as archive_reader: required_reader = RequiredReader( - remote_reference_required, resolve_inplace=resolve_inplace, user=test_user + remote_reference_required, resolve_inplace=resolve_inplace, user=user1 ) results = required_reader.read( archive_reader, 'entry_id', 'id_published_with_ref' @@ -1113,7 +1113,7 @@ def test_required_reader_with_remote_reference( assert calculation.system_ref.symmetry[0].space_group_number == 221 -def test_custom_schema(test_user, proc_infra): +def test_custom_schema(user1, proc_infra): yaml_archive = yaml.safe_load( """ --- @@ -1143,7 +1143,7 @@ data: """ ) archive = EntryArchive.m_from_dict(yaml_archive) - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload( upload_id='id_custom', upload_name='name_published', published=True @@ -1156,7 +1156,7 @@ data: f = BytesIO() write_archive(f, 1, [('id_example', yaml_archive)], entry_toc_depth=2) with read_archive(BytesIO(f.getbuffer())) as archive_reader: - required_reader = RequiredReader({'data': {'my_quantity': '*'}}, user=test_user) + required_reader = RequiredReader({'data': {'my_quantity': '*'}}, user=user1) results = required_reader.read(archive_reader, 'id_example', 'id_custom') assert_dict( diff --git a/tests/conftest.py b/tests/conftest.py index cf69cc71826ecd0d5a106f5d0deb49bbae5516c0..607a249723aa4b70ea8ebc12fd369ebd4551cac2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -186,7 +186,7 @@ def reset_config(): @pytest.fixture(scope='session') -def api_v1(monkeysession, test_user_molds): +def api_v1(monkeysession, user_molds): """ This fixture provides an HTTP client with Python requests interface that accesses the fast api. The have to provide URLs that start with out leading '/' after '.../api/v1. @@ -216,7 +216,7 @@ def api_v1(monkeysession, test_user_molds): ) def __call__(self, request): - for user in test_user_molds.values(): + for user in user_molds.values(): if user['username'] == self.user or user['email'] == self.user: request.headers['Authorization'] = f'Bearer {user["user_id"]}' return request diff --git a/tests/data/test_examples.py b/tests/data/test_examples.py index 2255a563cab64c7ef9176b8a3a484a99b86a7b90..26e82471805d25c53ec908ab2eb4dfc34928d5ac 100644 --- a/tests/data/test_examples.py +++ b/tests/data/test_examples.py @@ -87,14 +87,14 @@ def test_sample_tabular(mainfile, assert_xpaths, raw_files_function, no_warn): ) def test_sample_entry_mode( mongo_function, - test_user, + user1, raw_files_function, monkeypatch, proc_infra, test_files, number_of_entries, ): - upload = create_upload('test_upload_id', test_user.user_id, test_files) + upload = create_upload('test_upload_id', user1.user_id, test_files) assert upload is not None assert upload.processed_entries_count == number_of_entries @@ -213,14 +213,14 @@ def test_sample_entry_mode( ) def test_tabular_doc_examples( mongo_function, - test_user, + user1, raw_files_function, monkeypatch, proc_infra, test_files, status, ): - upload = create_upload('test_upload_id', test_user.user_id, test_files) + upload = create_upload('test_upload_id', user1.user_id, test_files) assert upload is not None for entry in Entry.objects(upload_id='test_upload_id'): diff --git a/tests/datamodel/metainfo/eln/test_labfolder.py b/tests/datamodel/metainfo/eln/test_labfolder.py index 43b50899d82e04e72323b402777d8730baac7907..b92aeb6bfcb2186f4be2360a458155294311dfcf 100644 --- a/tests/datamodel/metainfo/eln/test_labfolder.py +++ b/tests/datamodel/metainfo/eln/test_labfolder.py @@ -32,7 +32,7 @@ from nomad.datamodel.metainfo.eln.labfolder import ( from nomad.utils.exampledata import ExampleData -def test_labfolder_integration(mongo_function, monkeypatch, test_user): +def test_labfolder_integration(mongo_function, monkeypatch, user1): directory = 'tests/data/datamodel/metainfo/eln/material_library' mainfile = 'example-labfolder.archive.json' @@ -188,7 +188,7 @@ def test_labfolder_integration(mongo_function, monkeypatch, test_user): def test_labfolder_detailed( mongo_function, monkeypatch, - test_user, + user1, status_code, project_url, labfolder_email, @@ -223,7 +223,7 @@ def test_labfolder_detailed( monkeypatch.setattr(requests, 'get', mock_labfolder_json_method) # processing preparation - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id='test_upload_id', published=False) data.create_entry( diff --git a/tests/datamodel/metainfo/eln/test_openbis.py b/tests/datamodel/metainfo/eln/test_openbis.py index 1da5bfdde3df538f3b59fb00a0e529a9f2caf870..cfc4f14fae408e5b094accfe1e6d736fa0cc1e6f 100644 --- a/tests/datamodel/metainfo/eln/test_openbis.py +++ b/tests/datamodel/metainfo/eln/test_openbis.py @@ -94,7 +94,7 @@ def mocked_login(url): def test_openbis( mongo_function, monkeypatch, - test_user, + user1, status_code, project_url, username, @@ -153,7 +153,7 @@ def test_openbis( # patching openbis attrs monkeypatch.setattr(pybis, 'Openbis', mock_openbis_response) - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id='test_upload_id', published=False) data.create_entry( diff --git a/tests/datamodel/metainfo/eln/test_system.py b/tests/datamodel/metainfo/eln/test_system.py index 2d278777baada3701edd960ab5d0b3155a9e6a30..e1bcd2e71016c4f202fc1189708e6ecb227fa6e5 100644 --- a/tests/datamodel/metainfo/eln/test_system.py +++ b/tests/datamodel/metainfo/eln/test_system.py @@ -24,12 +24,12 @@ from nomad.utils.exampledata import ExampleData from tests.normalizing.conftest import run_normalize -def test_substance(raw_files_function, test_user, mongo_function): +def test_substance(raw_files_function, user1, mongo_function): directory = 'tests/data/datamodel/metainfo/eln' mainfile = 'test_substance.archive.yaml' upload_id = 'test_upload_id' - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id=upload_id, published=False) context = ClientContext(local_dir=directory, upload_id=upload_id) @@ -52,11 +52,11 @@ def test_substance(raw_files_function, test_user, mongo_function): os.unlink(os.path.join(directory, 'cas_10101-63-0_image.svg')) -def test_ensemble(raw_files_function, test_user, mongo_function): +def test_ensemble(raw_files_function, user1, mongo_function): directory = 'tests/data/datamodel/metainfo/eln' mainfile = 'test_ensemble.archive.yaml' upload_id = 'test_upload_id' - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id=upload_id, published=False) context = ClientContext(local_dir=directory, upload_id=upload_id) diff --git a/tests/datamodel/test_context.py b/tests/datamodel/test_context.py index 86692ff5a0eeae53d240ffe737d554d42cbf23ca..9a1bef47b04e7dbec5fcbcb14dfc5f84612b73f7 100644 --- a/tests/datamodel/test_context.py +++ b/tests/datamodel/test_context.py @@ -549,9 +549,9 @@ def test_client_custom_schema(api_v1, published_wo_user_metadata): ], ) def test_client_external_schema( - referencing_upload_contents, raw_files_function, test_user, api_v1, proc_infra + referencing_upload_contents, raw_files_function, user1, api_v1, proc_infra ): - upload1 = Upload(upload_id='references_upload_id1', main_author=test_user.user_id) + upload1 = Upload(upload_id='references_upload_id1', main_author=user1.user_id) upload1.save() files.StagingUploadFiles(upload_id=upload1.upload_id, create=True) upload1.staging_upload_files.add_rawfiles('examples/data/references/upload1') @@ -567,7 +567,7 @@ def test_client_external_schema( context2 = ClientContext( upload_id='upload2_id', installation_url=installation_url, - username=test_user.username, + username=user1.username, password='password', ) @@ -590,8 +590,8 @@ def test_client_external_schema( assert results == content -def test_circular_external_schema(raw_files_function, test_user, api_v1, proc_infra): - upload1 = Upload(upload_id='upload_id', main_author=test_user.user_id) +def test_circular_external_schema(raw_files_function, user1, api_v1, proc_infra): + upload1 = Upload(upload_id='upload_id', main_author=user1.user_id) upload1.save() files.StagingUploadFiles(upload_id=upload1.upload_id, create=True) upload1.staging_upload_files.add_rawfiles('examples/data/references/circular') diff --git a/tests/examples/test_archive_query.py b/tests/examples/test_archive_query.py index a10382204ab5132a52dd44bbe7ac9e482e1b158e..c31de1b4e984c0c34fdae96ca289123cbc10286a 100644 --- a/tests/examples/test_archive_query.py +++ b/tests/examples/test_archive_query.py @@ -32,7 +32,7 @@ def test_archive_query( elastic_function, raw_files_function, mongo_function, - test_user, + user1, capsys, ): mainfile = os.path.join( @@ -42,7 +42,7 @@ def test_archive_query( run_normalize(archive) archive.metadata.apply_archive_metadata(archive) - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload('test_upload_id', published=True) data.create_entry(upload_id='test_upload_id', entry_archive=archive) data.save() diff --git a/tests/fixtures/data.py b/tests/fixtures/data.py index 8f2f339a09749e6293be519fb7c8482f00b986fc..1977d6713523f3416cd671a2b8d48fe06cd42a42 100644 --- a/tests/fixtures/data.py +++ b/tests/fixtures/data.py @@ -63,11 +63,11 @@ def empty_upload(): @pytest.fixture(scope='module') -def example_user_metadata(other_test_user, test_user) -> dict: +def example_user_metadata(user2) -> dict: return { 'comment': 'test comment', 'references': ['http://external.ref/one', 'http://external.ref/two'], - 'entry_coauthors': [other_test_user.user_id], + 'entry_coauthors': [user2.user_id], '_pid': '256', 'external_id': 'external_test_id', } @@ -127,7 +127,7 @@ def oasis_publishable_upload( non_empty_processed: processing.Upload, internal_example_user_metadata, monkeypatch, - test_user, + user1, ): """ Creates a published upload which can be used with Upload.publish_externally. Some monkeypatching @@ -195,14 +195,14 @@ def oasis_publishable_upload( monkeypatch.setattr('requests.post', new_post) monkeypatch.setattr('nomad.config.oasis.is_oasis', True) - monkeypatch.setattr('nomad.config.keycloak.username', test_user.username) + monkeypatch.setattr('nomad.config.keycloak.username', user1.username) monkeypatch.setattr('nomad.config.oasis.central_nomad_deployment_url', '/api') # create a dataset to also test this aspect of oasis uploads entry = non_empty_processed.successful_entries[0] datamodel.Dataset( - dataset_id='dataset_id', dataset_name='dataset_name', user_id=test_user.user_id + dataset_id='dataset_id', dataset_name='dataset_name', user_id=user1.user_id ).a_mongo.save() entry.datasets = ['dataset_id'] entry.save() @@ -212,18 +212,18 @@ def oasis_publishable_upload( @pytest.mark.timeout(config.tests.default_timeout) @pytest.fixture(scope='function') def processed( - uploaded: Tuple[str, str], test_user: User, proc_infra, mails + uploaded: Tuple[str, str], user1: User, proc_infra, mails ) -> processing.Upload: """ - Provides a processed upload. Upload was uploaded with test_user. + Provides a processed upload. Upload was uploaded with user1. """ - return test_processing.run_processing(uploaded, test_user) + return test_processing.run_processing(uploaded, user1) @pytest.mark.timeout(config.tests.default_timeout) @pytest.fixture(scope='function') def processeds( - non_empty_example_upload: str, test_user: User, proc_infra + non_empty_example_upload: str, user1: User, proc_infra ) -> List[processing.Upload]: result: List[processing.Upload] = [] for i in range(2): @@ -232,9 +232,7 @@ def processeds( i, ) result.append( - test_processing.run_processing( - (upload_id, non_empty_example_upload), test_user - ) + test_processing.run_processing((upload_id, non_empty_example_upload), user1) ) return result @@ -243,12 +241,12 @@ def processeds( @pytest.mark.timeout(config.tests.default_timeout) @pytest.fixture(scope='function') def non_empty_processed( - non_empty_uploaded: Tuple[str, str], test_user: User, proc_infra + non_empty_uploaded: Tuple[str, str], user1: User, proc_infra ) -> processing.Upload: """ - Provides a processed upload. Upload was uploaded with test_user. + Provides a processed upload. Upload was uploaded with user1. """ - return test_processing.run_processing(non_empty_uploaded, test_user) + return test_processing.run_processing(non_empty_uploaded, user1) @pytest.mark.timeout(config.tests.default_timeout) @@ -257,7 +255,7 @@ def published( non_empty_processed: processing.Upload, internal_example_user_metadata ) -> processing.Upload: """ - Provides a processed published upload. Upload was uploaded with test_user and is embargoed. + Provides a processed published upload. Upload was uploaded with user1 and is embargoed. """ set_upload_entry_metadata(non_empty_processed, internal_example_user_metadata) non_empty_processed.publish_upload(embargo_length=12) @@ -275,7 +273,7 @@ def published_wo_user_metadata( non_empty_processed: processing.Upload, ) -> processing.Upload: """ - Provides a processed upload. Upload was uploaded with test_user. + Provides a processed upload. Upload was uploaded with user1. """ non_empty_processed.publish_upload() try: @@ -291,8 +289,8 @@ def example_data( elastic_module, raw_files_module, mongo_module, - test_user, - other_test_user, + user1, + user2, normalized, ): """ @@ -323,7 +321,7 @@ def example_data( id_empty: unpublished upload without any entries """ - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) # 6 uploads with different combinations of main_type and sub_type for main_type in ('embargo', 'unpublished'): @@ -338,8 +336,8 @@ def example_data( embargo_length = 0 upload_name = None entry_id = upload_id + '_1' - coauthors = [other_test_user.user_id] if sub_type == 'w_coauthor' else None - reviewers = [other_test_user.user_id] if sub_type == 'w_reviewer' else None + coauthors = [user2.user_id] if sub_type == 'w_coauthor' else None + reviewers = [user2.user_id] if sub_type == 'w_reviewer' else None data.create_upload( upload_id=upload_id, upload_name=upload_name, @@ -416,12 +414,12 @@ def example_data( @pytest.fixture(scope='function') def example_data_schema_python( - elastic_module, raw_files_module, mongo_module, test_user, normalized + elastic_module, raw_files_module, mongo_module, user1, normalized ): """ Contains entries that store data using a python schema. """ - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) upload_id = 'id_plugin_schema_published' date_value = datetime.now(timezone.utc) @@ -492,12 +490,12 @@ def example_data_schema_python( @pytest.fixture(scope='function') def example_data_nexus( - elastic_module, raw_files_module, mongo_module, test_user, normalized + elastic_module, raw_files_module, mongo_module, user1, normalized ): """ Contains entries that store data using a python schema. """ - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) upload_id = 'id_nexus_published' data.create_upload(upload_id=upload_id, upload_name=upload_id, published=True) @@ -535,13 +533,13 @@ def example_data_schema_yaml( no_warn, raw_files_module, mongo_module, - test_user, + user1, normalized, ): """ Contains entries that store data using a python schema. """ - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) upload_id = 'id_plugin_schema_published' date_value = datetime.now(timezone.utc) @@ -611,8 +609,8 @@ def example_data_schema_yaml( @pytest.fixture(scope='function') -def example_data_writeable(mongo_function, test_user, normalized): - data = ExampleData(main_author=test_user) +def example_data_writeable(mongo_function, user1, normalized): + data = ExampleData(main_author=user1) # one upload with one entry, published data.create_upload(upload_id='id_published_w', published=True, embargo_length=12) @@ -649,11 +647,11 @@ def example_data_writeable(mongo_function, test_user, normalized): @pytest.fixture(scope='function') -def example_datasets(mongo_function, test_user, other_test_user): +def example_datasets(mongo_function, user1, user2): dataset_specs = ( - ('test_dataset_1', test_user, None), - ('test_dataset_2', test_user, 'test_doi_2'), - ('test_dataset_3', other_test_user, None), + ('test_dataset_1', user1, None), + ('test_dataset_2', user1, 'test_doi_2'), + ('test_dataset_3', user2, None), ) datasets = [] for dataset_name, user, doi in dataset_specs: diff --git a/tests/fixtures/groups.py b/tests/fixtures/groups.py index 58144f8cbb25a48d75b72799566a4b509315db6d..e1155844ee5b4740de84587dafac642a0339dd9d 100644 --- a/tests/fixtures/groups.py +++ b/tests/fixtures/groups.py @@ -1,34 +1,41 @@ +""" +Group fixtures: +- groupO: group owned by userO without members +- groupOMN…: group owned by userO with members userM, userN, … +- special (unfinished) groups, often only partly defined +""" + import pytest from nomad.groups import UserGroup, create_user_group from nomad.utils.exampledata import ExampleData -from tests.utils import test_user_group_uuid, test_user_uuid +from tests.utils import fake_group_uuid, fake_user_uuid @pytest.fixture(scope='session') -def test_user_group_molds(): +def group_molds(): """Returns mapping from group label to field value dictionary.""" def old_group(group_id, group_name, owner, members): return dict( - group_id=test_user_group_uuid(group_id), + group_id=fake_group_uuid(group_id), group_name=group_name, - owner=test_user_uuid(owner), - members=[test_user_uuid(member) for member in members], + owner=fake_user_uuid(owner), + members=[fake_user_uuid(member) for member in members], ) def new_group(group_name, members): return dict( group_name=group_name, - members=[test_user_uuid(member) for member in members], + members=[fake_user_uuid(member) for member in members], ) return { - 'admin_owner_group': old_group(0, 'Admin Owner Group', 0, []), - 'user_owner_group': old_group(1, 'User Owner Group', 1, []), - 'other_owner_group': old_group(2, 'Other Owner Group', 2, []), - 'yet_owner_group': old_group(3, 'Yet Owner Group', 3, []), - 'mixed_group': old_group(4, 'Mixed Group', 0, [1, 2]), + 'group0': old_group(0, 'User0 Group', 0, []), + 'group1': old_group(1, 'User1 Group', 1, []), + 'group2': old_group(2, 'User2 Group', 2, []), + 'group3': old_group(3, 'User3 Group', 3, []), + 'group012': old_group(9012, 'Mixed Group', 0, [1, 2]), 'new_group': new_group('New Group', [2, 3]), 'short_name': new_group('GG', []), 'long_name': new_group('G' * 33, []), @@ -39,10 +46,8 @@ def test_user_group_molds(): @pytest.fixture(scope='session') -def convert_group_labels_to_ids(test_user_group_molds): - mapping = { - label: group.get('group_id') for label, group in test_user_group_molds.items() - } +def convert_group_labels_to_ids(group_molds): + mapping = {label: group.get('group_id') for label, group in group_molds.items()} def convert(raw): if isinstance(raw, str): @@ -60,32 +65,32 @@ def convert_group_labels_to_ids(test_user_group_molds): @pytest.fixture(scope='session') -def user_owner_group(test_user_group_molds): - return UserGroup(**test_user_group_molds['user_owner_group']) +def group1(group_molds): + return UserGroup(**group_molds['group1']) @pytest.fixture(scope='session') -def other_owner_group(test_user_group_molds): - return UserGroup(**test_user_group_molds['other_owner_group']) +def group2(group_molds): + return UserGroup(**group_molds['group2']) @pytest.fixture(scope='session') -def mixed_group(test_user_group_molds): - return UserGroup(**test_user_group_molds['mixed_group']) +def group012(group_molds): + return UserGroup(**group_molds['group012']) @pytest.fixture(scope='session') -def create_user_groups(test_user_group_molds): +def create_user_groups(group_molds): def create(): user_groups = {} for label in [ - 'admin_owner_group', - 'user_owner_group', - 'other_owner_group', - 'yet_owner_group', - 'mixed_group', + 'group0', + 'group1', + 'group2', + 'group3', + 'group012', ]: - group = test_user_group_molds[label] + group = group_molds[label] user_group = create_user_group(**group) user_groups[label] = user_group @@ -126,14 +131,14 @@ def fill_group_data(convert_group_labels_to_ids): @pytest.fixture(scope='module') def example_data_groups( - elastic_module, mongo_module, user_groups_module, test_user, fill_group_data + elastic_module, mongo_module, user_groups_module, user1, fill_group_data ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) fill_group_data(data, 'no_group', [], []) - fill_group_data(data, 'coauthor_other', ['other_owner_group'], []) - fill_group_data(data, 'reviewer_other', [], ['other_owner_group']) - fill_group_data(data, 'coauthor_mixed', ['mixed_group'], []) - fill_group_data(data, 'reviewer_mixed', [], ['mixed_group']) + fill_group_data(data, 'coauthor_group2', ['group2'], []) + fill_group_data(data, 'reviewer_group2', [], ['group2']) + fill_group_data(data, 'coauthor_group012', ['group012'], []) + fill_group_data(data, 'reviewer_group012', [], ['group012']) fill_group_data(data, 'reviewer_all', [], ['all']) data.save(with_files=False) @@ -144,8 +149,8 @@ def example_data_groups( @pytest.fixture(scope='function') -def upload_no_group(mongo_function, test_user): - data = ExampleData(main_author=test_user) +def upload_no_group(mongo_function, user1): + data = ExampleData(main_author=user1) data.create_upload(upload_id='id_no_group') data.save() @@ -155,16 +160,16 @@ def upload_no_group(mongo_function, test_user): @pytest.fixture(scope='function') -def upload_coauthor_other_and_mixed_group( +def upload_coauthor_group2_and_group012( mongo_function, - test_user, - other_owner_group, - mixed_group, + user1, + group2, + group012, ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload( upload_id='id_coauthor_ogroup_mgroup', - coauthor_groups=[other_owner_group.group_id, mixed_group.group_id], + coauthor_groups=[group2.group_id, group012.group_id], ) data.save() @@ -174,8 +179,8 @@ def upload_coauthor_other_and_mixed_group( @pytest.fixture(scope='function') -def upload_reviewer_all_group(mongo_function, test_user): - data = ExampleData(main_author=test_user) +def upload_reviewer_all_group(mongo_function, user1): + data = ExampleData(main_author=user1) data.create_upload(upload_id='id_reviewer_all', reviewer_groups=['all']) data.save() diff --git a/tests/fixtures/users.py b/tests/fixtures/users.py index 43a5b7a52ef8a6243a2c96489569dd71f5818c78..6c97444f2877b54ab647da0d6b3331bb624e53e9 100644 --- a/tests/fixtures/users.py +++ b/tests/fixtures/users.py @@ -1,77 +1,79 @@ +""" +User fixtures: +- user0: admin user +- user1: default user to use +- user2, user3: additional users for access or interaction tests +""" + import pytest from nomad import infrastructure from nomad.config import config from nomad.datamodel import User -from tests.utils import test_user_uuid +from tests.utils import fake_user_uuid -admin_user_id = test_user_uuid(0) +admin_user_id = fake_user_uuid(0) -test_users = { - test_user_uuid(0): dict(username='admin', email='admin', user_id=test_user_uuid(0)), - test_user_uuid(1): dict( +users = { + fake_user_uuid(0): dict(username='admin', email='admin', user_id=fake_user_uuid(0)), + fake_user_uuid(1): dict( username='scooper', email='sheldon.cooper@nomad-coe.eu', first_name='Sheldon', last_name='Cooper', - user_id=test_user_uuid(1), + user_id=fake_user_uuid(1), is_oasis_admin=True, ), - test_user_uuid(2): dict( + fake_user_uuid(2): dict( username='lhofstadter', email='leonard.hofstadter@nomad-fairdi.tests.de', first_name='Leonard', last_name='Hofstadter', - user_id=test_user_uuid(2), + user_id=fake_user_uuid(2), ), - test_user_uuid(3): dict( + fake_user_uuid(3): dict( username='hwolowitz', email='howard.wolowitz@nomad-fairdi.tests.de', first_name='Howard', last_name='Wolowitz', - user_id=test_user_uuid(3), + user_id=fake_user_uuid(3), ), } @pytest.fixture(scope='session') -def test_user_molds(): - label_num = { - 'admin_user': 0, - 'test_user': 1, - 'other_test_user': 2, - 'yet_test_user': 3, - } - return {label: test_users[test_user_uuid(num)] for label, num in label_num.items()} +def user_molds(): + label_num = {f'user{i}': i for i in range(4)} + return {label: users[fake_user_uuid(num)] for label, num in label_num.items()} @pytest.fixture(scope='session') -def admin_user(): - return User(**test_users[test_user_uuid(0)]) +def user0(): + return User(**users[fake_user_uuid(0)]) @pytest.fixture(scope='session') -def test_user(): - return User(**test_users[test_user_uuid(1)]) +def user1(): + return User(**users[fake_user_uuid(1)]) @pytest.fixture(scope='session') -def other_test_user(): - return User(**test_users[test_user_uuid(2)]) +def user2(): + return User(**users[fake_user_uuid(2)]) @pytest.fixture(scope='session') -def yet_test_user(): - return User(**test_users[test_user_uuid(3)]) +def user3(): + return User(**users[fake_user_uuid(3)]) @pytest.fixture(scope='session') -def test_users_dict(test_user, other_test_user, admin_user, yet_test_user): +def users_dict(user0, user1, user2, user3): return { - 'admin_user': admin_user, - 'test_user': test_user, - 'other_test_user': other_test_user, - 'yet_test_user': yet_test_user, + 'user0': user0, + 'user1': user1, + 'user2': user2, + 'user3': user3, } @@ -83,7 +85,7 @@ def configure_admin_user_id(monkeysession): class KeycloakMock: def __init__(self): self.id_counter = 3 - self.users = dict(**test_users) + self.users = dict(**users) def tokenauth(self, access_token: str): if access_token in self.users: @@ -93,7 +95,7 @@ class KeycloakMock: def add_user(self, user, *args, **kwargs): self.id_counter += 1 - user.user_id = test_user_uuid(self.id_counter) + user.user_id = fake_user_uuid(self.id_counter) user.username = (user.first_name[0] + user.last_name).lower() self.users[user.user_id] = dict( email=user.email, @@ -121,9 +123,9 @@ class KeycloakMock: def search_user(self, query): return [ - User(**test_user) - for test_user in self.users.values() - if query in ' '.join([str(value) for value in test_user.values()]) + User(**user) + for user in self.users.values() + if query in ' '.join([str(value) for value in user.values()]) ] def basicauth(self, username: str, password: str) -> str: diff --git a/tests/graph/test_graph_reader.py b/tests/graph/test_graph_reader.py index 92e2f7f7d1d718db080abf4061ffb38a15f5d3fa..a549744f4edffc5f553990dc1fe917876bab3e45 100644 --- a/tests/graph/test_graph_reader.py +++ b/tests/graph/test_graph_reader.py @@ -98,7 +98,7 @@ user_dict = { # noinspection SpellCheckingInspection,DuplicatedCode -def test_remote_reference(json_dict, example_data_with_reference, test_user): +def test_remote_reference(json_dict, example_data_with_reference, user1): def increment(): n = 0 while True: @@ -108,14 +108,14 @@ def test_remote_reference(json_dict, example_data_with_reference, test_user): counter = increment() def __user_print(msg, required, *, result: dict = None): - with UserReader(required, user=test_user) as reader: + with UserReader(required, user=user1) as reader: if result: - assert_dict(reader.read(test_user.user_id), result) + assert_dict(reader.read(user1.user_id), result) else: rprint(f'\n\nExample: {next(counter)} -> {msg}:') rprint(required) rprint('output:') - rprint(reader.read(test_user.user_id)) + rprint(reader.read(user1.user_id)) __user_print( 'plain user', @@ -831,7 +831,7 @@ def test_remote_reference(json_dict, example_data_with_reference, test_user): ) def __upload_print(msg, required, *, result: dict = None): - with UploadReader(required, user=test_user) as reader: + with UploadReader(required, user=user1) as reader: if result: assert_dict(reader.read('id_published_with_ref'), result) else: @@ -1246,7 +1246,7 @@ def test_remote_reference(json_dict, example_data_with_reference, test_user): ) def __entry_print(msg, required, *, to_file: bool = False, result: dict = None): - with EntryReader(required, user=test_user) as reader: + with EntryReader(required, user=user1) as reader: if result: assert_dict(reader.read('id_03'), result) else: @@ -1617,7 +1617,7 @@ def test_remote_reference(json_dict, example_data_with_reference, test_user): ) def __fs_print(msg, required, *, result: dict = None): - with FileSystemReader(required, user=test_user) as reader: + with FileSystemReader(required, user=user1) as reader: if result: assert_dict(reader.read('id_published_with_ref'), result) else: @@ -2081,7 +2081,7 @@ def test_remote_reference(json_dict, example_data_with_reference, test_user): # noinspection DuplicatedCode,SpellCheckingInspection -def test_general_reader(json_dict, example_data_with_reference, test_user): +def test_general_reader(json_dict, example_data_with_reference, user1): def increment(): n = 0 while True: @@ -2091,7 +2091,7 @@ def test_general_reader(json_dict, example_data_with_reference, test_user): counter = increment() def __ge_print(msg, required, *, to_file: bool = False, result: dict = None): - with MongoReader(required, user=test_user) as reader: + with MongoReader(required, user=user1) as reader: if result: assert_dict(reader.read(), result) else: @@ -2454,7 +2454,7 @@ def test_general_reader(json_dict, example_data_with_reference, test_user): # noinspection DuplicatedCode,SpellCheckingInspection -def test_general_reader_search(json_dict, example_data_with_reference, test_user): +def test_general_reader_search(json_dict, example_data_with_reference, user1): def increment(): n = 0 while True: @@ -2464,7 +2464,7 @@ def test_general_reader_search(json_dict, example_data_with_reference, test_user counter = increment() def __ge_print(msg, required, *, to_file: bool = False, result: dict = None): - with MongoReader(required, user=test_user) as reader: + with MongoReader(required, user=user1) as reader: if result: assert_dict(reader.read(), result) else: @@ -2555,7 +2555,7 @@ def test_general_reader_search(json_dict, example_data_with_reference, test_user @pytest.fixture(scope='function') -def custom_data(test_user, proc_infra): +def custom_data(user1, proc_infra): yaml_archive = yaml.safe_load( """ --- @@ -2585,7 +2585,7 @@ data: """ ) archive = EntryArchive.m_from_dict(yaml_archive) - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload( upload_id='id_custom', upload_name='name_published', published=True @@ -2600,7 +2600,7 @@ data: data.delete() -def test_custom_schema_archive_and_definition(test_user, custom_data): +def test_custom_schema_archive_and_definition(user1, custom_data): def increment(): n = 0 while True: @@ -2610,7 +2610,7 @@ def test_custom_schema_archive_and_definition(test_user, custom_data): counter = increment() def __entry_print(msg, required, *, to_file: bool = False, result: dict = None): - with EntryReader(required, user=test_user) as reader: + with EntryReader(required, user=user1) as reader: response = reader.read('id_example') if result: assert_dict(response, result) @@ -2712,14 +2712,14 @@ def test_custom_schema_archive_and_definition(test_user, custom_data): @pytest.fixture(scope='function') def example_data_with_reference( - elastic_function, raw_files_module, mongo_function, test_user, json_dict + elastic_function, raw_files_module, mongo_function, user1, json_dict ): """ Provides a couple of entries with references. Only used in test_required_reader_with_remote_reference. """ - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload( upload_id='id_published_with_ref', upload_name='name_published', published=False diff --git a/tests/metainfo/test_elasticsearch_extension.py b/tests/metainfo/test_elasticsearch_extension.py index 8447634d22602227c79e2edafad65717037a330a..082a1125d657fd39ca89b52715f338c9c85081a8 100644 --- a/tests/metainfo/test_elasticsearch_extension.py +++ b/tests/metainfo/test_elasticsearch_extension.py @@ -45,11 +45,11 @@ def example_data_normalizers( elastic_module, raw_files_module, mongo_module, - test_user, - other_test_user, + user1, + user2, normalized, ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) upload_id = 'normalizer_upload' data.create_upload(upload_id=upload_id, published=True) @@ -76,11 +76,11 @@ def example_data_large_keyword( elastic_module, raw_files_module, mongo_module, - test_user, - other_test_user, + user1, + user2, normalized, ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) upload_id = 'id_search_quantities_index' data.create_upload(upload_id=upload_id, upload_name=upload_id, published=True) diff --git a/tests/parsing/test_chemotion_parser.py b/tests/parsing/test_chemotion_parser.py index 117ff3634c60588f50303641e494246e292f8e80..7854780bc9f3b7044e8784be14be399195c2542e 100644 --- a/tests/parsing/test_chemotion_parser.py +++ b/tests/parsing/test_chemotion_parser.py @@ -59,9 +59,9 @@ def _assert_chemotion(test_archive): @pytest.mark.timeout(config.tests.default_timeout) -def test_chemotion_parser(raw_files_function, proc_infra, api_v1, test_user): +def test_chemotion_parser(raw_files_function, proc_infra, api_v1, user1): upload = run_processing( - ('test_upload', 'tests/data/parsers/chemotion/test.zip'), test_user + ('test_upload', 'tests/data/parsers/chemotion/test.zip'), user1 ) assert upload.total_entries_count == 2 diff --git a/tests/parsing/test_elabftw_parser.py b/tests/parsing/test_elabftw_parser.py index 73fd66d0ac44db8572adf82cf144cf1b6df7dfae..dd729ef028dd3e831fb607b0e1ec8324bb24b88b 100644 --- a/tests/parsing/test_elabftw_parser.py +++ b/tests/parsing/test_elabftw_parser.py @@ -80,9 +80,9 @@ def _assert_elabftw(test_archive): @pytest.mark.timeout(config.tests.default_timeout) -def test_elabftw_parser(raw_files_function, proc_infra, api_v1, test_user): +def test_elabftw_parser(raw_files_function, proc_infra, api_v1, user1): upload = run_processing( - ('test_upload', 'tests/data/parsers/elabftw/test.eln'), test_user + ('test_upload', 'tests/data/parsers/elabftw/test.eln'), user1 ) assert upload.total_entries_count == 2 diff --git a/tests/parsing/test_tabular.py b/tests/parsing/test_tabular.py index f9b9cb75c514185b9f3bf26c5d6b222dc0264237..8f746bbd81b5026f4f299377375498fe2ecd446f 100644 --- a/tests/parsing/test_tabular.py +++ b/tests/parsing/test_tabular.py @@ -339,9 +339,9 @@ def test_tabular_complex_schema(raw_files_function, monkeypatch, schema): def test_tabular_entry_mode( - mongo_function, test_user, raw_files_function, monkeypatch, proc_infra + mongo_function, user1, raw_files_function, monkeypatch, proc_infra ): - upload = Upload(upload_id='test_upload_id', main_author=test_user.user_id) + upload = Upload(upload_id='test_upload_id', main_author=user1.user_id) upload.save() files.StagingUploadFiles(upload_id=upload.upload_id, create=True) upload.staging_upload_files.add_rawfiles('tests/data/parsers/tabular/') diff --git a/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py b/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py index 93b7b7265d6fd74a270db34441cdd5fe999da131..ac9ee8d9cb9ff50c91b8be8b91f4ef8accb5bd6a 100644 --- a/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py +++ b/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py @@ -23,12 +23,12 @@ from nomad.utils.exampledata import ExampleData def test_perovskite_solar_cell_plugin_processing( - raw_files_function, no_warn, test_user, mongo_function + raw_files_function, no_warn, user1, mongo_function ): directory = 'tests/data/plugins/perovskite_solar_cell_database' mainfile = 'example.archive.json' upload_id = 'test_upload_id' - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id=upload_id, published=False) context = ClientContext(local_dir=directory, upload_id=upload_id) diff --git a/tests/processing/test_data.py b/tests/processing/test_data.py index 729f600599466708d0bdf82be4c3342375dc1ad9..e0a70ef1cb962c3a77782a6235f6050f0d21fa29 100644 --- a/tests/processing/test_data.py +++ b/tests/processing/test_data.py @@ -260,27 +260,21 @@ def test_processing(processed, no_warn, mails, monkeypatch): @pytest.mark.timeout(config.tests.default_timeout) -def test_processing_two_runs(test_user, proc_infra, tmp): +def test_processing_two_runs(user1, proc_infra, tmp): upload_file = create_template_upload_file( tmp, mainfiles=['tests/data/proc/templates/template_tworuns.json'] ) - processed = run_processing( - ( - 'test_upload_id', - upload_file, - ), - test_user, - ) + processed = run_processing(('test_upload_id', upload_file), user1) assert_processing(processed) @pytest.mark.timeout(config.tests.default_timeout) -def test_processing_with_large_dir(test_user, proc_infra, tmp): +def test_processing_with_large_dir(user1, proc_infra, tmp): upload_path = create_template_upload_file( tmp, mainfiles=['tests/data/proc/templates/template.json'], auxfiles=150 ) upload_id = upload_path[:-4] - upload = run_processing((upload_id, upload_path), test_user) + upload = run_processing((upload_id, upload_path), user1) for entry in upload.successful_entries: assert len(entry.warnings) == 1 @@ -315,10 +309,8 @@ def test_publish( @pytest.mark.timeout(config.tests.default_timeout) -def test_publish_directly( - non_empty_uploaded, test_user, proc_infra, no_warn, monkeypatch -): - processed = run_processing(non_empty_uploaded, test_user, publish_directly=True) +def test_publish_directly(non_empty_uploaded, user1, proc_infra, no_warn, monkeypatch): + processed = run_processing(non_empty_uploaded, user1, publish_directly=True) with processed.entries_metadata() as entries: assert_upload_files( @@ -359,13 +351,13 @@ def test_republish( def test_publish_failed( non_empty_uploaded: Tuple[str, str], internal_example_user_metadata, - test_user, + user1, monkeypatch, proc_infra, ): mock_failure(Entry, 'parsing', monkeypatch) - processed = run_processing(non_empty_uploaded, test_user) + processed = run_processing(non_empty_uploaded, user1) set_upload_entry_metadata(processed, internal_example_user_metadata) additional_keys = ['with_embargo'] @@ -400,7 +392,7 @@ def test_publish_to_central_nomad( proc_infra, monkeypatch, oasis_publishable_upload, - test_user, + user1, no_warn, import_settings, embargo_length, @@ -458,19 +450,19 @@ def test_publish_to_central_nomad( @pytest.mark.timeout(config.tests.default_timeout) -def test_processing_with_warning(proc_infra, test_user, with_warn, tmp): +def test_processing_with_warning(proc_infra, user1, with_warn, tmp): example_file = create_template_upload_file( tmp, 'tests/data/proc/templates/with_warning_template.json' ) example_upload_id = os.path.basename(example_file).replace('.zip', '') - upload = run_processing((example_upload_id, example_file), test_user) + upload = run_processing((example_upload_id, example_file), user1) assert_processing(upload) @pytest.mark.timeout(config.tests.default_timeout) -def test_process_non_existing(proc_infra, test_user, with_error): - upload = run_processing(('__does_not_exist', '__does_not_exist'), test_user) +def test_process_non_existing(proc_infra, user1, with_error): + upload = run_processing(('__does_not_exist', '__does_not_exist'), user1) assert not upload.process_running assert upload.process_status == ProcessStatus.FAILURE @@ -667,7 +659,7 @@ def test_re_process_match(non_empty_processed, published, monkeypatch, no_warn): @pytest.mark.parametrize('reuse_parser', [False, True]) -def test_reuse_parser(monkeypatch, tmp, test_user, proc_infra, reuse_parser, no_warn): +def test_reuse_parser(monkeypatch, tmp, user1, proc_infra, reuse_parser, no_warn): upload_path = os.path.join(tmp, 'example_upload.zip') with zipfile.ZipFile(upload_path, 'w') as zf: zf.write('tests/data/parsers/vasp/vasp.xml', 'one/run.vasp.xml') @@ -679,7 +671,7 @@ def test_reuse_parser(monkeypatch, tmp, test_user, proc_infra, reuse_parser, no_ 'example_upload', upload_path, ), - test_user, + user1, ) assert upload.total_entries_count == 2 @@ -891,7 +883,7 @@ def mock_failure(cls, function_name, monkeypatch): ) @pytest.mark.timeout(config.tests.default_timeout) def test_process_failure( - monkeypatch, uploaded, function, proc_infra, test_user, with_error + monkeypatch, uploaded, function, proc_infra, user1, with_error ): upload_id, _ = uploaded # mock the function to throw exceptions @@ -905,7 +897,7 @@ def test_process_failure( mock_failure(cls, function, monkeypatch) # run the test - upload = run_processing(uploaded, test_user) + upload = run_processing(uploaded, user1) assert not upload.process_running @@ -936,14 +928,14 @@ def test_process_failure( # consume_ram, segfault, and exit are not testable with the celery test worker @pytest.mark.parametrize('failure', ['exception']) -def test_malicious_parser_failure(proc_infra, failure, test_user, tmp): +def test_malicious_parser_failure(proc_infra, failure, user1, tmp): example_file = os.path.join(tmp, 'upload.zip') with zipfile.ZipFile(example_file, mode='w') as zf: with zf.open('chaos.json', 'w') as f: f.write(f'"{failure}"'.encode()) example_upload_id = f'chaos_{failure}' - upload = run_processing((example_upload_id, example_file), test_user) + upload = run_processing((example_upload_id, example_file), user1) assert not upload.process_running assert len(upload.errors) == 0 @@ -957,7 +949,7 @@ def test_malicious_parser_failure(proc_infra, failure, test_user, tmp): assert len(entry.errors) == 1 -def test_parent_child_parser(proc_infra, test_user, tmp): +def test_parent_child_parser(proc_infra, user1, tmp): # Create a dummy parser which creates child entries class ParentChildParser(Parser): name = 'parsers/parentchild' @@ -1005,7 +997,7 @@ def test_parent_child_parser(proc_infra, test_user, tmp): with open(example_filepath, 'w') as f: f.write('\n'.join(['parentchild', *children])) - upload = run_processing((example_upload_id, example_filepath), test_user) + upload = run_processing((example_upload_id, example_filepath), user1) assert upload.process_status == ProcessStatus.SUCCESS assert upload.total_entries_count == len(children) + 1 @@ -1023,12 +1015,12 @@ def test_parent_child_parser(proc_infra, test_user, tmp): @pytest.mark.timeout(config.tests.default_timeout) -def test_creating_new_entries_during_processing(proc_infra, test_user): +def test_creating_new_entries_during_processing(proc_infra, user1): """ Tests a use-case where a schema has a normalizer that adds new mainfiles during processing. """ upload_id = 'test_create_during_processing' - upload = Upload.create(upload_id=upload_id, main_author=test_user) + upload = Upload.create(upload_id=upload_id, main_author=user1) upload_files = StagingUploadFiles(upload_id, create=True) with upload_files.raw_file('batch.archive.json', 'w') as outfile: json.dump( @@ -1056,9 +1048,9 @@ def test_creating_new_entries_during_processing(proc_infra, test_user): @pytest.mark.timeout(config.tests.default_timeout) -def test_ems_data(proc_infra, test_user): +def test_ems_data(proc_infra, user1): upload = run_processing( - ('test_ems_upload', 'tests/data/proc/examples_ems.zip'), test_user + ('test_ems_upload', 'tests/data/proc/examples_ems.zip'), user1 ) additional_keys = ['results.method.method_name', 'results.material.elements'] @@ -1073,9 +1065,9 @@ def test_ems_data(proc_infra, test_user): @pytest.mark.timeout(config.tests.default_timeout) -def test_qcms_data(proc_infra, test_user): +def test_qcms_data(proc_infra, user1): upload = run_processing( - ('test_qcms_upload', 'tests/data/proc/examples_qcms.zip'), test_user + ('test_qcms_upload', 'tests/data/proc/examples_qcms.zip'), user1 ) additional_keys = [ @@ -1093,9 +1085,9 @@ def test_qcms_data(proc_infra, test_user): @pytest.mark.timeout(config.tests.default_timeout) -def test_phonopy_data(proc_infra, test_user): +def test_phonopy_data(proc_infra, user1): upload = run_processing( - ('test_upload', 'tests/data/proc/examples_phonopy.zip'), test_user + ('test_upload', 'tests/data/proc/examples_phonopy.zip'), user1 ) additional_keys = ['results.method.simulation.program_name'] @@ -1109,7 +1101,7 @@ def test_phonopy_data(proc_infra, test_user): assert_search_upload(entries, additional_keys, published=False) -def test_read_metadata_from_file(proc_infra, test_user, other_test_user, tmp): +def test_read_metadata_from_file(proc_infra, user1, user2, tmp): upload_file = os.path.join(tmp, 'upload.zip') with zipfile.ZipFile(upload_file, 'w') as zf: zf.write( @@ -1138,7 +1130,7 @@ def test_read_metadata_from_file(proc_infra, test_user, other_test_user, tmp): f.write(json.dumps(entry_2).encode()) metadata = { 'upload_name': 'my name', - 'coauthors': other_test_user.user_id, + 'coauthors': user2.user_id, 'references': ['http://test0.com'], 'entries': { 'examples/entry_3/template.json': { @@ -1152,7 +1144,7 @@ def test_read_metadata_from_file(proc_infra, test_user, other_test_user, tmp): with zf.open('nomad.json', 'w') as f: f.write(json.dumps(metadata).encode()) - upload = run_processing(('test_upload', upload_file), test_user) + upload = run_processing(('test_upload', upload_file), user1) entries = Entry.objects(upload_id=upload.upload_id) entries = sorted(entries, key=lambda entry: entry.mainfile) @@ -1165,7 +1157,7 @@ def test_read_metadata_from_file(proc_infra, test_user, other_test_user, tmp): ['http://test3.com'], ['http://test0.com'], ] - expected_coauthors = [other_test_user] + expected_coauthors = [user2] for i in range(len(entries)): entry_metadata = entries[i].full_entry_metadata(upload) @@ -1182,9 +1174,9 @@ def test_read_metadata_from_file(proc_infra, test_user, other_test_user, tmp): assert coauthors[j].last_name == expected_coauthors[j].last_name -def test_skip_matching(proc_infra, test_user): +def test_skip_matching(proc_infra, user1): upload = run_processing( - ('test_skip_matching', 'tests/data/proc/skip_matching.zip'), test_user + ('test_skip_matching', 'tests/data/proc/skip_matching.zip'), user1 ) assert upload.total_entries_count == 1 @@ -1203,13 +1195,13 @@ def test_skip_matching(proc_infra, test_user): ], ) def test_upload_context( - raw_files_function, mongo_function, test_user, url, normalized_url, monkeypatch + raw_files_function, mongo_function, user1, url, normalized_url, monkeypatch ): monkeypatch.setattr( 'nomad.utils.generate_entry_id', lambda *args, **kwargs: 'test_id' ) - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id='test_id', published=True) referenced_archive = EntryArchive(data=TestData()) diff --git a/tests/processing/test_edit_metadata.py b/tests/processing/test_edit_metadata.py index c258070b4be5c4d836583d4bc962f6cc4bf7520e..eca6c88969f22060e537ce473c6cd59f48d911ee 100644 --- a/tests/processing/test_edit_metadata.py +++ b/tests/processing/test_edit_metadata.py @@ -308,22 +308,20 @@ def test_edit_metadata( purged_app, example_data_writeable, example_datasets, - test_users_dict, + users_dict, kwargs, ): - kwargs['user'] = test_users_dict[kwargs.get('user', 'test_user')] + kwargs['user'] = users_dict[kwargs.get('user', 'user1')] assert_edit_request(**kwargs) -def test_set_and_clear_all( - proc_infra, example_data_writeable, example_datasets, test_user -): +def test_set_and_clear_all(proc_infra, example_data_writeable, example_datasets, user1): # Set all fields a coauthor can set - assert_edit_request(user=test_user, metadata=all_coauthor_metadata) + assert_edit_request(user=user1, metadata=all_coauthor_metadata) # Clear all fields that can be cleared with a 'set' operation # = all of the above, except embargo_length and datasets assert_edit_request( - user=test_user, + user=user1, metadata=dict( upload_name='', coauthors=[], @@ -523,7 +521,7 @@ def test_list_quantities( purged_app, example_data_writeable, example_datasets, - test_users_dict, + users_dict, kwargs, ): def replace_dataset_ref(dataset_ref): @@ -538,7 +536,7 @@ def test_list_quantities( return [replace_dataset_ref(ref) for ref in ref_or_reflist] return replace_dataset_ref(ref_or_reflist) - kwargs['user'] = test_users_dict[kwargs.get('user', 'test_user')] + kwargs['user'] = users_dict[kwargs.get('user', 'user1')] for suffix in ('_1', '_2'): for arg in ('metadata', 'expected_metadata', 'expected_error_loc'): if arg in kwargs: @@ -557,16 +555,14 @@ def test_list_quantities( assert_edit_request(**kwargs) -def test_admin_quantities( - proc_infra, example_data_writeable, test_user, other_test_user, admin_user -): +def test_admin_quantities(proc_infra, example_data_writeable, user1, user2, user0): assert_edit_request( - user=admin_user, upload_id='id_published_w', metadata=all_admin_metadata + user=user0, upload_id='id_published_w', metadata=all_admin_metadata ) # try to do the same as a non-admin for k, v in all_admin_metadata.items(): assert_edit_request( - user=test_user, + user=user1, upload_id='id_unpublished_w', metadata={k: v}, expected_error_loc=('metadata', k), @@ -574,7 +570,7 @@ def test_admin_quantities( def test_query_cannot_set_upload_attributes( - proc_infra, example_data_writeable, example_datasets, test_user + proc_infra, example_data_writeable, example_datasets, user1 ): query = {'and': [{'upload_create_time:gt': '2021-01-01'}, {'published': False}]} for k, v in all_coauthor_upload_metadata.items(): @@ -582,7 +578,7 @@ def test_query_cannot_set_upload_attributes( # regardless of if upload_id is specified for upload_id in (None, 'id_unpublished_w'): assert_edit_request( - user=test_user, + user=user1, query=query, owner='user', upload_id=upload_id, @@ -591,7 +587,7 @@ def test_query_cannot_set_upload_attributes( ) # Attempting to edit an entry level attribute with query should always succeed assert_edit_request( - user=test_user, + user=user1, query=query, owner='user', upload_id=None, diff --git a/tests/test_cli.py b/tests/test_cli.py index 9f63fa8e352a1269cf4512b9d9c5cd3c779ef069..3f03dca458c8dd7a902b0b9f4e1c918e95ed20e5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -305,16 +305,16 @@ class TestAdminUploads: published.reload() assert published.process_status == ProcessStatus.SUCCESS - def test_chown(self, published: Upload, test_user, other_test_user): + def test_chown(self, published: Upload, user1, user2): upload_id = published.upload_id - assert published.main_author == test_user.user_id + assert published.main_author == user1.user_id with published.entries_metadata() as entries_metadata: for entry_metadata in entries_metadata: - assert entry_metadata.main_author.user_id == test_user.user_id + assert entry_metadata.main_author.user_id == user1.user_id result = invoke_cli( cli, - ['admin', 'uploads', 'chown', other_test_user.username, upload_id], + ['admin', 'uploads', 'chown', user2.username, upload_id], catch_exceptions=False, ) @@ -323,10 +323,10 @@ class TestAdminUploads: published.block_until_complete() - assert published.main_author == other_test_user.user_id + assert published.main_author == user2.user_id with published.entries_metadata() as entries_metadata: for entry_metadata in entries_metadata: - assert entry_metadata.main_author.user_id == other_test_user.user_id + assert entry_metadata.main_author.user_id == user2.user_id @pytest.mark.parametrize( 'with_entries,success,failure', @@ -373,9 +373,9 @@ class TestAdminUploads: @pytest.mark.parametrize('indexed', [True, False]) def test_integrity_entry_index( - self, test_user, mongo_function, elastic_function, indexed + self, user1, mongo_function, elastic_function, indexed ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id='test_upload') data.create_entry(upload_id='test_upload') data.save(with_es=indexed, with_files=False) @@ -391,14 +391,14 @@ class TestAdminUploads: @pytest.mark.usefixtures('reset_config') class TestClient: def test_upload( - self, non_empty_example_upload, admin_user, proc_infra, client_with_api_v1 + self, non_empty_example_upload, user0, proc_infra, client_with_api_v1 ): result = invoke_cli( cli, [ 'client', '-u', - admin_user.username, + user0.username, '--token-via-api', 'upload', '--upload-name', diff --git a/tests/test_client.py b/tests/test_client.py index 5bca18a42264e21dc038e466b048b3a87afdba5e..a12dc1f9e4da3cfafc9f68f2db9366949d8171c5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -26,7 +26,7 @@ from nomad.client.archive import ArchiveQuery from nomad.datamodel import EntryArchive, User from nomad.datamodel.metainfo import runschema, SCHEMA_IMPORT_ERROR from nomad.metainfo import MSection, SubSection -from tests.fixtures.users import test_users +from tests.fixtures.users import users from tests.processing import test_data as test_processing @@ -54,11 +54,11 @@ def assert_results( @pytest.fixture(scope='function') -def many_uploads(non_empty_uploaded: Tuple[str, str], test_user: User, proc_infra): +def many_uploads(non_empty_uploaded: Tuple[str, str], user1: User, proc_infra): _, upload_file = non_empty_uploaded for index in range(0, 4): upload = test_processing.run_processing( - ('test_upload_%d' % index, upload_file), test_user + ('test_upload_%d' % index, upload_file), user1 ) upload.publish_upload() # pylint: disable=no-member try: @@ -90,7 +90,7 @@ def async_api_v1(monkeysession): monkeysession.setattr('httpx.AsyncClient.delete', getattr(test_client, 'delete')) def mocked_auth_headers(self) -> dict: - for user in test_users.values(): + for user in users.values(): if user['username'] == self.user or user['email'] == self.user: return dict(Authorization=f'Bearer {user["user_id"]}') return {} @@ -129,12 +129,12 @@ def test_async_query_required( assert_results(async_query.download(), sub_section_defs=sub_sections) -def test_async_query_auth(async_api_v1, published, other_test_user, test_user): - async_query = ArchiveQuery(username=other_test_user.username, password='password') +def test_async_query_auth(async_api_v1, published, user2, user1): + async_query = ArchiveQuery(username=user2.username, password='password') assert_results(async_query.download(), total=0) - async_query = ArchiveQuery(username=test_user.username, password='password') + async_query = ArchiveQuery(username=user1.username, password='password') assert_results(async_query.download(), total=1) diff --git a/tests/test_doi.py b/tests/test_doi.py index 33958cc5149e4cceee17dd79d474a0c37dd9b8dd..60498040f7d707584a64bc152bcaf5729b268f54 100644 --- a/tests/test_doi.py +++ b/tests/test_doi.py @@ -21,22 +21,22 @@ import pytest from unittest.mock import MagicMock -def test_create(mongo_function, test_user, no_warn): - doi = DOI.create('the_title', test_user) +def test_create(mongo_function, user1, no_warn): + doi = DOI.create('the_title', user1) assert DOI.objects(doi=doi.doi).first() is not None assert doi.metadata_xml is not None -def test_create_doi_counter(mongo_function, test_user, no_warn): - DOI.create('the_title', test_user) - doi = DOI.create('the_title', test_user) +def test_create_doi_counter(mongo_function, user1, no_warn): + DOI.create('the_title', user1) + doi = DOI.create('the_title', user1) assert doi.doi.endswith('-2') -def test_create_draft_doi(mongo_function, test_user, no_warn): +def test_create_draft_doi(mongo_function, user1, no_warn): if config.datacite.enabled: - doi = DOI.create('the_title', test_user) + doi = DOI.create('the_title', user1) doi.create_draft() doi.delete() @@ -52,7 +52,7 @@ def test_create_draft_doi(mongo_function, test_user, no_warn): ], ) def test_datacite_requests( - mongo_function, monkeypatch, test_user, status_code, response_ok, is_findable, text + mongo_function, monkeypatch, user1, status_code, response_ok, is_findable, text ): if config.datacite.enabled: @@ -63,7 +63,7 @@ def test_datacite_requests( mock_response.text = text return mock_response - doi = DOI.create('the_title', test_user) + doi = DOI.create('the_title', user1) monkeypatch.setattr( doi.create_draft.__globals__['requests'], 'post', mock_datacite_request diff --git a/tests/test_infrastructure.py b/tests/test_infrastructure.py index 17b49bb70998f404ef9eef1c3062553958620aa7..213a6c93c20c91bf077f0191ca896de7fafdb25b 100644 --- a/tests/test_infrastructure.py +++ b/tests/test_infrastructure.py @@ -19,7 +19,7 @@ import pytest from nomad.infrastructure import UserManagement -from tests.fixtures.users import test_user_uuid as create_test_user_uuid +from tests.fixtures.users import fake_user_uuid @pytest.fixture(scope='function') @@ -46,7 +46,7 @@ def test_search_user(user_management: UserManagement, query, count): [ pytest.param('username', 'scooper', id='username'), pytest.param('email', 'sheldon.cooper@nomad-coe.eu', id='email'), - pytest.param('user_id', create_test_user_uuid(1), id='user_id'), + pytest.param('user_id', fake_user_uuid(1), id='user_id'), ], ) def test_get_user(user_management: UserManagement, key, value): diff --git a/tests/test_search.py b/tests/test_search.py index 19d28243f4136b60bbc1e299ca308cbcb313e292..ed59ddeb08f0622b8b3cf79793bfedda07c29232 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -51,9 +51,6 @@ from nomad.utils.exampledata import ExampleData from tests.config import yaml_schema_name, python_schema_name -other_groups = ['other_owner_group', 'mixed_group'] - - def split(path): return [int(x) if x.isdigit() else x for x in path.split('.')] @@ -167,8 +164,8 @@ def get_schema_quantity(type, quantity): @pytest.fixture() -def example_data(elastic_function, test_user): - data = ExampleData(main_author=test_user) +def example_data(elastic_function, user1): + data = ExampleData(main_author=user1) data.create_upload(upload_id='test_upload_id', published=True, embargo_length=12) for i in range(0, 4): data.create_entry( @@ -182,20 +179,20 @@ def example_data(elastic_function, test_user): @pytest.fixture(scope='class') def example_group_data( - elastic_module, user_groups_module, test_user, other_test_user, fill_group_data + elastic_module, user_groups_module, user1, user2, fill_group_data ): - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) fill_group_data(data, 'no_embargo', [], [], embargo_length=0) fill_group_data(data, 'with_embargo', [], [], embargo_length=3) fill_group_data(data, 'no_group', [], []) - fill_group_data(data, 'coauthor_user', ['user_owner_group'], []) - fill_group_data(data, 'reviewer_user', [], ['user_owner_group']) - fill_group_data(data, 'coauthor_other', ['other_owner_group'], []) - fill_group_data(data, 'reviewer_other', [], ['other_owner_group']) - fill_group_data(data, 'coauthor_mixed', ['mixed_group'], []) - fill_group_data(data, 'reviewer_mixed', [], ['mixed_group']) + fill_group_data(data, 'coauthor_group1', ['group1'], []) + fill_group_data(data, 'reviewer_group1', [], ['group1']) + fill_group_data(data, 'coauthor_group2', ['group2'], []) + fill_group_data(data, 'reviewer_group2', [], ['group2']) + fill_group_data(data, 'coauthor_group012', ['group012'], []) + fill_group_data(data, 'reviewer_group012', [], ['group012']) fill_group_data(data, 'reviewer_all', [], ['all']) - fill_group_data(data, 'other_user', [], [], main_author=other_test_user) + fill_group_data(data, 'user2', [], [], main_author=user2) data.save(with_files=False, with_mongo=False) yield data @@ -204,8 +201,8 @@ def example_group_data( @pytest.fixture() -def example_text_search_data(mongo_module, elastic_function, test_user): - data = ExampleData(main_author=test_user) +def example_text_search_data(mongo_module, elastic_function, user1): + data = ExampleData(main_author=user1) data.create_upload(upload_id='test_upload_text_search', published=True) data.create_entry( upload_id='test_upload_text_search', @@ -221,7 +218,7 @@ def example_text_search_data(mongo_module, elastic_function, test_user): @pytest.fixture() -def example_eln_data(elastic_function, test_user): +def example_eln_data(elastic_function, user1): class DataSection(EntryData): text = Quantity(type=str) keyword = Quantity(type=MEnum('one', 'two')) @@ -230,7 +227,7 @@ def example_eln_data(elastic_function, test_user): date = Quantity(type=Datetime) boolean = Quantity(type=bool) - data = ExampleData(main_author=test_user) + data = ExampleData(main_author=user1) data.create_upload(upload_id='test_upload_id', published=True, embargo_length=12) parameters = [ @@ -338,37 +335,37 @@ class TestsWithGroups: 'owner, user, exc_or_total', [ pytest.param('admin', None, ARE, id='admin-none'), - pytest.param('admin', 'test_user', ARE, id='admin-user'), - pytest.param('admin', 'admin_user', 11, id='admin-admin'), + pytest.param('admin', 'user1', ARE, id='admin-user1'), + pytest.param('admin', 'user0', 11, id='admin-user0'), pytest.param('user', None, ARE, id='user-none'), - pytest.param('user', 'test_user', 10, id='user-user'), - pytest.param('user', 'other_test_user', 1, id='user-other'), + pytest.param('user', 'user1', 10, id='user-user1'), + pytest.param('user', 'user2', 1, id='user-user2'), pytest.param('shared', None, ARE, id='shared-none'), - pytest.param('shared', 'test_user', 10, id='shared-user'), - pytest.param('shared', 'other_test_user', 6, id='shared'), + pytest.param('shared', 'user1', 10, id='shared-user1'), + pytest.param('shared', 'user2', 6, id='shared'), pytest.param('staging', None, ARE, id='staging-none'), - pytest.param('staging', 'test_user', 8, id='staging-user'), - pytest.param('staging', 'other_test_user', 6, id='staging-other'), + pytest.param('staging', 'user1', 8, id='staging-user1'), + pytest.param('staging', 'user2', 6, id='staging-user2'), pytest.param('visible', None, 2, id='visible-none'), - pytest.param('visible', 'test_user', 10, id='visible-user'), - pytest.param('visible', 'other_test_user', 7, id='visible-other'), + pytest.param('visible', 'user1', 10, id='visible-user1'), + pytest.param('visible', 'user2', 7, id='visible-user2'), pytest.param('public', None, 1, id='public-none'), - pytest.param('public', 'test_user', 1, id='public-user'), - pytest.param('public', 'other_test_user', 1, id='public-other'), + pytest.param('public', 'user1', 1, id='public-user1'), + pytest.param('public', 'user2', 1, id='public-user2'), pytest.param('all', None, 3, id='all-none'), - pytest.param('all', 'test_user', 10, id='all-user'), - pytest.param('all', 'other_test_user', 8, id='all-other'), + pytest.param('all', 'user1', 10, id='all-user1'), + pytest.param('all', 'user2', 8, id='all-user2'), ], ) def test_search_query_group( self, - test_users_dict, + users_dict, example_group_data, owner, user, exc_or_total, ): - user = test_users_dict.get(user) + user = users_dict.get(user) user_id = user.user_id if user is not None else None if not isinstance(exc_or_total, int): diff --git a/tests/utils.py b/tests/utils.py index 59fb508b063d37065326456166f8d73a176aa72a..64923eea83dc33a865f4d3353b70a0b5cef8a405 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -159,10 +159,10 @@ def create_template_upload_file( return upload_path -def test_user_uuid(handle): +def fake_user_uuid(handle): return '00000000-0000-0000-0000-00000000000%d' % handle -def test_user_group_uuid(handle: Any): +def fake_group_uuid(handle: Any): """Returns a test user group uuid based on the handle.""" return str(handle).rjust(22, 'G')