Files
@ 1a5441ba7518
Branch filter:
Location: website/conservancy/tests.py - annotation
1a5441ba7518
1.8 KiB
text/x-python
Fix tests
These were failing due to pytest defaulting to `DEBUG = False` (and then getting
`ValueError: Missing staticfiles manifest entry for ...`).
These were failing due to pytest defaulting to `DEBUG = False` (and then getting
`ValueError: Missing staticfiles manifest entry for ...`).
94c56bb468cb 94c56bb468cb cba71044a243 94c56bb468cb daf93dc32b26 1792c7ed8be5 94c56bb468cb 94c56bb468cb 94c56bb468cb 94c56bb468cb 94c56bb468cb daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d 97b60b44f50d daf93dc32b26 97b60b44f50d daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 1792c7ed8be5 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 1792c7ed8be5 1792c7ed8be5 daf93dc32b26 daf93dc32b26 daf93dc32b26 daf93dc32b26 661603c3be88 1792c7ed8be5 661603c3be88 daf93dc32b26 1792c7ed8be5 31fa3694ea12 31fa3694ea12 31fa3694ea12 31fa3694ea12 31fa3694ea12 31fa3694ea12 | import datetime
from django.conf import settings
from django.http import Http404
import pytest
from pytest_django.asserts import assertContains
from . import views
from conservancy.fundgoal.models import FundraisingGoal
def create_fundraising_goal():
FundraisingGoal.objects.create(
fundraiser_code_name='cy2023-end-year-match',
fundraiser_goal_amount=0,
fundraiser_so_far_amount=0,
fundraiser_donation_count=0,
fundraiser_donation_count_disclose_threshold=0,
fundraiser_endtime=datetime.datetime(2000, 1, 1)
)
# Simple smoke tests to make sure the essential pages on the site are working.
get_200_ok_test_data = [
'/',
'/news/',
'/blog/',
'/sustainer/',
]
@pytest.mark.parametrize('url', get_200_ok_test_data)
@pytest.mark.django_db
def test_get_200_ok(url, client):
response = client.get(url)
assert response.status_code == 200
# Tests for the template/file content serving functionality.
@pytest.mark.django_db
def test_about_page_served(rf):
create_fundraising_goal()
request = rf.get('/about/')
response = views.content(request)
assertContains(response, 'Conservancy is a nonprofit organization')
def test_annual_report_file_served(rf):
request = rf.get('/projects/apply/ConservancyFSATemplate.pdf')
response = views.content(request)
assert response.headers['Content-Type'] == 'application/pdf'
def test_path_traversal_404s(rf):
# Will work in development only
assert (settings.BASE_DIR / 'content' / 'about/../../../conservancy-website.sqlite3').exists()
request = rf.get('/about/../../../conservancy-website.sqlite3')
with pytest.raises(Http404):
views.content(request)
def test_long_path_404s(rf):
request = rf.get('x' * 1000)
with pytest.raises(Http404):
views.content(request)
|