2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
2018-06-15 20:56:36 +02:00
|
|
|
|
|
|
|
class ZcommandTest(ZulipTestCase):
|
|
|
|
|
|
|
|
def test_invalid_zcommand(self) -> None:
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login('hamlet')
|
2018-06-15 20:56:36 +02:00
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/boil-ocean")
|
2018-06-15 20:56:36 +02:00
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_error(result, "No such command: boil-ocean")
|
|
|
|
|
2018-06-21 19:23:35 +02:00
|
|
|
payload = dict(command="boil-ocean")
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_error(result, "There should be a leading slash in the zcommand.")
|
|
|
|
|
2018-06-15 20:56:36 +02:00
|
|
|
def test_ping_zcommand(self) -> None:
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login('hamlet')
|
2018-06-15 20:56:36 +02:00
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/ping")
|
2018-06-15 20:56:36 +02:00
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
def test_night_zcommand(self) -> None:
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login('hamlet')
|
2018-06-15 20:56:36 +02:00
|
|
|
user = self.example_user('hamlet')
|
|
|
|
user.night_mode = False
|
|
|
|
user.save()
|
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/night")
|
2018-06-15 20:56:36 +02:00
|
|
|
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:
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login('hamlet')
|
2018-06-15 20:56:36 +02:00
|
|
|
user = self.example_user('hamlet')
|
|
|
|
user.night_mode = True
|
|
|
|
user.save()
|
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/day")
|
2018-06-15 20:56:36 +02:00
|
|
|
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'])
|
2020-03-12 07:51:47 +01:00
|
|
|
|
|
|
|
def test_fluid_zcommand(self) -> None:
|
|
|
|
self.login("hamlet")
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
user.fluid_layout_width = False
|
|
|
|
user.save()
|
|
|
|
|
|
|
|
payload = dict(command="/fluid-width")
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assert_in_response('Changed to fluid-width mode!', result)
|
|
|
|
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assert_in_response('You are still in fluid width mode', result)
|
|
|
|
|
|
|
|
def test_fixed_zcommand(self) -> None:
|
|
|
|
self.login("hamlet")
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
user.fluid_layout_width = True
|
|
|
|
user.save()
|
|
|
|
|
|
|
|
payload = dict(command="/fixed-width")
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assert_in_response('Changed to fixed-width mode!', result)
|
|
|
|
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assert_in_response('You are still in fixed width mode', result)
|