chore: Bump copyright year
[mailman-postorious.git] / src / postorius / tests / mailman_api_tests / test_generic_view.py
blob41d22df1d8b70fdc38b88020469f8bebb783c6bd
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2018-2023 by the Free Software Foundation, Inc.
4 # This file is part of Postorius.
6 # Postorius is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option)
9 # any later version.
11 # Postorius is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Postorius. If not, see <http://www.gnu.org/licenses/>.
20 from django.contrib.auth.models import AnonymousUser
21 from django.http import HttpResponse
22 from django.test import RequestFactory, TestCase
24 from postorius.views.generic import MailingListView
27 class TestGenericView(TestCase):
28 """Test generic view adds templates and Mailing List."""
30 def setUp(self):
31 # We first create a test view that is based on the MailingListView.
32 # This view only implements a POST and no GET.
33 class TestView(MailingListView):
34 def post(self, request):
35 return HttpResponse(status=200)
37 self.view = TestView.as_view()
38 self.factory = RequestFactory()
40 def test_no_GET_in_view(self):
41 request = self.factory.post('/')
42 request.user = AnonymousUser()
43 # Since out view implements a POST, we shouldn't get an ERROR here.
44 response = self.view(request)
45 self.assertEqual(response.status_code, 200)
46 # Now, let's try a GET request.
47 request = self.factory.get('/')
48 request.user = AnonymousUser()
49 # We shouldn't a ImproperlyConfigured error with GET but 405 error.
50 response = self.view(request)
51 self.assertEqual(response.status_code, 405)