Skip to content

Commit

Permalink
Tests for uncovered local_db code
Browse files Browse the repository at this point in the history
  • Loading branch information
rebkwok committed Feb 28, 2024
1 parent 7a707d3 commit 8580dfe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion local_db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StatusField(models.TextField):
choices = [(i.value, i.name) for i in Status]

def from_db_value(self, value, expression, connection):
if value is None:
if value is None: # pragma: no cover
return value

return Status[value]
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,47 @@ def test_provider_get_requests_authored_by_user(
assert set(r.id for r in api.get_requests_authored_by_user(user)) == set(expected)


@pytest.mark.parametrize(
"output_checker, expected",
[
# A non-output checker never sees outstanding requests
(False, []),
# An output checker only sees outstanding requests that
# they did not author
(True, ["r1"]),
],
)
def test_provider_get_outstanding_requests_for_review(output_checker, expected, api):
user = User(1, "test", ["workspace"], output_checker)
other_user = User(1, "other", ["workspace"], False)
# request created by another user, status submitted
factories.create_release_request(
"workspace", other_user, id="r1", status=Status.SUBMITTED
)

# requests not visible to output checker
# status submitted, but authored by output checker
factories.create_release_request(
"workspace", user, id="r2", status=Status.SUBMITTED
)
# requests authored by other users, status other than pending
for i, status in enumerate(
[
Status.PENDING,
Status.WITHDRAWN,
Status.APPROVED,
Status.REJECTED,
Status.RELEASED,
]
):
ws = f"workspace{i}"
factories.create_release_request(ws, User(1, f"test_{i}", [ws]), status=status)

assert set(r.id for r in api.get_outstanding_requests_for_review(user)) == set(
expected
)


def test_provider_get_current_request_for_user(api):
workspace = factories.create_workspace("workspace")
user = User(1, "testuser", ["workspace"], False)
Expand Down Expand Up @@ -276,6 +317,15 @@ def test_add_file_to_request_states(status, success, api):
assert not release_request.abspath(path).exists()


def test_request_release_invalid_state():
factories.create_workspace("workspace")
with pytest.raises(AttributeError):
factories.create_release_request(
"workspace",
status="unknown",
)


def setup_empty_release_request():
author = User(1, "author", ["workspace"], False)
path = Path("path/file.txt")
Expand Down

0 comments on commit 8580dfe

Please sign in to comment.