Skip to content
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

TST/REF: unify and parametrize data, backend, and client fixtures #116

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
26 changes: 26 additions & 0 deletions docs/source/upcoming_release_notes/116-tst_ref_fixtures.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
116 tst_ref_fixtures
####################

API Breaks
----------
- N/A

Features
--------
- N/A

Bugfixes
--------
- Fixes bug where TestBackend could not delete an entry that was a direct child of the `Root`
- Fixes behavior of FilestoreBackend to throw `Entry*Error` exceptions rather than just returning None

Maintenance
-----------
- Adds `test_data`, `test_backend`, and `test_client` fixtures that can be parametrized, replacing other specialized fixtures that maybe setup.
- Adds `setup_test_stack` to concisely parametrize and request the aforementioned `test_*` fixtures.
- Organizes data-helper functions into a separate `conftest_data` file.
- Adjusts existing tests to use `setup_test_stack` and `test_*` fixtures instead of other specialized fixtures.

Contributors
------------
- tangkong
14 changes: 10 additions & 4 deletions superscore/backends/filestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from apischema import deserialize, serialize

from superscore.backends.core import SearchTermType, _Backend
from superscore.errors import BackendError
from superscore.errors import (BackendError, EntryExistsError,
EntryNotFoundError)
from superscore.model import Entry, Nestable, Root
from superscore.utils import build_abs_path

Expand Down Expand Up @@ -253,7 +254,12 @@ def get_entry(self, uuid: Union[UUID, str]) -> Entry:
with self._load_and_store_context() as db:
if isinstance(uuid, str):
uuid = UUID(uuid)
return db.get(uuid)
result = db.get(uuid)

if result is None:
raise EntryNotFoundError(f"Entry {uuid} could not be found")

return result

def save_entry(self, entry: Entry) -> None:
"""
Expand All @@ -262,8 +268,8 @@ def save_entry(self, entry: Entry) -> None:
"""
with self._load_and_store_context() as db:
if db.get(entry.uuid):
raise BackendError("Entry already exists, try updating the entry "
"instead of saving it")
raise EntryExistsError("Entry already exists, try updating the "
"entry instead of saving it")
self.flatten_and_cache(entry)
self._root.entries.append(entry)

Expand Down
10 changes: 9 additions & 1 deletion superscore/backends/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,23 @@ def update_entry(self, entry: Entry) -> None:

def delete_entry(self, to_delete: Entry) -> None:
stack = [self.data.copy()]
# remove from nested children
while len(stack) > 0:
children = stack.pop()
for entry in children.copy():
if entry == to_delete:
children.remove(entry)
elif entry.uuid == to_delete.uuid:
raise BackendError(f"Can't delete: entry {to_delete.uuid} is out of sync with the version in the backend")
raise BackendError(
f"Can't delete: entry {to_delete.uuid} "
"is out of sync with the version in the backend"
)
stack.extend([entry.children for entry in children if isinstance(entry, Nestable)])

# Remove from top level if necessary
if to_delete in self.data:
self.data.remove(to_delete)

self._fill_entry_cache()

@property
Expand Down
Loading