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:
|
|
|
|
test_stream = self.make_stream('Test Public Archives')
|
|
|
|
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:
|
|
|
|
test_stream = self.make_stream('Test Public Archives')
|
|
|
|
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:
|
|
|
|
test_stream = self.make_stream('Test Public Archives')
|
|
|
|
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,
|
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
|
|
|
'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
|
|
|
)
|
|
|
|
|
|
|
|
result = send_msg_and_get_result('Test Message 1')
|
|
|
|
self.assert_in_success_response(["Test Message 1"], result)
|
|
|
|
result = send_msg_and_get_result('/me goes testing.')
|
|
|
|
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]
|
|
|
|
self.assertEqual(public_stream['name'], "Rome")
|
|
|
|
|
|
|
|
public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm)
|
|
|
|
self.assert_length(public_subs, 1)
|
|
|
|
public_sub = public_subs[0]
|
|
|
|
self.assertEqual(public_sub['name'], "Rome")
|
|
|
|
self.assert_length(public_unsubs, 0)
|
|
|
|
self.assert_length(public_neversubs, 0)
|
|
|
|
|
|
|
|
# Now add a second public stream
|
|
|
|
test_stream = self.make_stream('Test Public Archives')
|
|
|
|
do_change_stream_web_public(test_stream, True)
|
|
|
|
public_streams = get_web_public_streams(realm)
|
|
|
|
self.assert_length(public_streams, 2)
|
|
|
|
public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm)
|
|
|
|
self.assert_length(public_subs, 2)
|
|
|
|
self.assert_length(public_unsubs, 0)
|
|
|
|
self.assert_length(public_neversubs, 0)
|
|
|
|
self.assertNotEqual(public_subs[0]['color'], public_subs[1]['color'])
|
|
|
|
|
|
|
|
do_deactivate_stream(test_stream)
|
|
|
|
public_streams = get_web_public_streams(realm)
|
|
|
|
self.assert_length(public_streams, 1)
|
|
|
|
public_subs, public_unsubs, public_neversubs = get_web_public_subs(realm)
|
|
|
|
self.assert_length(public_subs, 1)
|
|
|
|
self.assert_length(public_unsubs, 0)
|
|
|
|
self.assert_length(public_neversubs, 0)
|
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)
|
|
|
|
history = result.json()['topics']
|
|
|
|
self.assertEqual(history, [])
|
|
|
|
|
|
|
|
def test_non_web_public_stream(self) -> None:
|
|
|
|
test_stream = self.make_stream('Test Public Archives')
|
|
|
|
|
|
|
|
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",
|
|
|
|
'Test Message',
|
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
|
|
|
'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)
|
|
|
|
history = result.json()['topics']
|
|
|
|
self.assertEqual(history, [])
|
|
|
|
|
|
|
|
def test_web_public_stream(self) -> None:
|
|
|
|
test_stream = self.make_stream('Test Public Archives')
|
|
|
|
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",
|
|
|
|
'Test Message 3',
|
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
|
|
|
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",
|
|
|
|
'Test Message',
|
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
|
|
|
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",
|
|
|
|
'Test Message 2',
|
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
|
|
|
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",
|
|
|
|
'Test Message 3',
|
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
|
|
|
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",
|
|
|
|
'Test Message 4',
|
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
|
|
|
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)
|
|
|
|
history = result.json()['topics']
|
2018-07-14 06:38:35 +02:00
|
|
|
self.assert_length(history, 3)
|
|
|
|
# Should be sorted with latest topic first
|
2018-06-14 00:44:22 +02:00
|
|
|
self.assertEqual(history[0]['name'], 'TopicGlobal')
|
2018-07-14 06:38:35 +02:00
|
|
|
self.assertEqual(history[1]['name'], 'second_topic')
|
|
|
|
self.assertEqual(history[2]['name'], 'first_topic')
|