-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert test to pytest style, add basic frontend testing
- Loading branch information
Showing
21 changed files
with
154 additions
and
117 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,115 +1,128 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from . import DocumentCollectionFactory, DocumentFactory, UserFactory | ||
|
||
|
||
class DocumentAccessTest(TestCase): | ||
def setUp(self): | ||
self.user = UserFactory.create() | ||
|
||
def test_unlisted_document_needs_slug(self): | ||
doc = DocumentFactory.create(user=self.user, public=True, listed=False) | ||
|
||
url = reverse( | ||
"filingcabinet:document-detail_short", | ||
kwargs={ | ||
"pk": doc.pk, | ||
}, | ||
) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
url = reverse( | ||
"filingcabinet:document-detail", kwargs={"pk": doc.pk, "slug": doc.slug} | ||
) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
self.client.force_login(self.user) | ||
url = reverse( | ||
"filingcabinet:document-detail_short", | ||
kwargs={ | ||
"pk": doc.pk, | ||
}, | ||
) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
def test_list_unlisted_document_api(self): | ||
DocumentFactory.create(user=self.user, public=True, listed=False) | ||
url = reverse("api:document-list") | ||
response = self.client.get(url) | ||
self.assertEqual(len(response.json()["objects"]), 0) | ||
self.client.force_login(self.user) | ||
response = self.client.get(url) | ||
self.assertEqual(len(response.json()["objects"]), 1) | ||
|
||
def test_retrieve_unlisted_document_api(self): | ||
doc = DocumentFactory.create(user=self.user, public=True, listed=False) | ||
url = reverse("api:document-detail", kwargs={"pk": doc.pk}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
url = reverse("api:document-detail", kwargs={"pk": doc.pk}) | ||
response = self.client.get(url + "?uid=" + str(doc.uid)) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
self.client.force_login(self.user) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_unlisted_documentcollection_needs_slug(self): | ||
collection = DocumentCollectionFactory.create( | ||
user=self.user, public=True, listed=False | ||
) | ||
|
||
url = reverse( | ||
"filingcabinet:document-collection_short", | ||
kwargs={ | ||
"pk": collection.pk, | ||
}, | ||
) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
url = reverse( | ||
"filingcabinet:document-collection", | ||
kwargs={"pk": collection.pk, "slug": collection.slug}, | ||
) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
self.client.force_login(self.user) | ||
url = reverse( | ||
"filingcabinet:document-collection_short", | ||
kwargs={ | ||
"pk": collection.pk, | ||
}, | ||
) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
def test_list_unlisted_documentcollection_api(self): | ||
DocumentCollectionFactory.create(user=self.user, public=True, listed=False) | ||
url = reverse("api:documentcollection-list") | ||
response = self.client.get(url) | ||
self.assertEqual(len(response.json()["objects"]), 0) | ||
self.client.force_login(self.user) | ||
response = self.client.get(url) | ||
self.assertEqual(len(response.json()["objects"]), 1) | ||
|
||
def test_retrieve_unlisted_documentcollection_api(self): | ||
collection = DocumentCollectionFactory.create( | ||
user=self.user, public=True, listed=False | ||
) | ||
url = reverse("api:documentcollection-detail", kwargs={"pk": collection.pk}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
response = self.client.get(url + "?uid=" + str(collection.uid)) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
self.client.force_login(self.user) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
import pytest | ||
|
||
from filingcabinet import get_document_model, get_documentcollection_model | ||
|
||
from .factories import DocumentCollectionFactory, DocumentFactory | ||
|
||
Document = get_document_model() | ||
DocumentCollection = get_documentcollection_model() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_unlisted_document_needs_slug(client, dummy_user): | ||
doc = DocumentFactory.create(user=dummy_user, public=True, listed=False) | ||
|
||
url = reverse( | ||
"filingcabinet:document-detail_short", | ||
kwargs={ | ||
"pk": doc.pk, | ||
}, | ||
) | ||
response = client.get(url) | ||
assert response.status_code == 404 | ||
|
||
url = reverse( | ||
"filingcabinet:document-detail", kwargs={"pk": doc.pk, "slug": doc.slug} | ||
) | ||
response = client.get(url) | ||
assert response.status_code == 200 | ||
|
||
client.force_login(dummy_user) | ||
url = reverse( | ||
"filingcabinet:document-detail_short", | ||
kwargs={ | ||
"pk": doc.pk, | ||
}, | ||
) | ||
response = client.get(url) | ||
assert response.status_code == 302 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_unlisted_document_api(client, dummy_user): | ||
DocumentFactory.create(user=dummy_user, public=True, listed=False) | ||
url = reverse("api:document-list") | ||
response = client.get(url) | ||
assert len(response.json()["objects"]) == 0 | ||
client.force_login(dummy_user) | ||
response = client.get(url) | ||
assert len(response.json()["objects"]) == 1 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_retrieve_unlisted_document_api(client, dummy_user): | ||
doc = DocumentFactory.create(user=dummy_user, public=True, listed=False) | ||
url = reverse("api:document-detail", kwargs={"pk": doc.pk}) | ||
response = client.get(url) | ||
assert response.status_code == 403 | ||
|
||
url = reverse("api:document-detail", kwargs={"pk": doc.pk}) | ||
response = client.get(url + "?uid=" + str(doc.uid)) | ||
assert response.status_code == 200 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(url) | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_unlisted_documentcollection_needs_slug(client, dummy_user): | ||
collection = DocumentCollectionFactory.create( | ||
user=dummy_user, public=True, listed=False | ||
) | ||
|
||
url = reverse( | ||
"filingcabinet:document-collection_short", | ||
kwargs={ | ||
"pk": collection.pk, | ||
}, | ||
) | ||
response = client.get(url) | ||
assert response.status_code == 404 | ||
|
||
url = reverse( | ||
"filingcabinet:document-collection", | ||
kwargs={"pk": collection.pk, "slug": collection.slug}, | ||
) | ||
response = client.get(url) | ||
assert response.status_code == 200 | ||
|
||
client.force_login(dummy_user) | ||
url = reverse( | ||
"filingcabinet:document-collection_short", | ||
kwargs={ | ||
"pk": collection.pk, | ||
}, | ||
) | ||
response = client.get(url) | ||
assert response.status_code == 302 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_unlisted_documentcollection_api(client, dummy_user): | ||
DocumentCollectionFactory.create(user=dummy_user, public=True, listed=False) | ||
url = reverse("api:documentcollection-list") | ||
response = client.get(url) | ||
assert len(response.json()["objects"]) == 0 | ||
client.force_login(dummy_user) | ||
response = client.get(url) | ||
assert len(response.json()["objects"]) == 1 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_retrieve_unlisted_documentcollection_api(client, dummy_user): | ||
collection = DocumentCollectionFactory.create( | ||
user=dummy_user, public=True, listed=False | ||
) | ||
url = reverse("api:documentcollection-detail", kwargs={"pk": collection.pk}) | ||
response = client.get(url) | ||
assert response.status_code == 403 | ||
|
||
response = client.get(url + "?uid=" + str(collection.uid)) | ||
assert response.status_code == 200 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(url) | ||
assert response.status_code == 200 |
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,5 @@ | ||
def test_document_viewer(page, live_server, processed_document): | ||
page.goto(live_server.url + processed_document.get_absolute_url()) | ||
assert processed_document.title in page.title() | ||
assert page.query_selector("h2").text_content() == processed_document.title | ||
page.pause() |
Binary file added
BIN
+254 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/example.pdf
Binary file not shown.
Binary file added
BIN
+262 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p1-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+169 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p1-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+331 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p1-original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.7 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p1-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+282 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p2-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+181 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p2-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+360 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p2-original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.7 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p2-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+279 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p3-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+180 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p3-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+359 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p3-original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.5 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p3-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+83.2 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p4-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+53.9 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p4-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+126 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p4-original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.63 KB
tests/testdata/docs/ef/39/5b/ef395b666014488aa551e431e653a1d9/page-p4-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.