mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Add backend tests for group signups.
(imported from commit bbb415f40225e6fc16aa8d1edf0b95b37e09f751)
This commit is contained in:
@@ -291,18 +291,18 @@ class AuthedTestCase(TestCase):
|
|||||||
self.assertIn("msg", json)
|
self.assertIn("msg", json)
|
||||||
return json
|
return json
|
||||||
|
|
||||||
def get_json_error(self, result):
|
def get_json_error(self, result, status_code=400):
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, status_code)
|
||||||
json = ujson.loads(result.content)
|
json = ujson.loads(result.content)
|
||||||
self.assertEqual(json.get("result"), "error")
|
self.assertEqual(json.get("result"), "error")
|
||||||
return json['msg']
|
return json['msg']
|
||||||
|
|
||||||
def assert_json_error(self, result, msg):
|
def assert_json_error(self, result, msg, status_code=400):
|
||||||
"""
|
"""
|
||||||
Invalid POSTs return a 400 and JSON of the form {"result": "error",
|
Invalid POSTs return an error status code and JSON of the form
|
||||||
"msg": "reason"}.
|
{"result": "error", "msg": "reason"}.
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.get_json_error(result), msg)
|
self.assertEqual(self.get_json_error(result, status_code=status_code), msg)
|
||||||
|
|
||||||
def assert_length(self, queries, count, exact=False):
|
def assert_length(self, queries, count, exact=False):
|
||||||
if exact:
|
if exact:
|
||||||
|
|||||||
@@ -81,6 +81,49 @@ class PublicURLTest(TestCase):
|
|||||||
for status_code, url_set in post_urls.iteritems():
|
for status_code, url_set in post_urls.iteritems():
|
||||||
self.fetch("post", url_set, status_code)
|
self.fetch("post", url_set, status_code)
|
||||||
|
|
||||||
|
class SignupTest(AuthedTestCase):
|
||||||
|
def test_signup_page_looks_right(self):
|
||||||
|
"""
|
||||||
|
Requesting /signup/ returns a successful status code and the expected
|
||||||
|
text.
|
||||||
|
"""
|
||||||
|
result = self.client.get("/signup/")
|
||||||
|
self.assertEquals(result.status_code, 200)
|
||||||
|
self.assertIn("Does your company already use Zulip?", result.content)
|
||||||
|
self.assertIn("I'm looking forward to it!", result.content)
|
||||||
|
|
||||||
|
def test_signup_for_new_realm(self):
|
||||||
|
"""
|
||||||
|
You sign up a new group by sending company information to the sign-me-up
|
||||||
|
endpoint.
|
||||||
|
"""
|
||||||
|
result = self.client.post("/signup/sign-me-up",
|
||||||
|
{"name": "King Hamlet",
|
||||||
|
"email": "hamlet@denmark.com",
|
||||||
|
"company": "Denmark",
|
||||||
|
"count": 10,
|
||||||
|
"product": "soliloquys"})
|
||||||
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
def test_signup_for_existing_realm(self):
|
||||||
|
"""
|
||||||
|
If you try to sign up with an e-mail address from an existing group, you
|
||||||
|
probably meant to register, so we send you a registration confirmation
|
||||||
|
link.
|
||||||
|
"""
|
||||||
|
result = self.client.post("/signup/sign-me-up",
|
||||||
|
{"name": "Claudius",
|
||||||
|
"email": "claudius@zulip.com",
|
||||||
|
"company": "Denmark",
|
||||||
|
"count": 10,
|
||||||
|
"product": "soliloquys"})
|
||||||
|
self.assert_json_error(result, "Your group is already signed up!",
|
||||||
|
status_code=403)
|
||||||
|
from django.core.mail import outbox
|
||||||
|
registration_email = outbox.pop()
|
||||||
|
self.assertIn("To complete signup, visit this link below",
|
||||||
|
registration_email.body)
|
||||||
|
|
||||||
class LoginTest(AuthedTestCase):
|
class LoginTest(AuthedTestCase):
|
||||||
"""
|
"""
|
||||||
Logging in, registration, and logging out.
|
Logging in, registration, and logging out.
|
||||||
|
|||||||
Reference in New Issue
Block a user