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

Admin tests #1775

Merged
merged 3 commits into from
Mar 18, 2024
Merged

Admin tests #1775

merged 3 commits into from
Mar 18, 2024

Conversation

actlikewill
Copy link
Contributor

@actlikewill actlikewill commented Mar 15, 2024

  • this adds tests for the judgment admin

Copy link

sentry-io bot commented Mar 15, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: peachjam/models/core_document_model.py

Function Unhandled Issue
update_or_create_for_document CalledProcessError: Command '['/app/peachjam/../bin/pdfjs-to-text', '/tmp/tmpklra61y4', '/tmp/tmpj6l0ot__.txt']' retu... ...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

@actlikewill actlikewill changed the base branch from main to source-update March 15, 2024 12:37
@actlikewill
Copy link
Contributor Author

actlikewill commented Mar 15, 2024

@longhotsummer these tests are already revealing some issues. There is some inconsistency with the way we set mimetypes for source documents. When adding new documents, to set the mimetype, we read from file.content_type but when we are modifying, we use the python magic library. These two dont always give the same results. It could also be because of the way Webtest is mocking the files but its making the tests that I'm writing fail.

@longhotsummer
Copy link
Contributor

@longhotsummer these tests are already revealing some issues. There is some inconsistency with the way we set mimetypes for source documents. When adding new documents, to set the mimetype, we read from file.content_type but when we are modifying, we use the python magic library. These two dont always give the same results. It could also be because of the way Webtest is mocking the files but its making the tests that I'm writing fail.

This is good to learn. We file.content_type trusts the browser, whereas the python magic library actually looks at the file contents. So b"pdf judgment content" won't be considered a PDF by the magic library.

An option is to add some small PDF and DOCX files as fixture objects and post real files.

@actlikewill
Copy link
Contributor Author

An option is to add some small PDF and DOCX files as fixture objects and post real files.

@longhotsummer I've tried this but it doesn't seem to work properly. The webtes.Upload doesn't seem to work with actual files. Still checking though

self.assertRedirects(response2, judgment_list_url)

judgment.refresh_from_db()
self.assertIn("test case", judgment.content_html)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@longhotsummer this is the assertion that revealed the issue. I'm checking that the content_html has been changed, but since the mimetype is incorrect, it is not extracting the content. The mimetype is reported as text/plain

@actlikewill actlikewill marked this pull request as ready for review March 16, 2024 07:41
@actlikewill
Copy link
Contributor Author

@longhotsummer this pr will merge to this one #1771 with the bug fix, the we can merge it to master

@longhotsummer longhotsummer merged commit 4103b05 into source-update Mar 18, 2024
9 checks passed
@longhotsummer longhotsummer deleted the admin-tests branch March 18, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants