mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 05:53:43 +00:00
test-backend: Raise zerver/views/home.py test coverage to 100%.
This commit is contained in:
@@ -85,8 +85,6 @@ not_yet_fully_covered = {
|
||||
# Test files should have full coverage; it's a bug in the test if
|
||||
# they don't! There are open issues for all of these.
|
||||
'zerver/tests/test_tornado.py',
|
||||
# Getting views file coverage to 100% is a major project goal
|
||||
'zerver/views/home.py',
|
||||
}
|
||||
|
||||
enforce_fully_covered = sorted(target_fully_covered - not_yet_fully_covered)
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import ujson
|
||||
|
||||
from django.http import HttpResponse
|
||||
from mock import patch
|
||||
from mock import MagicMock, patch
|
||||
from six.moves import urllib
|
||||
from typing import Any, Dict
|
||||
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.test_runner import slow
|
||||
from zerver.models import get_realm, get_stream, get_user_profile_by_email
|
||||
from zerver.views.home import home, sent_time_in_epoch_seconds
|
||||
|
||||
class HomeTest(ZulipTestCase):
|
||||
@slow('big method')
|
||||
@@ -232,6 +235,36 @@ class HomeTest(ZulipTestCase):
|
||||
html = result.content.decode('utf-8')
|
||||
self.assertIn('There are new Terms of Service', html)
|
||||
|
||||
def test_terms_of_service_first_time_template(self):
|
||||
# type: () -> None
|
||||
email = "hamlet@zulip.com"
|
||||
self.login(email)
|
||||
|
||||
user = get_user_profile_by_email(email)
|
||||
user.tos_version = None
|
||||
user.save()
|
||||
|
||||
with \
|
||||
self.settings(FIRST_TIME_TOS_TEMPLATE='hello.html'), \
|
||||
self.settings(TOS_VERSION='99.99'):
|
||||
result = self.client_post('/accounts/accept_terms/')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assert_in_response("I agree to the", result)
|
||||
self.assert_in_response("Finally, workplace chat", result)
|
||||
|
||||
def test_accept_terms_of_service(self):
|
||||
# type: () -> None
|
||||
email = "hamlet@zulip.com"
|
||||
self.login(email)
|
||||
|
||||
result = self.client_post('/accounts/accept_terms/')
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assert_in_response("I agree to the", result)
|
||||
|
||||
result = self.client_post('/accounts/accept_terms/', {'terms': True})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(result['Location'], '/')
|
||||
|
||||
def test_bad_narrow(self):
|
||||
# type: () -> None
|
||||
email = 'hamlet@zulip.com'
|
||||
@@ -360,3 +393,34 @@ class HomeTest(ZulipTestCase):
|
||||
self.login(email)
|
||||
result = self.client_get("/api/v1/generate_204")
|
||||
self.assertEqual(result.status_code, 204)
|
||||
|
||||
def test_message_sent_time(self):
|
||||
# type: () -> None
|
||||
epoch_seconds = 1490472096
|
||||
pub_date = datetime.datetime.fromtimestamp(epoch_seconds)
|
||||
user_message = MagicMock()
|
||||
user_message.message.pub_date = pub_date
|
||||
self.assertEqual(sent_time_in_epoch_seconds(user_message), epoch_seconds)
|
||||
|
||||
def test_handlebars_compile_error(self):
|
||||
# type: () -> None
|
||||
request = MagicMock()
|
||||
with self.settings(DEVELOPMENT=True):
|
||||
with patch('os.path.exists', return_value=True):
|
||||
result = home(request)
|
||||
self.assertEqual(result.status_code, 500)
|
||||
self.assert_in_response('Error compiling handlebars templates.', result)
|
||||
|
||||
def test_subdomain_homepage(self):
|
||||
# type: () -> None
|
||||
email = 'hamlet@zulip.com'
|
||||
self.login(email)
|
||||
with self.settings(SUBDOMAINS_HOMEPAGE=True):
|
||||
with patch('zerver.views.home.get_subdomain', return_value=""):
|
||||
result = self._get_home_page()
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assert_in_response('Finally, workplace chat', result)
|
||||
|
||||
with patch('zerver.views.home.get_subdomain', return_value="subdomain"):
|
||||
result = self._get_home_page()
|
||||
self._sanity_check(result)
|
||||
|
||||
Reference in New Issue
Block a user