mirror of https://github.com/zulip/zulip.git
populate_db: Populate linkifiers.
The curl examples of reordering linkifiers require there to be some linkifiers in the database to be reordered. This adjusts some test cases so they do not assume that there is no linkifier in the test db.
This commit is contained in:
parent
112a6e445e
commit
011b4c1f7a
|
@ -449,8 +449,8 @@ def add_realm_filter(client: Client) -> None:
|
|||
@openapi_test_function("/realm/filters/{filter_id}:patch")
|
||||
def update_realm_filter(client: Client) -> None:
|
||||
# {code_example|start}
|
||||
# Update the linkifier (realm_filter) with ID 1
|
||||
filter_id = 1
|
||||
# Update the linkifier (realm_filter) with ID 4
|
||||
filter_id = 4
|
||||
request = {
|
||||
"pattern": "#(?P<id>[0-9]+)",
|
||||
"url_template": "https://github.com/zulip/zulip/issues/{id}",
|
||||
|
@ -467,8 +467,8 @@ def update_realm_filter(client: Client) -> None:
|
|||
@openapi_test_function("/realm/filters/{filter_id}:delete")
|
||||
def remove_realm_filter(client: Client) -> None:
|
||||
# {code_example|start}
|
||||
# Remove the linkifier (realm_filter) with ID 1
|
||||
result = client.remove_realm_filter(1)
|
||||
# Remove the linkifier (realm_filter) with ID 4
|
||||
result = client.remove_realm_filter(4)
|
||||
# {code_example|end}
|
||||
|
||||
validate_against_openapi_schema(result, "/realm/filters/{filter_id}", "delete", "200")
|
||||
|
|
|
@ -10710,7 +10710,7 @@ paths:
|
|||
The ID of the linkifier that you want to update.
|
||||
schema:
|
||||
type: integer
|
||||
example: 2
|
||||
example: 5
|
||||
required: true
|
||||
- $ref: "#/components/parameters/LinkifierPattern"
|
||||
- $ref: "#/components/parameters/LinkifierURLTemplate"
|
||||
|
|
|
@ -772,9 +772,9 @@ class FetchInitialStateDataTest(ZulipTestCase):
|
|||
linkifier_url_template=True,
|
||||
)
|
||||
self.assertEqual(result["realm_filters"], [])
|
||||
self.assertEqual(result["realm_linkifiers"][0]["pattern"], "#(?P<id>[123])")
|
||||
self.assertEqual(result["realm_linkifiers"][-1]["pattern"], "#(?P<id>[123])")
|
||||
self.assertEqual(
|
||||
result["realm_linkifiers"][0]["url_template"],
|
||||
result["realm_linkifiers"][-1]["url_template"],
|
||||
"https://realm.com/my_realm_filter/{id}",
|
||||
)
|
||||
|
||||
|
|
|
@ -218,6 +218,7 @@ from zerver.models import (
|
|||
Realm,
|
||||
RealmAuditLog,
|
||||
RealmDomain,
|
||||
RealmFilter,
|
||||
RealmPlayground,
|
||||
RealmUserDefault,
|
||||
Service,
|
||||
|
@ -2166,8 +2167,10 @@ class NormalActionsTest(BaseAction):
|
|||
)
|
||||
check_realm_linkifiers("events[0]", events[0])
|
||||
|
||||
linkifier_id = events[0]["realm_linkifiers"][-1]["id"]
|
||||
self.assertEqual(RealmFilter.objects.get(id=linkifier_id).pattern, regex)
|
||||
|
||||
regex = "#(?P<id>[0-9]+)"
|
||||
linkifier_id = events[0]["realm_linkifiers"][0]["id"]
|
||||
events = self.verify_action(
|
||||
lambda: do_update_linkifier(
|
||||
self.user_profile.realm, linkifier_id, regex, url, acting_user=None
|
||||
|
|
|
@ -1453,6 +1453,7 @@ class MarkdownTest(ZulipTestCase):
|
|||
|
||||
def test_linkifier_precedence(self) -> None:
|
||||
realm = self.example_user("hamlet").realm
|
||||
RealmFilter.objects.filter(realm=realm).delete()
|
||||
# The insertion order should not affect the fact that the linkifiers are ordered by id.
|
||||
# Note that we might later switch to a different field to order the linkifiers.
|
||||
sequence = (10, 3, 11, 2, 4, 5, 6)
|
||||
|
|
|
@ -7,6 +7,11 @@ from zerver.models import RealmFilter, url_template_validator
|
|||
|
||||
|
||||
class RealmFilterTest(ZulipTestCase):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
iago = self.example_user("iago")
|
||||
RealmFilter.objects.filter(realm=iago.realm).delete()
|
||||
|
||||
def test_list(self) -> None:
|
||||
self.login("iago")
|
||||
data = {
|
||||
|
|
|
@ -26,6 +26,7 @@ from zerver.actions.custom_profile_fields import (
|
|||
)
|
||||
from zerver.actions.message_send import build_message_send_dict, do_send_messages
|
||||
from zerver.actions.realm_emoji import check_add_realm_emoji
|
||||
from zerver.actions.realm_linkifiers import do_add_linkifier
|
||||
from zerver.actions.scheduled_messages import check_schedule_message
|
||||
from zerver.actions.streams import bulk_add_subscriptions
|
||||
from zerver.actions.user_groups import create_user_group_in_database
|
||||
|
@ -795,6 +796,24 @@ class Command(BaseCommand):
|
|||
deliver_at=timezone_now() + timedelta(days=365),
|
||||
realm=zulip_realm,
|
||||
)
|
||||
do_add_linkifier(
|
||||
zulip_realm,
|
||||
"#D(?P<id>[0-9]{2,8})",
|
||||
"https://github.com/zulip/zulip-desktop/pull/{id}",
|
||||
acting_user=None,
|
||||
)
|
||||
do_add_linkifier(
|
||||
zulip_realm,
|
||||
"zulip-mobile#(?P<id>[0-9]{2,8})",
|
||||
"https://github.com/zulip/zulip-mobile/pull/{id}",
|
||||
acting_user=None,
|
||||
)
|
||||
do_add_linkifier(
|
||||
zulip_realm,
|
||||
"zulip-(?P<repo>[a-zA-Z-_0-9]+)#(?P<id>[0-9]{2,8})",
|
||||
"https://github.com/zulip/{repo}/pull/{id}",
|
||||
acting_user=None,
|
||||
)
|
||||
else:
|
||||
zulip_realm = get_realm("zulip")
|
||||
recipient_streams = [
|
||||
|
|
Loading…
Reference in New Issue