-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing improvements for snovault and indirectly for cgap #241
Open
netsettler
wants to merge
6
commits into
master
Choose a base branch
from
kmp_misc_20230201
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cae1111
Add 'make test-full'. Install 'wheel' in 'make configure'.
netsettler 7efeeca
In pyproject: Make a beta version. Remove classifier for Python 3.7.
netsettler 53c5402
Add functions useful to cgap in snovault/tools.py.
netsettler 02c894b
Various PEP8-driven changes in snovault/util.py
netsettler 9b054ea
PEP8 changes
netsettler 3f3a299
Experimental workaround to a future problem in pkg_resources.parse_ve…
netsettler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "dcicsnovault" | ||
version = "7.1.1" | ||
version = "7.1.3.2b2" # to become "7.1.2" | ||
description = "Storage support for 4DN Data Portals." | ||
authors = ["4DN-DCIC Team <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -31,7 +31,6 @@ classifiers = [ | |
# Specify the Python versions you support here. In particular, ensure | ||
# that you indicate whether you support Python 2, Python 3 or both. | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import contextlib | ||
import webtest | ||
|
||
from .interfaces import DBSESSION | ||
from .elasticsearch import create_mapping | ||
|
||
|
||
def make_testapp(app, *, http_accept=None, remote_user=None): | ||
""" | ||
By default, makes a testapp with environ={"HTTP_ACCEPT": "application/json", "REMOTE_USER": "TEST"}. | ||
Arguments can be used to override these defaults. An explicit None accepts the default. | ||
|
||
:param app: a Pyramid app object. | ||
:param http_accept: The value of HTTP_ACCEPT in the testapp's environ, or None accepting 'application/json'. | ||
:param remote_user: The value of REMOTE_USER in the testapp's environ, or None accepting 'TEST'. | ||
""" | ||
environ = { | ||
'HTTP_ACCEPT': http_accept or 'application/json', | ||
'REMOTE_USER': remote_user or 'TEST', | ||
} | ||
testapp = webtest.TestApp(app, environ) | ||
return testapp | ||
|
||
|
||
def make_htmltestapp(app): | ||
"""Makes a testapp with environ={"HTTP_ACCEPT": "text/html", "REMOTE_USER": "TEST"}""" | ||
return make_testapp(app, http_accept='text/html') | ||
|
||
|
||
def make_authenticated_testapp(app): | ||
"""Makes a testapp with environ={"HTTP_ACCEPT": "application/json", "REMOTE_USER": "TEST_AUTHENTICATED"}""" | ||
return make_testapp(app, remote_user='TEST_AUTHENTICATED') | ||
|
||
|
||
def make_submitter_testapp(app): | ||
"""Makes a testapp with environ={"HTTP_ACCEPT": "application/json", "REMOTE_USER": "TEST_SUBMITTER"}""" | ||
return make_testapp(app, remote_user='TEST_SUBMITTER') | ||
|
||
|
||
def make_indexer_testapp(app): | ||
"""Makes a testapp with environ={"HTTP_ACCEPT": "application/json", "REMOTE_USER": "INDEXER"}""" | ||
return make_testapp(app, remote_user='INDEXER') | ||
|
||
|
||
def make_embed_testapp(app): | ||
"""Makes a testapp with environ={"HTTP_ACCEPT": "application/json", "REMOTE_USER": "EMBED"}""" | ||
return make_testapp(app, remote_user='EMBED') | ||
|
||
|
||
class NoNestedCommit(BaseException): | ||
""" | ||
This is a pseudo-error class to be used as a special control construct | ||
only for the purpose of implementing begin_nested. | ||
""" | ||
pass | ||
|
||
|
||
@contextlib.contextmanager | ||
def begin_nested(*, app, commit=True): | ||
session = app.registry[DBSESSION] | ||
connection = session.connection().connect() | ||
try: | ||
with connection.begin_nested(): | ||
yield | ||
if not commit: | ||
raise NoNestedCommit() # Raising an error will bypass an attempt to commit | ||
except NoNestedCommit: | ||
pass | ||
|
||
|
||
@contextlib.contextmanager | ||
def local_collections(*, app, collections): | ||
with begin_nested(app=app, commit=False): | ||
create_mapping.run(app, collections=collections, skip_indexing=True, purge_queue=True) | ||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,18 @@ | |
import functools | ||
import json | ||
import os | ||
import structlog | ||
import sys | ||
|
||
from copy import copy | ||
from datetime import datetime, timedelta | ||
|
||
import structlog | ||
from pyramid.httpexceptions import HTTPForbidden | ||
from pyramid.threadlocal import manager as threadlocal_manager | ||
|
||
from .interfaces import CONNECTION, STORAGE, TYPES | ||
from .settings import Settings | ||
|
||
|
||
log = structlog.getLogger(__name__) | ||
|
||
|
||
|
@@ -39,9 +40,9 @@ | |
REFRESH_INTERVAL = '1s' | ||
|
||
# Schema keys to ignore when finding embeds | ||
SCHEMA_KEYS_TO_IGNORE_FOR_EMBEDS = set([ | ||
SCHEMA_KEYS_TO_IGNORE_FOR_EMBEDS = { | ||
"items", "properties", "additionalProperties", "patternProperties" | ||
]) | ||
} | ||
|
||
|
||
class IndexSettings: | ||
|
@@ -720,7 +721,7 @@ def crawl_schemas_by_embeds(item_type, types, split_path, schema): | |
element = split_path[idx] | ||
# schema_cursor should always be a dictionary if we have more split_fields | ||
if not isinstance(schema_cursor, dict): | ||
error_message = '{} has a bad embed: {} does not have valid schemas throughout.'.format(item_type, linkTo_path) | ||
error_message = f'{item_type} has a bad embed: {linkTo_path} does not have valid schemas throughout.' | ||
return error_message, embeds_to_add | ||
if element == '*': | ||
linkTo_path = '.'.join(split_path[:-1]) | ||
|
@@ -875,11 +876,19 @@ def recursively_process_field(item, split_fields): | |
########################### | ||
|
||
|
||
def _sid_cache(request): | ||
return request._sid_cache # noQA. Centrally ignore that it's an access to a protected member. | ||
|
||
|
||
def _sid_cache_update(request, new_value): | ||
request._sid_cache.update(new_value) # noQA. Centrally ignore that it's an access to a protected member. | ||
|
||
|
||
def check_es_and_cache_linked_sids(context, request, view='embedded'): | ||
""" | ||
For the given context and request, see if the desired item is present in | ||
Elasticsearch and, if so, retrieve it cache all sids of the linked objects | ||
that correspond to the given view. Store these in request._sid_cacheself. | ||
that correspond to the given view. Store these in request's sid cache. | ||
|
||
Args: | ||
context: current Item | ||
|
@@ -896,9 +905,9 @@ def check_es_and_cache_linked_sids(context, request, view='embedded'): | |
es_links_field = 'linked_uuids_object' if view == 'object' else 'linked_uuids_embedded' | ||
if es_res and es_res.get(es_links_field): | ||
linked_uuids = [link['uuid'] for link in es_res[es_links_field] | ||
if link['uuid'] not in request._sid_cache] | ||
if link['uuid'] not in _sid_cache(request)] | ||
to_cache = request.registry[STORAGE].write.get_sids_by_uuids(linked_uuids) | ||
request._sid_cache.update(to_cache) | ||
_sid_cache_update(request, to_cache) | ||
return es_res | ||
return None | ||
|
||
|
@@ -938,11 +947,12 @@ def validate_es_content(context, request, es_res, view='embedded'): | |
return False | ||
for linked in linked_es_sids: | ||
# infrequently, may need to add sids from the db to the _sid_cache | ||
if linked['uuid'] not in request._sid_cache: | ||
cached = _sid_cache(request) | ||
found_sid = cached.get(linked['uuid']) | ||
if not found_sid: | ||
db_res = request.registry[STORAGE].write.get_by_uuid(linked['uuid']) | ||
if db_res: | ||
request._sid_cache[linked['uuid']] = db_res.sid | ||
found_sid = request._sid_cache.get(linked['uuid']) | ||
cached[linked['uuid']] = found_sid = db_res.sid | ||
Comment on lines
+950
to
+955
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the logic here so please double-check carefully, but I think this way of expressing what found_sid is will be easier to read. |
||
if found_sid is None or linked['sid'] < found_sid: | ||
use_es_result = False | ||
break | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fussed a bit about whether to default this to
'-9999'
,'0'
, or'1'
, but I think we never use negative versions and'0'
is therefore the lower bound. And I wanted a way to distinguish between this default and the earliest version I thought was likely to be specified explicitly, which is probably'1'
.