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)
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
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."""
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)