-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1775 from laws-africa/admin-tests
Admin tests
- Loading branch information
Showing
5 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
|
@@ -15,5 +15,22 @@ | |
"password": "pbkdf2_sha256$12000$NkxvaoXfb4p2$A6u0ez3trvm9VyIT606HB5G3NKRLl4znE4ZlsZS5T7U=", | ||
"date_joined": "2012-01-13 00:14:00+00:00" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "auth.user", | ||
"fields": { | ||
"username": "[email protected]", | ||
"first_name": "admin_user", | ||
"last_name": "", | ||
"is_active": true, | ||
"is_superuser": true, | ||
"is_staff": true, | ||
"last_login": "2021-01-13 00:14:00+00:00", | ||
"groups": [], | ||
"user_permissions": [], | ||
"password": "pbkdf2_sha256$12000$NkxvaoXfb4p2$A6u0ez3trvm9VyIT606HB5G3NKRLl4znE4ZlsZS5T7U=", | ||
"date_joined": "2012-01-13 00:14:00+00:00" | ||
} | ||
} | ||
] |
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,155 @@ | ||
import os | ||
|
||
from django.contrib.auth.models import User | ||
from django.urls import reverse | ||
from django_webtest import WebTest | ||
from webtest import Upload | ||
|
||
from peachjam.models import Judgment | ||
|
||
|
||
class TestJudgmentAdmin(WebTest): | ||
fixtures = ["tests/users", "tests/countries", "tests/courts", "tests/languages"] | ||
|
||
def setUp(self): | ||
self.app.set_user(User.objects.get(username="[email protected]")) | ||
|
||
def test_add_judgment_docx_swap_pdf(self): | ||
# add judgment | ||
judgment_add_url = reverse("admin:peachjam_judgment_add") | ||
judgment_list_url = reverse("admin:peachjam_judgment_changelist") | ||
|
||
form = self.app.get(judgment_add_url).form | ||
|
||
form["jurisdiction"] = "ZA" | ||
form["court"] = "1" | ||
form["language"] = "en" | ||
form["case_name"] = "test case" | ||
|
||
# date uses a multi-field widget | ||
form["date_0"] = "21" | ||
form["date_1"] = "2" | ||
form["date_2"] = "2000" | ||
|
||
with open( | ||
os.path.abspath("peachjam/fixtures/source_files/zagpjhc_judgment.docx"), | ||
"rb", | ||
) as docx_file: | ||
docx_file_content = docx_file.read() | ||
|
||
# upload file | ||
form["upload_file"] = Upload( | ||
"file.docx", | ||
docx_file_content, | ||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", | ||
) | ||
|
||
response = form.submit() | ||
self.assertRedirects(response, judgment_list_url) | ||
|
||
judgment = Judgment.objects.filter( | ||
expression_frbr_uri="/akn/za/judgment/eacj/2000/1/eng@2000-02-21" | ||
).first() | ||
self.assertIsNotNone(judgment) | ||
|
||
# check if content_html has been extracted | ||
self.assertIn( | ||
"The second count is robbery, in that on or about near the place mentioned in count", | ||
judgment.content_html, | ||
) | ||
self.assertEqual( | ||
"test-case-2000-eacj-1-21-february-2000.docx", | ||
judgment.source_file.filename, | ||
) | ||
|
||
# swap source file with pdf | ||
judgment_change_url = reverse( | ||
"admin:peachjam_judgment_change", kwargs={"object_id": judgment.pk} | ||
) | ||
form2 = self.app.get(judgment_change_url).form | ||
|
||
with open( | ||
os.path.abspath("peachjam/fixtures/source_files/gauteng_judgment.pdf"), "rb" | ||
) as pdf_file: | ||
pdf_file_content = pdf_file.read() | ||
form2["source_file-0-file"] = Upload( | ||
"upload_pdf.pdf", pdf_file_content, "application/pdf" | ||
) | ||
response2 = form2.submit() | ||
self.assertRedirects(response2, judgment_list_url) | ||
|
||
judgment.refresh_from_db() | ||
self.assertEqual( | ||
"test-case-2000-eacj-1-21-february-2000.pdf", judgment.source_file.filename | ||
) | ||
|
||
def test_add_judgment_pdf_swap_docx(self): | ||
# add judgment | ||
judgment_add_url = reverse("admin:peachjam_judgment_add") | ||
judgment_list_url = reverse("admin:peachjam_judgment_changelist") | ||
|
||
form = self.app.get(judgment_add_url).form | ||
|
||
form["jurisdiction"] = "ZA" | ||
form["court"] = "1" | ||
form["language"] = "en" | ||
form["case_name"] = "test case" | ||
|
||
# date uses a multi-field widget | ||
form["date_0"] = "25" | ||
form["date_1"] = "3" | ||
form["date_2"] = "1999" | ||
|
||
# upload file | ||
with open( | ||
os.path.abspath("peachjam/fixtures/source_files/gauteng_judgment.pdf"), "rb" | ||
) as pdf_file: | ||
pdf_file_content = pdf_file.read() | ||
|
||
form["upload_file"] = Upload( | ||
"upload_pdf.pdf", pdf_file_content, "application/pdf" | ||
) | ||
|
||
response = form.submit() | ||
self.assertRedirects(response, judgment_list_url) | ||
|
||
judgment = Judgment.objects.filter( | ||
expression_frbr_uri="/akn/za/judgment/eacj/1999/1/eng@1999-03-25" | ||
).first() | ||
self.assertIsNotNone(judgment) | ||
|
||
# check if content_html has been extracted | ||
self.assertEqual( | ||
"test-case-1999-eacj-1-25-march-1999.pdf", | ||
judgment.source_file.filename, | ||
) | ||
|
||
# swap source file with pdf | ||
judgment_change_url = reverse( | ||
"admin:peachjam_judgment_change", kwargs={"object_id": judgment.pk} | ||
) | ||
|
||
with open( | ||
os.path.abspath("peachjam/fixtures/source_files/zagpjhc_judgment.docx"), | ||
"rb", | ||
) as docx_file: | ||
docx_file_content = docx_file.read() | ||
|
||
form2 = self.app.get(judgment_change_url).form | ||
form2["source_file-0-file"] = Upload( | ||
"file.docx", | ||
docx_file_content, | ||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", | ||
) | ||
|
||
response2 = form2.submit() | ||
self.assertRedirects(response2, judgment_list_url) | ||
|
||
judgment.refresh_from_db() | ||
self.assertIn( | ||
"The second count is robbery, in that on or about near the place mentioned in count", | ||
judgment.content_html, | ||
) | ||
self.assertEqual( | ||
"test-case-1999-eacj-1-25-march-1999.docx", judgment.source_file.filename | ||
) |
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