diff --git a/conservancy/tests.py b/conservancy/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..43b46528933df6eed684e3c4cdd1d9bf77e87229 --- /dev/null +++ b/conservancy/tests.py @@ -0,0 +1,36 @@ +import datetime + +from django.http import Http404 +from django.test import RequestFactory, TestCase + +from . import views +from conservancy.fundgoal.models import FundraisingGoal + + +class ContentTest(TestCase): + def setUp(self): + self.factory = RequestFactory() + 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) + ) + + def test_about_page_served(self): + request = self.factory.get('/about/') + with self.assertTemplateUsed('about/index.html'): + response = views.index(request).render() + self.assertContains(response, 'Conservancy is a nonprofit organization') + + def test_annual_report_file_served(self): + request = self.factory.get('/docs/conservancy_annual-report_fy-2011.pdf') + response = views.index(request) + self.assertEqual(response.headers['Content-Type'], 'application/pdf') + + def test_path_traversal_404s(self): + request = self.factory.get('/about/../../settings.py') + with self.assertRaises(Http404): + views.index(request)