2019-07-15 21:29:47 +02:00
|
|
|
from django.conf import settings
|
2016-09-15 18:45:04 +02:00
|
|
|
|
2019-07-15 21:29:47 +02:00
|
|
|
from zerver.lib.actions import internal_send_private_message
|
2017-09-27 19:43:28 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
from zerver.lib.test_helpers import message_stream_count, most_recent_message
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.models import UserProfile, get_system_bot
|
2017-09-27 19:43:28 +02:00
|
|
|
|
2016-09-15 18:45:04 +02:00
|
|
|
|
|
|
|
class TutorialTests(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def setUp(self) -> None:
|
2019-10-19 20:47:00 +02:00
|
|
|
super().setUp()
|
2017-09-27 19:43:28 +02:00
|
|
|
# This emulates the welcome message sent by the welcome bot to hamlet@zulip.com
|
|
|
|
# This is only a quick fix - ideally, we would have this message sent by the initialization
|
|
|
|
# code in populate_db.py
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2019-07-15 21:29:47 +02:00
|
|
|
welcome_bot = get_system_bot(settings.WELCOME_BOT)
|
2021-02-12 08:20:45 +01:00
|
|
|
content = "Shortened welcome message."
|
2021-02-18 19:58:04 +01:00
|
|
|
internal_send_private_message(welcome_bot, user, content)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_tutorial_status(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2016-09-15 18:45:04 +02:00
|
|
|
|
|
|
|
cases = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("started", UserProfile.TUTORIAL_STARTED),
|
|
|
|
("finished", UserProfile.TUTORIAL_FINISHED),
|
2016-09-15 18:45:04 +02:00
|
|
|
]
|
|
|
|
for incoming_status, expected_db_status in cases:
|
2021-05-04 16:59:17 +02:00
|
|
|
params = dict(status=incoming_status)
|
2021-02-12 08:20:45 +01:00
|
|
|
result = self.client_post("/json/users/me/tutorial_status", params)
|
2016-09-15 18:45:04 +02:00
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2016-09-15 18:45:04 +02:00
|
|
|
self.assertEqual(user.tutorial_status, expected_db_status)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_single_response_to_pm(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2020-03-07 11:43:05 +01:00
|
|
|
bot = get_system_bot(settings.WELCOME_BOT)
|
2021-02-12 08:20:45 +01:00
|
|
|
content = "whatever"
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2020-03-07 11:43:05 +01:00
|
|
|
self.send_personal_message(user, bot, content)
|
2017-09-27 19:43:28 +02:00
|
|
|
user_messages = message_stream_count(user)
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_response = (
|
|
|
|
"Congratulations on your first reply! :tada:\n\n"
|
|
|
|
"Feel free to continue using this space to practice your new messaging "
|
|
|
|
"skills. Or, try clicking on some of the stream names to your left!"
|
|
|
|
)
|
2017-09-27 19:43:28 +02:00
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
# Welcome bot shouldn't respond to further PMs.
|
2020-03-07 11:43:05 +01:00
|
|
|
self.send_personal_message(user, bot, content)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(message_stream_count(user), user_messages + 1)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_no_response_to_group_pm(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
user1 = self.example_user("hamlet")
|
|
|
|
user2 = self.example_user("cordelia")
|
2020-03-07 11:43:05 +01:00
|
|
|
bot = get_system_bot(settings.WELCOME_BOT)
|
2017-09-27 19:43:28 +02:00
|
|
|
content = "whatever"
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user1)
|
2020-03-07 11:43:05 +01:00
|
|
|
self.send_huddle_message(user1, [bot, user2], content)
|
2017-09-27 19:43:28 +02:00
|
|
|
user1_messages = message_stream_count(user1)
|
|
|
|
self.assertEqual(most_recent_message(user1).content, content)
|
|
|
|
# Welcome bot should still respond to initial PM after group PM.
|
2020-03-07 11:43:05 +01:00
|
|
|
self.send_personal_message(user1, bot, content)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(message_stream_count(user1), user1_messages + 2)
|