2018-06-15 20:56:36 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from zerver.lib.test_classes import (
|
|
|
|
ZulipTestCase,
|
|
|
|
)
|
|
|
|
|
|
|
|
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'])
|