Files
zulip/zerver/tests/test_hotspots.py
Anders Kaseorg 365fe0b3d5 python: Sort imports with isort.
Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 16:45:32 -07:00

61 lines
2.7 KiB
Python

import ujson
from zerver.lib.actions import do_create_user, do_mark_hotspot_as_read
from zerver.lib.hotspots import ALL_HOTSPOTS, get_next_hotspots
from zerver.lib.test_classes import ZulipTestCase
from zerver.models import UserHotspot, UserProfile, get_realm
# Splitting this out, since I imagine this will eventually have most of the
# complicated hotspots logic.
class TestGetNextHotspots(ZulipTestCase):
def setUp(self) -> None:
super().setUp()
self.user = do_create_user(
'user@zulip.com', 'password', get_realm('zulip'), 'user', 'user')
def test_first_hotspot(self) -> None:
hotspots = get_next_hotspots(self.user)
self.assertEqual(len(hotspots), 1)
self.assertEqual(hotspots[0]['name'], 'intro_reply')
def test_some_done_some_not(self) -> None:
do_mark_hotspot_as_read(self.user, 'intro_reply')
do_mark_hotspot_as_read(self.user, 'intro_compose')
hotspots = get_next_hotspots(self.user)
self.assertEqual(len(hotspots), 1)
self.assertEqual(hotspots[0]['name'], 'intro_streams')
def test_all_done(self) -> None:
self.assertNotEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
for hotspot in ALL_HOTSPOTS:
do_mark_hotspot_as_read(self.user, hotspot)
self.assertEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
self.assertEqual(get_next_hotspots(self.user), [])
def test_send_all(self) -> None:
with self.settings(DEVELOPMENT=True, ALWAYS_SEND_ALL_HOTSPOTS = True):
self.assertEqual(len(ALL_HOTSPOTS), len(get_next_hotspots(self.user)))
class TestHotspots(ZulipTestCase):
def test_do_mark_hotspot_as_read(self) -> None:
user = self.example_user('hamlet')
do_mark_hotspot_as_read(user, 'intro_compose')
self.assertEqual(list(UserHotspot.objects.filter(user=user)
.values_list('hotspot', flat=True)), ['intro_compose'])
def test_hotspots_url_endpoint(self) -> None:
user = self.example_user('hamlet')
self.login_user(user)
result = self.client_post('/json/users/me/hotspots',
{'hotspot': ujson.dumps('intro_reply')})
self.assert_json_success(result)
self.assertEqual(list(UserHotspot.objects.filter(user=user)
.values_list('hotspot', flat=True)), ['intro_reply'])
result = self.client_post('/json/users/me/hotspots',
{'hotspot': ujson.dumps('invalid')})
self.assert_json_error(result, "Unknown hotspot: invalid")
self.assertEqual(list(UserHotspot.objects.filter(user=user)
.values_list('hotspot', flat=True)), ['intro_reply'])