-
Notifications
You must be signed in to change notification settings - Fork 0
SUBMISSION-196 PDF-Only Stamping #84
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3d77212
Stamp PDF-only submissions and install stamped + unstamped PDFs [SUBM…
DavidLFielding 2de2e17
Merge remote-tracking branch 'origin/develop' into SUBMISSION-196-PDF…
DavidLFielding 4de4fd8
Call /stamp without trailing slash to avoid 307 redirect [SUBMISSION-…
DavidLFielding d5cee85
Merge remote-tracking branch 'origin/develop' into SUBMISSION-196-PDF…
DavidLFielding 2623e6f
Drop the redundant unstamped PDF for PDF-only; clean up stale TeX nos…
DavidLFielding 300be29
Don't mark PDF-only source processed when the install guard skips [SU…
DavidLFielding f517d71
Move PDF-only one-PDF check to validate_under_lock [SUBMISSION-196] D…
DavidLFielding 13d247f
Clarify InstallPdfPreview.project docstring: records preview artifact…
DavidLFielding 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| """Tests for InstallPdfPreview.validate_under_lock. [SUBMISSION-196] | ||
|
|
||
| The event requires exactly one PDF in the source workspace. That precondition | ||
| lives in ``validate_under_lock`` (run under the submission row lock), so a | ||
| violated invariant rejects the event cleanly -- raising ``InvalidEvent`` -- | ||
| instead of installing a partial or absent preview. | ||
|
|
||
| Unreachable in normal flow (``source_format == PDF`` implies a single lone PDF; | ||
| see ``_infer_source_format``); these tests guard the invariant. | ||
| """ | ||
|
|
||
| from datetime import datetime | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
| from pytz import UTC | ||
|
|
||
| from submit_ce.domain import submission as submod, agent | ||
| from submit_ce.domain.uploads import SourceFormat | ||
| from submit_ce.domain.exceptions import InvalidEvent | ||
| from submit_ce.domain.event.process import InstallPdfPreview | ||
|
|
||
|
|
||
| class _FakeStore: | ||
| def __init__(self, files): | ||
| self._files = files | ||
|
|
||
| def get_workspace(self, submission_id): | ||
| return SimpleNamespace(files=self._files) | ||
|
|
||
|
|
||
| class _FakeApi: | ||
| def __init__(self, files): | ||
| self._store = _FakeStore(files) | ||
|
|
||
| def get_file_store(self): | ||
| return self._store | ||
|
|
||
|
|
||
| def _user(uid="u1"): | ||
| return agent.PublicUser(name="Test User", user_id=uid, | ||
| email=f"{uid}@example.org", endorsements=[]) | ||
|
|
||
|
|
||
| def _pdf_submission(sid="1234567"): | ||
| u = _user() | ||
| s = submod.Submission(creator=u, owner=u, created=datetime.now(UTC), | ||
| source_format=SourceFormat.PDF) | ||
| s.submission_id = sid | ||
| return s | ||
|
|
||
|
|
||
| def _pdf_file(name): | ||
| return SimpleNamespace(name=name, path=name, crc32c="c", bytes=10) | ||
|
|
||
|
|
||
| def _validate(files): | ||
| s = _pdf_submission() | ||
| api = _FakeApi(files) | ||
| InstallPdfPreview(creator=s.creator).validate_under_lock(api, s) | ||
|
|
||
|
|
||
| def test_zero_pdfs_rejected(): | ||
| with pytest.raises(InvalidEvent): | ||
| _validate([]) | ||
|
|
||
|
|
||
| def test_multiple_pdfs_rejected(): | ||
| with pytest.raises(InvalidEvent): | ||
| _validate([_pdf_file("a.pdf"), _pdf_file("b.pdf")]) | ||
|
|
||
|
|
||
| def test_exactly_one_pdf_passes(): | ||
| # Should not raise. | ||
| _validate([_pdf_file("paper.pdf")]) |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.