mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-25 01:20:35 +00:00
Merge pull request #573 from mouse-reeve/views-tests
Make sure templates render rather than checking template paths
This commit is contained in:
commit
7dea363061
15 changed files with 56 additions and 41 deletions
|
@ -33,7 +33,7 @@ class AuthenticationViews(TestCase):
|
|||
|
||||
result = login(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'login.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
request.user = self.local_user
|
||||
|
@ -94,7 +94,7 @@ class AuthenticationViews(TestCase):
|
|||
})
|
||||
response = view(request)
|
||||
self.assertEqual(models.User.objects.count(), 1)
|
||||
self.assertEqual(response.template_name, 'login.html')
|
||||
response.render()
|
||||
|
||||
def test_register_invalid_username(self):
|
||||
''' gotta have an email '''
|
||||
|
@ -109,7 +109,7 @@ class AuthenticationViews(TestCase):
|
|||
})
|
||||
response = view(request)
|
||||
self.assertEqual(models.User.objects.count(), 1)
|
||||
self.assertEqual(response.template_name, 'login.html')
|
||||
response.render()
|
||||
|
||||
request = self.factory.post(
|
||||
'register/',
|
||||
|
@ -120,7 +120,7 @@ class AuthenticationViews(TestCase):
|
|||
})
|
||||
response = view(request)
|
||||
self.assertEqual(models.User.objects.count(), 1)
|
||||
self.assertEqual(response.template_name, 'login.html')
|
||||
response.render()
|
||||
|
||||
request = self.factory.post(
|
||||
'register/',
|
||||
|
@ -131,7 +131,7 @@ class AuthenticationViews(TestCase):
|
|||
})
|
||||
response = view(request)
|
||||
self.assertEqual(models.User.objects.count(), 1)
|
||||
self.assertEqual(response.template_name, 'login.html')
|
||||
response.render()
|
||||
|
||||
|
||||
def test_register_closed_instance(self):
|
||||
|
|
|
@ -34,6 +34,7 @@ class AuthorViews(TestCase):
|
|||
remote_id='https://example.com/book/1',
|
||||
parent_work=self.work
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_author_page(self):
|
||||
|
@ -45,7 +46,8 @@ class AuthorViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, author.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'author.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
request = self.factory.get('')
|
||||
|
@ -66,7 +68,8 @@ class AuthorViews(TestCase):
|
|||
|
||||
result = view(request, author.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'edit_author.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -116,4 +119,5 @@ class AuthorViews(TestCase):
|
|||
resp = view(request, author.id)
|
||||
author.refresh_from_db()
|
||||
self.assertEqual(author.name, 'Test Author')
|
||||
self.assertEqual(resp.template_name, 'edit_author.html')
|
||||
resp.render()
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
|
|
@ -23,6 +23,7 @@ class BlockViews(TestCase):
|
|||
inbox='https://example.com/users/rat/inbox',
|
||||
outbox='https://example.com/users/rat/outbox',
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_block_get(self):
|
||||
|
@ -32,7 +33,7 @@ class BlockViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'preferences/blocks.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_block_post(self):
|
||||
|
|
|
@ -33,6 +33,7 @@ class BookViews(TestCase):
|
|||
remote_id='https://example.com/book/1',
|
||||
parent_work=self.work
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_book_page(self):
|
||||
|
@ -44,7 +45,7 @@ class BookViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, self.book.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'book.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
request = self.factory.get('')
|
||||
|
@ -63,7 +64,7 @@ class BookViews(TestCase):
|
|||
request.user.is_superuser = True
|
||||
result = view(request, self.book.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'edit_book.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -116,7 +117,7 @@ class BookViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, self.work.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'editions.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
request = self.factory.get('')
|
||||
|
|
|
@ -15,6 +15,7 @@ class FederationViews(TestCase):
|
|||
self.local_user = models.User.objects.create_user(
|
||||
'mouse@local.com', 'mouse@mouse.mouse', 'password',
|
||||
local=True, localname='mouse')
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_federation_page(self):
|
||||
|
@ -25,5 +26,5 @@ class FederationViews(TestCase):
|
|||
request.user.is_superuser = True
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'settings/federation.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
|
|
@ -21,6 +21,7 @@ class FeedMessageViews(TestCase):
|
|||
title='Example Edition',
|
||||
remote_id='https://example.com/book/1',
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_feed(self):
|
||||
|
@ -30,7 +31,7 @@ class FeedMessageViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request, 'local')
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/feed.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -45,7 +46,7 @@ class FeedMessageViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/status.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.feed.is_api_request') as is_api:
|
||||
|
@ -66,7 +67,7 @@ class FeedMessageViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, 'mouse', status.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/status.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.feed.is_api_request') as is_api:
|
||||
|
@ -83,7 +84,7 @@ class FeedMessageViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'feed/direct_messages.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ class ImportViews(TestCase):
|
|||
self.local_user = models.User.objects.create_user(
|
||||
'mouse@local.com', 'mouse@mouse.mouse', 'password',
|
||||
local=True, localname='mouse')
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_import_page(self):
|
||||
|
@ -25,7 +26,7 @@ class ImportViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'import.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -39,5 +40,5 @@ class ImportViews(TestCase):
|
|||
async_result.return_value = []
|
||||
result = view(request, import_job.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'import_status.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
|
|
@ -18,6 +18,7 @@ class InviteViews(TestCase):
|
|||
self.local_user = models.User.objects.create_user(
|
||||
'mouse@local.com', 'mouse@mouse.mouse', 'password',
|
||||
local=True, localname='mouse')
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_invite_page(self):
|
||||
|
@ -32,7 +33,7 @@ class InviteViews(TestCase):
|
|||
invite.return_value = True
|
||||
result = view(request, 'hi')
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'invite.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -44,5 +45,5 @@ class InviteViews(TestCase):
|
|||
request.user.is_superuser = True
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'settings/manage_invites.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
|
|
@ -18,6 +18,7 @@ class LandingViews(TestCase):
|
|||
local=True, localname='mouse')
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_home_page(self):
|
||||
|
@ -27,13 +28,13 @@ class LandingViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.template_name, 'feed/feed.html')
|
||||
result.render()
|
||||
|
||||
request.user = self.anonymous_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.template_name, 'discover.html')
|
||||
result.render()
|
||||
|
||||
|
||||
def test_about_page(self):
|
||||
|
@ -43,7 +44,7 @@ class LandingViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'about.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -53,5 +54,3 @@ class LandingViews(TestCase):
|
|||
request = self.factory.get('')
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'discover.html')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
|
|
@ -15,6 +15,7 @@ class NotificationViews(TestCase):
|
|||
self.local_user = models.User.objects.create_user(
|
||||
'mouse@local.com', 'mouse@mouse.mouse', 'password',
|
||||
local=True, localname='mouse')
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_notifications_page(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
|
@ -23,7 +24,7 @@ class NotificationViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'notifications.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_clear_notifications(self):
|
||||
|
|
|
@ -19,6 +19,7 @@ class PasswordViews(TestCase):
|
|||
local=True, localname='mouse')
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create(id=1)
|
||||
|
||||
|
||||
def test_password_reset_request(self):
|
||||
|
@ -29,7 +30,7 @@ class PasswordViews(TestCase):
|
|||
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'password_reset_request.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -43,7 +44,7 @@ class PasswordViews(TestCase):
|
|||
request = self.factory.post('', {'email': 'mouse@mouse.com'})
|
||||
with patch('bookwyrm.emailing.send_email.delay'):
|
||||
resp = view(request)
|
||||
self.assertEqual(resp.template_name, 'password_reset_request.html')
|
||||
resp.render()
|
||||
|
||||
self.assertEqual(
|
||||
models.PasswordReset.objects.get().user, self.local_user)
|
||||
|
@ -56,7 +57,7 @@ class PasswordViews(TestCase):
|
|||
request.user = self.anonymous_user
|
||||
result = view(request, code.code)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'password_reset.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
@ -82,7 +83,7 @@ class PasswordViews(TestCase):
|
|||
'confirm-password': 'hi'
|
||||
})
|
||||
resp = view(request, 'jhgdkfjgdf')
|
||||
self.assertEqual(resp.template_name, 'password_reset.html')
|
||||
resp.render()
|
||||
self.assertTrue(models.PasswordReset.objects.exists())
|
||||
|
||||
def test_password_reset_mismatch(self):
|
||||
|
@ -94,7 +95,7 @@ class PasswordViews(TestCase):
|
|||
'confirm-password': 'hihi'
|
||||
})
|
||||
resp = view(request, code.code)
|
||||
self.assertEqual(resp.template_name, 'password_reset.html')
|
||||
resp.render()
|
||||
self.assertTrue(models.PasswordReset.objects.exists())
|
||||
|
||||
|
||||
|
@ -106,7 +107,7 @@ class PasswordViews(TestCase):
|
|||
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'preferences/change_password.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ class ShelfViews(TestCase):
|
|||
connector_file='self_connector',
|
||||
local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_search_json_response(self):
|
||||
|
@ -89,7 +90,7 @@ class ShelfViews(TestCase):
|
|||
manager.return_value = [search_result]
|
||||
response = view(request)
|
||||
self.assertIsInstance(response, TemplateResponse)
|
||||
self.assertEqual(response.template_name, 'search_results.html')
|
||||
response.render()
|
||||
self.assertEqual(
|
||||
response.context_data['book_results'][0].title, 'Gideon the Ninth')
|
||||
|
||||
|
@ -103,6 +104,6 @@ class ShelfViews(TestCase):
|
|||
with patch('bookwyrm.connectors.connector_manager.search'):
|
||||
response = view(request)
|
||||
self.assertIsInstance(response, TemplateResponse)
|
||||
self.assertEqual(response.template_name, 'search_results.html')
|
||||
response.render()
|
||||
self.assertEqual(
|
||||
response.context_data['user_results'][0], self.local_user)
|
||||
|
|
|
@ -29,6 +29,7 @@ class ShelfViews(TestCase):
|
|||
identifier='test-shelf',
|
||||
user=self.local_user
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_shelf_page(self):
|
||||
|
@ -41,7 +42,7 @@ class ShelfViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, self.local_user.username, shelf.identifier)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'user/shelf.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.shelf.is_api_request') as is_api:
|
||||
|
|
|
@ -33,6 +33,7 @@ class TagViews(TestCase):
|
|||
remote_id='https://example.com/book/1',
|
||||
parent_work=self.work
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_tag_page(self):
|
||||
|
@ -46,7 +47,7 @@ class TagViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, tag.identifier)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'tag.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
request = self.factory.get('')
|
||||
|
|
|
@ -23,6 +23,7 @@ class UserViews(TestCase):
|
|||
self.rat = models.User.objects.create_user(
|
||||
'rat@local.com', 'rat@rat.rat', 'password',
|
||||
local=True, localname='rat')
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
||||
def test_user_page(self):
|
||||
|
@ -34,7 +35,7 @@ class UserViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, 'mouse')
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'user/user.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.user.is_api_request') as is_api:
|
||||
|
@ -65,7 +66,7 @@ class UserViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, 'mouse')
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'user/followers.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.user.is_api_request') as is_api:
|
||||
|
@ -96,7 +97,7 @@ class UserViews(TestCase):
|
|||
is_api.return_value = False
|
||||
result = view(request, 'mouse')
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'user/following.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
with patch('bookwyrm.views.user.is_api_request') as is_api:
|
||||
|
@ -125,7 +126,7 @@ class UserViews(TestCase):
|
|||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
self.assertEqual(result.template_name, 'preferences/edit_user.html')
|
||||
result.render()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue