mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
Fix Client handling in the test suite.
(imported from commit 56841a00052c3aa85f2eeb45133439a46f3caf82)
This commit is contained in:
@@ -61,7 +61,7 @@ callback_table = {}
|
|||||||
mit_sync_table = {}
|
mit_sync_table = {}
|
||||||
|
|
||||||
class Realm(models.Model):
|
class Realm(models.Model):
|
||||||
domain = models.CharField(max_length=40, db_index=True)
|
domain = models.CharField(max_length=40, db_index=True, unique=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Realm: %s %s>" % (self.domain, self.id)
|
return "<Realm: %s %s>" % (self.domain, self.id)
|
||||||
@@ -285,7 +285,7 @@ class Recipient(models.Model):
|
|||||||
return "<Recipient: %s (%d, %s)>" % (display_recipient, self.type_id, self.type)
|
return "<Recipient: %s (%d, %s)>" % (display_recipient, self.type_id, self.type)
|
||||||
|
|
||||||
class Client(models.Model):
|
class Client(models.Model):
|
||||||
name = models.CharField(max_length=30)
|
name = models.CharField(max_length=30, db_index=True, unique=True)
|
||||||
|
|
||||||
def get_client(name):
|
def get_client(name):
|
||||||
(client, _) = Client.objects.get_or_create(name=name)
|
(client, _) = Client.objects.get_or_create(name=name)
|
||||||
@@ -465,7 +465,7 @@ def do_remove_subscription(user_profile, stream, no_log=False):
|
|||||||
class Huddle(models.Model):
|
class Huddle(models.Model):
|
||||||
# TODO: We should consider whether using
|
# TODO: We should consider whether using
|
||||||
# CommaSeparatedIntegerField would be better.
|
# CommaSeparatedIntegerField would be better.
|
||||||
huddle_hash = models.CharField(max_length=40, db_index=True)
|
huddle_hash = models.CharField(max_length=40, db_index=True, unique=True)
|
||||||
|
|
||||||
def get_huddle_hash(id_list):
|
def get_huddle_hash(id_list):
|
||||||
id_list = sorted(set(id_list))
|
id_list = sorted(set(id_list))
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from django.utils.timezone import utc
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from zephyr.models import Message, UserProfile, Stream, Recipient, Subscription, \
|
from zephyr.models import Message, UserProfile, Stream, Recipient, Subscription, \
|
||||||
filter_by_subscriptions, Realm, do_send_message
|
filter_by_subscriptions, Realm, do_send_message, Client
|
||||||
from zephyr.views import json_get_updates
|
from zephyr.views import json_get_updates
|
||||||
from zephyr.decorator import TornadoAsyncException
|
from zephyr.decorator import TornadoAsyncException
|
||||||
from zephyr.lib.initial_password import initial_password
|
from zephyr.lib.initial_password import initial_password
|
||||||
@@ -60,7 +60,9 @@ class AuthedTestCase(TestCase):
|
|||||||
recipient = Stream.objects.get(name=recipient_name, realm=sender.realm)
|
recipient = Stream.objects.get(name=recipient_name, realm=sender.realm)
|
||||||
recipient = Recipient.objects.get(type_id=recipient.id, type=message_type)
|
recipient = Recipient.objects.get(type_id=recipient.id, type=message_type)
|
||||||
pub_date = datetime.datetime.utcnow().replace(tzinfo=utc)
|
pub_date = datetime.datetime.utcnow().replace(tzinfo=utc)
|
||||||
do_send_message(Message(sender=sender, recipient=recipient, subject="test", pub_date=pub_date),
|
(sending_client, _) = Client.objects.get_or_create(name="test suite")
|
||||||
|
do_send_message(Message(sender=sender, recipient=recipient, subject="test", pub_date=pub_date,
|
||||||
|
sending_client=sending_client),
|
||||||
synced_from_mit=True)
|
synced_from_mit=True)
|
||||||
|
|
||||||
def users_subscribed_to_stream(self, stream_name, realm_domain):
|
def users_subscribed_to_stream(self, stream_name, realm_domain):
|
||||||
@@ -336,6 +338,7 @@ class MessagePOSTTest(AuthedTestCase):
|
|||||||
self.login("hamlet@humbughq.com")
|
self.login("hamlet@humbughq.com")
|
||||||
result = self.client.post("/json/send_message/", {"type": "stream",
|
result = self.client.post("/json/send_message/", {"type": "stream",
|
||||||
"stream": "Verona",
|
"stream": "Verona",
|
||||||
|
"client": "test suite",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"subject": "Test subject"})
|
"subject": "Test subject"})
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
@@ -349,6 +352,7 @@ class MessagePOSTTest(AuthedTestCase):
|
|||||||
self.assertFalse(Stream.objects.filter(name="nonexistent_stream"))
|
self.assertFalse(Stream.objects.filter(name="nonexistent_stream"))
|
||||||
result = self.client.post("/json/send_message/", {"type": "stream",
|
result = self.client.post("/json/send_message/", {"type": "stream",
|
||||||
"stream": "nonexistent_stream",
|
"stream": "nonexistent_stream",
|
||||||
|
"client": "test suite",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"subject": "Test subject"})
|
"subject": "Test subject"})
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
@@ -361,6 +365,7 @@ class MessagePOSTTest(AuthedTestCase):
|
|||||||
self.login("hamlet@humbughq.com")
|
self.login("hamlet@humbughq.com")
|
||||||
result = self.client.post("/json/send_message/", {"type": "personal",
|
result = self.client.post("/json/send_message/", {"type": "personal",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
|
"client": "test suite",
|
||||||
"recipient": "othello@humbughq.com"})
|
"recipient": "othello@humbughq.com"})
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
@@ -371,6 +376,7 @@ class MessagePOSTTest(AuthedTestCase):
|
|||||||
self.login("hamlet@humbughq.com")
|
self.login("hamlet@humbughq.com")
|
||||||
result = self.client.post("/json/send_message/", {"type": "personal",
|
result = self.client.post("/json/send_message/", {"type": "personal",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
|
"client": "test suite",
|
||||||
"recipient": "nonexistent"})
|
"recipient": "nonexistent"})
|
||||||
self.assert_json_error(result, "Invalid email 'nonexistent'")
|
self.assert_json_error(result, "Invalid email 'nonexistent'")
|
||||||
|
|
||||||
@@ -381,6 +387,7 @@ class MessagePOSTTest(AuthedTestCase):
|
|||||||
self.login("hamlet@humbughq.com")
|
self.login("hamlet@humbughq.com")
|
||||||
result = self.client.post("/json/send_message/", {"type": "invalid type",
|
result = self.client.post("/json/send_message/", {"type": "invalid type",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
|
"client": "test suite",
|
||||||
"recipient": "othello@humbughq.com"})
|
"recipient": "othello@humbughq.com"})
|
||||||
self.assert_json_error(result, "Invalid message type")
|
self.assert_json_error(result, "Invalid message type")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user