mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
Add create_zephyr_class helper.
(imported from commit 993fbb799b706e402ae212330e4abbe28bf84ee9)
This commit is contained in:
@@ -3,7 +3,8 @@ from django.utils.timezone import utc
|
|||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Recipient, \
|
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Recipient, \
|
||||||
Subscription, Huddle, get_huddle, Realm, create_user_profile, UserMessage
|
Subscription, Huddle, get_huddle, Realm, create_user_profile, UserMessage, \
|
||||||
|
create_zephyr_class
|
||||||
from zephyr.zephyr_mirror import subs_list
|
from zephyr.zephyr_mirror import subs_list
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@@ -24,11 +25,7 @@ def create_classes(class_list, realm):
|
|||||||
if ZephyrClass.objects.filter(name=name, realm=realm):
|
if ZephyrClass.objects.filter(name=name, realm=realm):
|
||||||
# We're trying to create the same zephyr class twice!
|
# We're trying to create the same zephyr class twice!
|
||||||
raise
|
raise
|
||||||
new_class = ZephyrClass(name=name, realm=realm)
|
create_zephyr_class(name, realm)
|
||||||
new_class.save()
|
|
||||||
|
|
||||||
recipient = Recipient(type_id=new_class.pk, type="class")
|
|
||||||
recipient.save()
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Populate a test database"
|
help = "Populate a test database"
|
||||||
|
|||||||
@@ -84,6 +84,14 @@ class ZephyrClass(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
|
||||||
|
def create_zephyr_class(name, realm):
|
||||||
|
zephyr_class = ZephyrClass(name=name, realm=realm)
|
||||||
|
zephyr_class.save()
|
||||||
|
|
||||||
|
recipient = Recipient(type_id=zephyr_class.id, type="class")
|
||||||
|
recipient.save()
|
||||||
|
return (zephyr_class, recipient)
|
||||||
|
|
||||||
class Recipient(models.Model):
|
class Recipient(models.Model):
|
||||||
type_id = models.IntegerField()
|
type_id = models.IntegerField()
|
||||||
type = models.CharField(max_length=30)
|
type = models.CharField(max_length=30)
|
||||||
|
|||||||
@@ -338,5 +338,7 @@ class ZephyrPOSTTest(AuthedTestCase):
|
|||||||
Sending a zephyr of unknown type returns error JSON.
|
Sending a zephyr of unknown type returns error JSON.
|
||||||
"""
|
"""
|
||||||
self.login("hamlet", "hamlet")
|
self.login("hamlet", "hamlet")
|
||||||
result = self.client.post("/zephyr/", {"type": "invalid type"})
|
result = self.client.post("/zephyr/", {"type": "invalid type",
|
||||||
|
"new_zephyr": "Test message",
|
||||||
|
"recipient": "othello"})
|
||||||
self.assert_json_error(result, "Invalid zephyr type")
|
self.assert_json_error(result, "Invalid zephyr type")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from django.utils.timezone import utc
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
|
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
|
||||||
Recipient, filter_by_subscriptions, get_display_recipient, get_huddle, \
|
Recipient, filter_by_subscriptions, get_display_recipient, get_huddle, \
|
||||||
create_user_profile, Realm, UserMessage
|
create_user_profile, Realm, UserMessage, create_zephyr_class
|
||||||
from zephyr.forms import RegistrationForm
|
from zephyr.forms import RegistrationForm
|
||||||
|
|
||||||
import tornado.web
|
import tornado.web
|
||||||
@@ -287,11 +287,7 @@ def add_subscriptions(request):
|
|||||||
zephyr_class = zephyr_class[0]
|
zephyr_class = zephyr_class[0]
|
||||||
recipient = Recipient.objects.get(type_id=zephyr_class.pk, type="class")
|
recipient = Recipient.objects.get(type_id=zephyr_class.pk, type="class")
|
||||||
else:
|
else:
|
||||||
zephyr_class = ZephyrClass(name=sub_name, realm=user_profile.realm)
|
(_, recipient) = create_zephyr_class(sub_name, user_profile.realm)
|
||||||
zephyr_class.save()
|
|
||||||
|
|
||||||
recipient = Recipient(type_id=zephyr_class.pk, type="class")
|
|
||||||
recipient.save()
|
|
||||||
|
|
||||||
subscription = Subscription.objects.filter(userprofile=user_profile,
|
subscription = Subscription.objects.filter(userprofile=user_profile,
|
||||||
recipient=recipient)
|
recipient=recipient)
|
||||||
|
|||||||
Reference in New Issue
Block a user