Files
zulip/zerver/tests/test_zcommand.py
Rhea Parekh d0bc8d0736 zcommands: Add zcommand module and separate test module.
Move the zcommands from '/views/messages.py' to
'/lib/zcommand'.

Also, move the zcommand tests from '/tests/test_messages.py'
to '/tests/test_zcommand'.
2018-06-16 10:32:42 -04:00

52 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
from zerver.lib.test_classes import (
ZulipTestCase,
)
class ZcommandTest(ZulipTestCase):
def test_invalid_zcommand(self) -> None:
self.login(self.example_email("hamlet"))
payload = dict(command="boil-ocean")
result = self.client_post("/json/zcommand", payload)
self.assert_json_error(result, "No such command: boil-ocean")
def test_ping_zcommand(self) -> None:
self.login(self.example_email("hamlet"))
payload = dict(command="ping")
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
def test_night_zcommand(self) -> None:
self.login(self.example_email("hamlet"))
user = self.example_user('hamlet')
user.night_mode = False
user.save()
payload = dict(command="night")
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('Changed to night', result.json()['msg'])
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('still in night mode', result.json()['msg'])
def test_day_zcommand(self) -> None:
self.login(self.example_email("hamlet"))
user = self.example_user('hamlet')
user.night_mode = True
user.save()
payload = dict(command="day")
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('Changed to day', result.json()['msg'])
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('still in day mode', result.json()['msg'])