Add backend tests for group signups.

(imported from commit bbb415f40225e6fc16aa8d1edf0b95b37e09f751)
This commit is contained in:
Jessica McKellar
2014-01-31 17:12:10 -05:00
parent 1c5110dbad
commit ea934cf286
2 changed files with 49 additions and 6 deletions

View File

@@ -291,18 +291,18 @@ class AuthedTestCase(TestCase):
self.assertIn("msg", json)
return json
def get_json_error(self, result):
self.assertEqual(result.status_code, 400)
def get_json_error(self, result, status_code=400):
self.assertEqual(result.status_code, status_code)
json = ujson.loads(result.content)
self.assertEqual(json.get("result"), "error")
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",
"msg": "reason"}.
Invalid POSTs return an error status code and JSON of the form
{"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):
if exact:

View File

@@ -81,6 +81,49 @@ class PublicURLTest(TestCase):
for status_code, url_set in post_urls.iteritems():
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):
"""
Logging in, registration, and logging out.