Another test case for the user view

This commit is contained in:
Mouse Reeve 2021-02-10 18:01:11 -08:00
parent e918ddf526
commit b898f263b7

View file

@ -3,6 +3,7 @@ import pathlib
from unittest.mock import patch from unittest.mock import patch
from PIL import Image from PIL import Image
from django.contrib.auth.models import AnonymousUser
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.test import TestCase from django.test import TestCase
@ -24,6 +25,8 @@ class UserViews(TestCase):
'rat@local.com', 'rat@rat.rat', 'password', 'rat@local.com', 'rat@rat.rat', 'password',
local=True, localname='rat') local=True, localname='rat')
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False
def test_user_page(self): def test_user_page(self):
@ -38,6 +41,14 @@ class UserViews(TestCase):
result.render() result.render()
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
request.user = self.anonymous_user
with patch('bookwyrm.views.user.is_api_request') as is_api:
is_api.return_value = False
result = view(request, 'mouse')
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(result.status_code, 200)
with patch('bookwyrm.views.user.is_api_request') as is_api: with patch('bookwyrm.views.user.is_api_request') as is_api:
is_api.return_value = True is_api.return_value = True
result = view(request, 'mouse') result = view(request, 'mouse')