-
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.
Add view tests for document, collection, portal
- Loading branch information
Showing
6 changed files
with
322 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from django.urls import reverse | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_collection_detail(document_collection, client): | ||
response = client.get(document_collection.get_absolute_url()) | ||
assert response.status_code == 200 | ||
assert document_collection.title in response.content.decode("utf-8") | ||
assert document_collection.description in response.content.decode("utf-8") | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_collection_detail_private(document_collection, client, dummy_user): | ||
document_collection.public = False | ||
document_collection.user = dummy_user | ||
document_collection.save() | ||
response = client.get(document_collection.get_absolute_url()) | ||
assert response.status_code == 404 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(document_collection.get_absolute_url()) | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize("initial_slug_val", ["", None]) | ||
def test_collection_detail_slug_behavior( | ||
document_collection, client, dummy_user, initial_slug_val | ||
): | ||
if initial_slug_val is not None: | ||
document_collection.slug = initial_slug_val | ||
document_collection.user = dummy_user | ||
document_collection.save() | ||
|
||
bad_slug_url = reverse( | ||
"filingcabinet:document-collection", | ||
kwargs={"pk": document_collection.pk, "slug": "bad"}, | ||
) | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == document_collection.get_absolute_url() | ||
|
||
query_param = "?foo=bar" | ||
bad_slug_url = bad_slug_url + query_param | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 302 | ||
assert ( | ||
response.headers["Location"] | ||
== document_collection.get_absolute_url() + query_param | ||
) | ||
|
||
document_collection.public = False | ||
document_collection.user = dummy_user | ||
document_collection.save() | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 404 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 302 | ||
assert ( | ||
response.headers["Location"] | ||
== document_collection.get_absolute_url() + query_param | ||
) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_collection_embed(document_collection, client): | ||
response = client.get(document_collection.get_absolute_domain_embed_url()) | ||
assert response.status_code == 200 | ||
assert "<h2>{}</h2>".format( | ||
document_collection.title | ||
) not in response.content.decode("utf-8") | ||
|
||
document_collection.slug = "" | ||
document_collection.save() | ||
response = client.get(document_collection.get_absolute_domain_embed_url()) | ||
assert response.status_code == 200 | ||
assert "<h2>{}</h2>".format( | ||
document_collection.title | ||
) not in response.content.decode("utf-8") |
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,146 @@ | ||
from django.urls import reverse | ||
|
||
import pytest | ||
|
||
from filingcabinet import views | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_document_detail(processed_document, client): | ||
response = client.get(processed_document.get_absolute_url()) | ||
assert response.status_code == 200 | ||
assert processed_document.title in response.content.decode("utf-8") | ||
assert processed_document.description in response.content.decode("utf-8") | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_document_detail_private(processed_document, client, dummy_user): | ||
processed_document.public = False | ||
processed_document.user = dummy_user | ||
processed_document.save() | ||
response = client.get(processed_document.get_absolute_url()) | ||
assert response.status_code == 404 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(processed_document.get_absolute_url()) | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_document_detail_pending(processed_document, client, dummy_user): | ||
processed_document.pending = True | ||
processed_document.user = dummy_user | ||
processed_document.save() | ||
response = client.get(processed_document.get_absolute_url()) | ||
assert response.status_code == 200 | ||
# iframe with PDF embed present | ||
assert '<iframe src="{}"'.format( | ||
processed_document.get_file_url() | ||
) in response.content.decode("utf-8") | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize("initial_slug_val", ["", None]) | ||
def test_document_detail_slug_behavior( | ||
processed_document, client, dummy_user, initial_slug_val | ||
): | ||
if initial_slug_val is not None: | ||
processed_document.slug = initial_slug_val | ||
processed_document.user = dummy_user | ||
processed_document.save() | ||
|
||
bad_slug_url = reverse( | ||
"filingcabinet:document-detail", | ||
kwargs={"pk": processed_document.pk, "slug": "bad"}, | ||
) | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 302 | ||
assert response.headers["Location"] == processed_document.get_absolute_url() | ||
|
||
query_param = "?foo=bar" | ||
bad_slug_url = bad_slug_url + query_param | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 302 | ||
assert ( | ||
response.headers["Location"] | ||
== processed_document.get_absolute_url() + query_param | ||
) | ||
|
||
processed_document.public = False | ||
processed_document.user = dummy_user | ||
processed_document.save() | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 404 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 302 | ||
assert ( | ||
response.headers["Location"] | ||
== processed_document.get_absolute_url() + query_param | ||
) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_document_detail_page_query(processed_document, client, monkeypatch): | ||
monkeypatch.setattr(views, "PREVIEW_PAGE_COUNT", 2) | ||
response = client.get(processed_document.get_absolute_url() + "?page=1000") | ||
assert response.status_code == 200 | ||
content = response.content.decode("utf-8") | ||
assert '<a href="#page-1"' in content | ||
assert '<a href="#page-2"' in content | ||
assert '<a href="#page-3"' not in content | ||
assert '<a href="#page-4"' not in content | ||
|
||
response = client.get(processed_document.get_absolute_url() + "?page=1") | ||
assert response.status_code == 200 | ||
content = response.content.decode("utf-8") | ||
assert '<a href="#page-1"' in content | ||
assert '<a href="#page-2"' in content | ||
assert '<a href="#page-3"' not in content | ||
assert '<a href="#page-4"' not in content | ||
|
||
response = client.get(processed_document.get_absolute_url() + "?page=2") | ||
assert response.status_code == 200 | ||
content = response.content.decode("utf-8") | ||
assert '<a href="#page-1"' not in content | ||
assert '<a href="#page-2"' in content | ||
assert '<a href="#page-3"' in content | ||
assert '<a href="#page-4"' not in content | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_document_embed(processed_document, client): | ||
response = client.get(processed_document.get_absolute_domain_embed_url()) | ||
assert response.status_code == 200 | ||
assert "<h2>{}</h2>".format( | ||
processed_document.title | ||
) not in response.content.decode("utf-8") | ||
|
||
processed_document.slug = "" | ||
processed_document.save() | ||
response = client.get(processed_document.get_absolute_domain_embed_url()) | ||
assert response.status_code == 200 | ||
assert "<h2>{}</h2>".format( | ||
processed_document.title | ||
) not in response.content.decode("utf-8") | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_document_file_detail(processed_document, client, dummy_user): | ||
processed_document.user = dummy_user | ||
processed_document.public = False | ||
processed_document.save() | ||
|
||
response = client.get(processed_document.get_file_url()) | ||
assert response.status_code == 404 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(processed_document.get_file_url().replace("/ef/", "/aa/")) | ||
assert response.status_code == 404 | ||
response = client.get(processed_document.get_file_url()) | ||
assert response.status_code == 200 | ||
assert response.headers["Content-Type"] == "" | ||
assert response.headers["X-Accel-Redirect"].endswith( | ||
processed_document.get_file_name() | ||
) |
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,38 @@ | ||
from django.urls import reverse | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_portal_detail(document_portal, client): | ||
response = client.get(document_portal.get_absolute_url()) | ||
assert response.status_code == 200 | ||
assert document_portal.title in response.content.decode("utf-8") | ||
assert document_portal.description in response.content.decode("utf-8") | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_portal_detail_private(document_portal, client, dummy_user): | ||
document_portal.public = False | ||
document_portal.save() | ||
response = client.get(document_portal.get_absolute_url()) | ||
assert response.status_code == 404 | ||
|
||
client.force_login(dummy_user) | ||
response = client.get(document_portal.get_absolute_url()) | ||
assert response.status_code == 404 | ||
|
||
dummy_user.is_superuser = True | ||
dummy_user.save() | ||
response = client.get(document_portal.get_absolute_url()) | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_portal_detail_slug_behavior(client): | ||
bad_slug_url = reverse( | ||
"filingcabinet:document-portal", | ||
kwargs={"slug": "bad"}, | ||
) | ||
response = client.get(bad_slug_url) | ||
assert response.status_code == 404 |
This file was deleted.
Oops, something went wrong.