Skip to content

Commit

Permalink
Minor updates related to PR-1808 feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Jul 19, 2023
1 parent 9219c88 commit 55b1d76
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 52 deletions.
4 changes: 3 additions & 1 deletion src/encoded/project/authentication.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from dcicutils.misc_utils import ignored
from pyramid.httpexceptions import HTTPUnauthorized
from snovault.project.authentication import SnovaultProjectAuthentication

class FourfrontProjectAuthentication(SnovaultProjectAuthentication):

def login(self, context, request, *, samesite):
samesite = "lax" # TODO: maybe make lax = True or False (from Kent)
ignored(samesite)
samesite = "lax"
return super().login(context, request, samesite=samesite)

def namespaced_authentication_policy_authenticated_userid(self, namespaced_authentication_policy, request, set_user_info_property):
Expand Down
3 changes: 2 additions & 1 deletion src/encoded/server_defaults.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from snovault.project_app import app_project
from snovault.server_defaults import (
add_last_modified,
enc_accession,
Expand All @@ -7,5 +8,5 @@
)

ACCESSION_FACTORY = __name__ + ':accession_factory'
ACCESSION_PREFIX = '4DN'
ACCESSION_PREFIX = app_project().ACCESSION_PREFIX
ACCESSION_TEST_PREFIX = 'TST'
23 changes: 11 additions & 12 deletions src/encoded/tests/test_loadxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@


pytestmark = [pytest.mark.setone, pytest.mark.working]
loadxl_package = "snovault.loadxl"


def test_load_data_endpoint(testapp):
data = {'fdn_dir': 'master-inserts',
'itype': ['award', 'lab', 'user']}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=200)
assert res.json['status'] == 'success'
Expand All @@ -23,7 +22,7 @@ def test_load_data_endpoint(testapp):
def test_load_data_endpoint_returns_error_if_incorrect_keyword(testapp):
data = {'mdn_dir': 'master-inserts',
'itype': ['user']}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=422)
assert res.json['status'] == 'error'
Expand All @@ -33,7 +32,7 @@ def test_load_data_endpoint_returns_error_if_incorrect_keyword(testapp):
def test_load_data_endpoint_returns_error_if_incorrect_data(testapp):
data = {'fdn_dir': 'master-inserts',
'itype': ['user']}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=422)
assert res.json['status'] == 'error'
Expand All @@ -45,7 +44,7 @@ def test_load_data_user_specified_config(testapp):
'itype': ['user', 'lab', 'award']}
config_uri = 'test.ini'
data['config_uri'] = config_uri
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=200)
assert res.json['status'] == 'success'
Expand All @@ -54,8 +53,8 @@ def test_load_data_user_specified_config(testapp):

def test_load_data_local_dir(testapp):
expected_dir = resource_filename('encoded', 'tests/data/perf-testing/')
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'{loadxl_package}.load_all') as load_all:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.load_all') as load_all:
mocked_app.return_value = testapp.app
load_all.return_value = None
res = testapp.post_json('/load_data', {'fdn_dir': 'perf-testing'}, status=200)
Expand All @@ -69,7 +68,7 @@ def test_load_data_from_json(testapp):
award_inserts = list(get_inserts('master-inserts', 'award'))
data = {'store': {'user': user_inserts, 'lab': lab_inserts, 'award': award_inserts},
'itype': ['user', 'lab', 'award']}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=200)
assert res.json['status'] == 'success'
Expand All @@ -78,7 +77,7 @@ def test_load_data_from_json(testapp):
def test_load_data_local_path(testapp):
local_path = resource_filename('encoded', 'tests/data/master-inserts/')
data = {'local_path': local_path, 'itype': ['user', 'lab', 'award']}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=200)
assert res.json['status'] == 'success'
Expand All @@ -97,7 +96,7 @@ def test_load_data_iter_response(testapp):
expected = len(user_inserts) + len(lab_inserts) + len(award_inserts)
data = {'store': {'user': user_inserts, 'lab': lab_inserts, 'award': award_inserts},
'itype': ['user', 'lab', 'award'], 'iter_response': True}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=200)
assert res.content_type == 'text/plain'
Expand All @@ -121,7 +120,7 @@ def test_load_data_iter_response_fail(testapp):
# the total number of items we expect
expected = len(user_inserts)
data = {'store': {'user': user_inserts}, 'itype': ['user'], 'iter_response': True}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
res = testapp.post_json('/load_data', data, status=200)
assert res.content_type == 'text/plain'
Expand All @@ -147,7 +146,7 @@ def test_load_all_gen(testapp):
expected = len(user_inserts) + len(lab_inserts) + len(award_inserts)
data = {'store': {'user': user_inserts, 'lab': lab_inserts, 'award': award_inserts},
'itype': ['user', 'lab', 'award']}
with mock.patch(f'{loadxl_package}.get_app') as mocked_app:
with mock.patch(f'snovault.loadxl.get_app') as mocked_app:
mocked_app.return_value = testapp.app
# successful load cases
gen1 = loadxl.load_all_gen(testapp, data['store'], None,
Expand Down
55 changes: 17 additions & 38 deletions src/encoded/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import structlog
import tempfile
from typing import Any, Generator, Optional
from dcicutils.misc_utils import url_path_join, find_association
from dcicutils.misc_utils import exported, find_association, url_path_join
from snovault.util import (
beanstalk_env_from_registry,
check_user_is_logged_in,
Expand All @@ -20,51 +20,30 @@
delay_rerun,
get_trusted_email,
make_vapp_for_ingestion,
resolve_file_path as snovault_resolve_file_path,
#resolve_file_path as snovault_resolve_file_path,
s3_local_file,
s3_output_stream,
)

# These are now moved or reused from snovault.utils (May 2023):
# - CONTENT_TYPE_SPECIAL_CASES
# - register_path_content_type
# - content_type_allowed
# - gunzip_content
# - deduplicate_list
# - debuglog
# - make_vapp_for_email
# - vapp_for_email
# - make_vapp_for_ingestion
# - vapp_for_ingestion
# - _app_from_clues
# - make_s3_client
# - build_s3_presigned_get_url
# - convert_integer_to_comma_string
# - ENCODED_ROOT_DIR
# - resolve_file_path
# - subrequest_object
# - subrequest_item_creation
# - s3_output_stream
# - s3_local_file
# - s3_input_stream
# - check_user_is_logged_in
# - create_empty_s3_file
# - get_trusted_email
# - beanstalk_env_from_request
# - beanstalk_env_from_registry
# - customized_delay_rerun
# - delay_rerun
# - SettingsKey
# - ExtraArgs
# - extra_kwargs_for_s3_encrypt_key_id

exported (
beanstalk_env_from_registry,
check_user_is_logged_in,
content_type_allowed,
create_empty_s3_file,
customized_delay_rerun,
debuglog,
delay_rerun,
get_trusted_email,
make_vapp_for_ingestion,
s3_local_file,
s3_output_stream
)

log = structlog.getLogger(__name__)
ENCODED_ROOT_DIR = os.path.dirname(__file__)


def resolve_file_path(path, file_loc=None):
return snovault_resolve_file_path(path=path, file_loc=file_loc, root_dir=ENCODED_ROOT_DIR)
#def resolve_file_path(path, file_loc=None):
# return snovault_resolve_file_path(path=path, file_loc=file_loc, root_dir=ENCODED_ROOT_DIR)


@contextlib.contextmanager
Expand Down

0 comments on commit 55b1d76

Please sign in to comment.