Fix Client handling in the test suite.

(imported from commit 56841a00052c3aa85f2eeb45133439a46f3caf82)
This commit is contained in:
Tim Abbott
2012-10-22 13:23:11 -04:00
parent 7cf8f842f7
commit f26a614bb3
2 changed files with 12 additions and 5 deletions

View File

@@ -61,7 +61,7 @@ callback_table = {}
mit_sync_table = {}
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):
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)
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):
(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):
# TODO: We should consider whether using
# 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):
id_list = sorted(set(id_list))

View File

@@ -4,7 +4,7 @@ from django.utils.timezone import utc
from django.db.models import Q
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.decorator import TornadoAsyncException
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 = Recipient.objects.get(type_id=recipient.id, type=message_type)
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)
def users_subscribed_to_stream(self, stream_name, realm_domain):
@@ -336,6 +338,7 @@ class MessagePOSTTest(AuthedTestCase):
self.login("hamlet@humbughq.com")
result = self.client.post("/json/send_message/", {"type": "stream",
"stream": "Verona",
"client": "test suite",
"content": "Test message",
"subject": "Test subject"})
self.assert_json_success(result)
@@ -349,6 +352,7 @@ class MessagePOSTTest(AuthedTestCase):
self.assertFalse(Stream.objects.filter(name="nonexistent_stream"))
result = self.client.post("/json/send_message/", {"type": "stream",
"stream": "nonexistent_stream",
"client": "test suite",
"content": "Test message",
"subject": "Test subject"})
self.assert_json_success(result)
@@ -361,6 +365,7 @@ class MessagePOSTTest(AuthedTestCase):
self.login("hamlet@humbughq.com")
result = self.client.post("/json/send_message/", {"type": "personal",
"content": "Test message",
"client": "test suite",
"recipient": "othello@humbughq.com"})
self.assert_json_success(result)
@@ -371,6 +376,7 @@ class MessagePOSTTest(AuthedTestCase):
self.login("hamlet@humbughq.com")
result = self.client.post("/json/send_message/", {"type": "personal",
"content": "Test message",
"client": "test suite",
"recipient": "nonexistent"})
self.assert_json_error(result, "Invalid email 'nonexistent'")
@@ -381,6 +387,7 @@ class MessagePOSTTest(AuthedTestCase):
self.login("hamlet@humbughq.com")
result = self.client.post("/json/send_message/", {"type": "invalid type",
"content": "Test message",
"client": "test suite",
"recipient": "othello@humbughq.com"})
self.assert_json_error(result, "Invalid message type")