2018-04-27 15:48:55 +02:00
|
|
|
from django.http import HttpResponse
|
2020-06-11 00:54:34 +02:00
|
|
|
|
|
|
|
from zerver.lib.actions import (
|
|
|
|
do_change_stream_web_public,
|
|
|
|
do_deactivate_stream,
|
|
|
|
get_web_public_streams,
|
|
|
|
get_web_public_subs,
|
|
|
|
)
|
2018-04-27 15:48:55 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2018-05-08 21:01:34 +02:00
|
|
|
from zerver.models import get_realm
|
2018-04-27 15:48:55 +02:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-04-27 15:48:55 +02:00
|
|
|
class GlobalPublicStreamTest(ZulipTestCase):
|
|
|
|
def test_non_existant_stream_id(self) -> None:
|
2020-03-28 01:25:56 +01:00
|
|
|
# Here we use a relatively big number as stream id assuming such an id
|
2018-04-27 15:48:55 +02:00
|
|
|
# won't exist in the test DB.
|
2018-07-12 10:27:14 +02:00
|
|
|
result = self.client_get("/archive/streams/100000000/topics/TopicGlobal")
|
2018-05-02 20:08:10 +02:00
|
|
|
self.assert_in_success_response(["This stream does not exist."], result)
|
2018-04-27 15:48:55 +02:00
|
|
|
|
|
|
|
def test_non_web_public_stream(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
test_stream = self.make_stream("Test Public Archives")
|
2018-04-27 15:48:55 +02:00
|
|
|
result = self.client_get(
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"/archive/streams/" + str(test_stream.id) + "/topics/notpublicglobalstream",
|
2018-04-27 15:48:55 +02:00
|
|
|
)
|
|
|
|
self.assert_in_success_response(["This stream does not exist."], result)
|
|
|
|
|
|
|
|
def test_non_existant_topic(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
test_stream = self.make_stream("Test Public Archives")
|
2018-04-27 15:48:55 +02:00
|
|
|
do_change_stream_web_public(test_stream, True)
|
|
|
|
result = self.client_get(
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"/archive/streams/" + str(test_stream.id) + "/topics/nonexistenttopic",
|
2018-04-27 15:48:55 +02:00
|
|
|
)
|
|
|
|
self.assert_in_success_response(["This topic does not exist."], result)
|
|
|
|
|
|
|
|
def test_web_public_stream_topic(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
test_stream = self.make_stream("Test Public Archives")
|
2018-04-27 15:48:55 +02:00
|
|
|
do_change_stream_web_public(test_stream, True)
|
|
|
|
|
|
|
|
def send_msg_and_get_result(msg: str) -> HttpResponse:
|
|
|
|
self.send_stream_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user("iago"),
|
2018-04-27 15:48:55 +02:00
|
|
|
"Test Public Archives",
|
|
|
|
msg,
|
2021-02-12 08:20:45 +01:00
|
|
|
"TopicGlobal",
|
2018-04-27 15:48:55 +02:00
|
|
|
)
|
|
|
|
return self.client_get(
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"/archive/streams/" + str(test_stream.id) + "/topics/TopicGlobal",
|
2018-04-27 15:48:55 +02:00
|
|
|
)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = send_msg_and_get_result("Test Message 1")
|
2018-04-27 15:48:55 +02:00
|
|
|
self.assert_in_success_response(["Test Message 1"], result)
|
2021-02-12 08:20:45 +01:00
|
|
|
result = send_msg_and_get_result("/me goes testing.")
|
2018-04-27 15:48:55 +02:00
|
|
|
self.assert_in_success_response(["goes testing."], result)
|
2018-05-08 21:01:34 +02:00
|
|
|
|
|
|
|
def test_get_web_public_streams(self) -> None:
|
|
|
|
realm = get_realm("zulip")
|
|
|
|
public_streams = get_web_public_streams(realm)
|
|
|
|
self.assert_length(public_streams, 1)
|
|
|
|
public_stream = public_streams[0]
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(public_stream["name"], "Rome")
|
2018-05-08 21:01:34 +02:00
|
|
|
|
2021-01-14 21:44:56 +01:00
|
|
|
info = get_web_public_subs(realm)
|
|
|
|
self.assert_length(info.subscriptions, 1)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(info.subscriptions[0]["name"], "Rome")
|
2021-01-14 21:44:56 +01:00
|
|
|
self.assert_length(info.unsubscribed, 0)
|
|
|
|
self.assert_length(info.never_subscribed, 0)
|
2018-05-08 21:01:34 +02:00
|
|
|
|
|
|
|
# Now add a second public stream
|
2021-02-12 08:20:45 +01:00
|
|
|
test_stream = self.make_stream("Test Public Archives")
|
2018-05-08 21:01:34 +02:00
|
|
|
do_change_stream_web_public(test_stream, True)
|
|
|
|
public_streams = get_web_public_streams(realm)
|
|
|
|
self.assert_length(public_streams, 2)
|
2021-01-14 21:44:56 +01:00
|
|
|
info = get_web_public_subs(realm)
|
|
|
|
self.assert_length(info.subscriptions, 2)
|
|
|
|
self.assert_length(info.unsubscribed, 0)
|
|
|
|
self.assert_length(info.never_subscribed, 0)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertNotEqual(info.subscriptions[0]["color"], info.subscriptions[1]["color"])
|
2018-05-08 21:01:34 +02:00
|
|
|
|
|
|
|
do_deactivate_stream(test_stream)
|
|
|
|
public_streams = get_web_public_streams(realm)
|
|
|
|
self.assert_length(public_streams, 1)
|
2021-01-14 21:44:56 +01:00
|
|
|
info = get_web_public_subs(realm)
|
|
|
|
self.assert_length(info.subscriptions, 1)
|
|
|
|
self.assert_length(info.unsubscribed, 0)
|
|
|
|
self.assert_length(info.never_subscribed, 0)
|
2018-06-14 00:44:22 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-06-14 00:44:22 +02:00
|
|
|
class WebPublicTopicHistoryTest(ZulipTestCase):
|
|
|
|
def test_non_existant_stream_id(self) -> None:
|
|
|
|
result = self.client_get("/archive/streams/100000000/topics")
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
history = result.json()["topics"]
|
2018-06-14 00:44:22 +02:00
|
|
|
self.assertEqual(history, [])
|
|
|
|
|
|
|
|
def test_non_web_public_stream(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
test_stream = self.make_stream("Test Public Archives")
|
2018-06-14 00:44:22 +02:00
|
|
|
|
|
|
|
self.send_stream_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user("iago"),
|
2018-06-14 00:44:22 +02:00
|
|
|
"Test Public Archives",
|
2021-02-12 08:20:45 +01:00
|
|
|
"Test Message",
|
|
|
|
"TopicGlobal",
|
2018-06-14 00:44:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
result = self.client_get(
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"/archive/streams/" + str(test_stream.id) + "/topics",
|
2018-06-14 00:44:22 +02:00
|
|
|
)
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
history = result.json()["topics"]
|
2018-06-14 00:44:22 +02:00
|
|
|
self.assertEqual(history, [])
|
|
|
|
|
|
|
|
def test_web_public_stream(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
test_stream = self.make_stream("Test Public Archives")
|
2018-06-14 00:44:22 +02:00
|
|
|
do_change_stream_web_public(test_stream, True)
|
|
|
|
|
2018-07-14 06:38:35 +02:00
|
|
|
self.send_stream_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user("iago"),
|
2018-07-14 06:38:35 +02:00
|
|
|
"Test Public Archives",
|
2021-02-12 08:20:45 +01:00
|
|
|
"Test Message 3",
|
|
|
|
topic_name="first_topic",
|
2018-07-14 06:38:35 +02:00
|
|
|
)
|
2018-06-14 00:44:22 +02:00
|
|
|
self.send_stream_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user("iago"),
|
2018-06-14 00:44:22 +02:00
|
|
|
"Test Public Archives",
|
2021-02-12 08:20:45 +01:00
|
|
|
"Test Message",
|
|
|
|
topic_name="TopicGlobal",
|
2018-07-14 06:38:35 +02:00
|
|
|
)
|
|
|
|
self.send_stream_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user("iago"),
|
2018-07-14 06:38:35 +02:00
|
|
|
"Test Public Archives",
|
2021-02-12 08:20:45 +01:00
|
|
|
"Test Message 2",
|
|
|
|
topic_name="topicglobal",
|
2018-07-14 06:38:35 +02:00
|
|
|
)
|
|
|
|
self.send_stream_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user("iago"),
|
2018-07-14 06:38:35 +02:00
|
|
|
"Test Public Archives",
|
2021-02-12 08:20:45 +01:00
|
|
|
"Test Message 3",
|
|
|
|
topic_name="second_topic",
|
2018-07-14 06:38:35 +02:00
|
|
|
)
|
|
|
|
self.send_stream_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user("iago"),
|
2018-07-14 06:38:35 +02:00
|
|
|
"Test Public Archives",
|
2021-02-12 08:20:45 +01:00
|
|
|
"Test Message 4",
|
|
|
|
topic_name="TopicGlobal",
|
2018-06-14 00:44:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
result = self.client_get(
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"/archive/streams/" + str(test_stream.id) + "/topics",
|
2018-06-14 00:44:22 +02:00
|
|
|
)
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
history = result.json()["topics"]
|
2018-07-14 06:38:35 +02:00
|
|
|
self.assert_length(history, 3)
|
|
|
|
# Should be sorted with latest topic first
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(history[0]["name"], "TopicGlobal")
|
|
|
|
self.assertEqual(history[1]["name"], "second_topic")
|
|
|
|
self.assertEqual(history[2]["name"], "first_topic")
|