From 7d654a26c8e953ee9ebfcba931b8b6cfd20a1339 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Sat, 25 Jun 2016 22:34:36 +0530 Subject: [PATCH] Casper test for realm creation. --- .../casper_tests/00-realm-creation.js | 91 +++++++++++++++++++ zerver/views/__init__.py | 8 +- zproject/dev_urls.py | 1 + zproject/urls.py | 1 + 4 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 frontend_tests/casper_tests/00-realm-creation.js diff --git a/frontend_tests/casper_tests/00-realm-creation.js b/frontend_tests/casper_tests/00-realm-creation.js new file mode 100644 index 0000000000..691785f14e --- /dev/null +++ b/frontend_tests/casper_tests/00-realm-creation.js @@ -0,0 +1,91 @@ +var common = require('../casper_lib/common.js').common; + +var email = 'alice@test.example.com'; +var domain = 'test.example.com'; +var organization_name = 'Awesome Organization'; + +casper.start('http://localhost:9981/create_realm/'); + +casper.then(function () { + // Submit the email for realm creation + this.waitForSelector('form[action^="/create_realm/"]', function () { + this.fill('form[action^="/create_realm/"]', { + email: email + }, true); + }); + // Make sure confirmation email is send + this.waitWhileSelector('form[action^="/create_realm/"]', function () { + var regex = new RegExp('^http:\/\/[^\/]+\/accounts\/send_confirm\/' + email); + this.test.assertUrlMatch(regex, 'Confirmation mail send'); + }); +}); + +// Special endpoint enabled only during tests for extracting confirmation key +casper.thenOpen('http://localhost:9981/confirmation_key/'); + +// Open the confirmation URL +casper.then(function () { + var confirmation_key = JSON.parse(this.getPageContent()).confirmation_key; + var confirmation_url = 'http://localhost:9981/accounts/do_confirm/' + confirmation_key; + this.thenOpen(confirmation_url); +}); + +// Make sure the realm creation page is loaded correctly +casper.then(function () { + this.waitForSelector('.pitch', function () { + this.test.assertSelectorHasText('.pitch', "You're almost there. We just need you to do one last thing."); + }); + + this.waitForSelector('.controls.fakecontrol', function () { + this.test.assertSelectorHasText('.controls.fakecontrol', email); + }); + + this.waitForSelector('label[for=id_team_name]', function () { + this.test.assertSelectorHasText('label[for=id_team_name]', 'Organization name'); + }); +}); + +casper.then(function () { + this.waitForSelector('form[action^="/accounts/register/"]', function () { + this.fill('form[action^="/accounts/register/"]', { + full_name: 'Alice', + realm_name: organization_name, + password: 'password', + terms: true + }, true); + }); + + this.waitWhileSelector('form[action^="/accounts/register/"]', function () { + casper.test.assertUrlMatch('http://localhost:9981/invite/', 'Invite more users page loaded'); + }); +}); + +// Tests for invite more users page +casper.then(function () { + this.waitForSelector('.app-main.portico-page-container', function () { + this.test.assertSelectorHasText('.app-main.portico-page-container', "You're the first one here!"); + }); + + this.waitForSelector('.invite_row', function () { + this.test.assertSelectorHasText('.invite_row', domain); + }); + + this.waitForSelector('#submit_invitation', function () { + this.click('#submit_invitation'); + }); + + this.waitWhileSelector('#submit_invitation', function () { + this.test.assertUrlMatch('http://localhost:9981/', 'Realm created and logged in'); + }); +}); + +casper.then(function () { + // The user is logged in to the newly created realm + this.test.assertTitle('home - ' + organization_name + ' - Zulip'); +}); + +common.then_log_out(); + +casper.run(function () { + casper.test.done(); +}); diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index d175535b21..029bc174ec 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -710,7 +710,7 @@ def accounts_home_with_domain(request, domain): return HttpResponseRedirect(reverse('zerver.views.accounts_home')) def send_registration_completion_email(email, request, realm_creation=False): - # type: (str, HttpRequest, bool) -> HttpResponse + # type: (str, HttpRequest, bool) -> Confirmation """ Send an email with a confirmation link to the provided e-mail so the user can complete their registration. @@ -735,7 +735,9 @@ def create_realm(request): form = RealmCreationForm(request.POST, domain=request.session.get("domain")) if form.is_valid(): email = form.cleaned_data['email'] - send_registration_completion_email(email, request, realm_creation=True) + confirmation_key = send_registration_completion_email(email, request, realm_creation=True).confirmation_key + if settings.DEVELOPMENT: + request.session['confirmation_key'] = {'confirmation_key': confirmation_key} return HttpResponseRedirect(reverse('send_confirm', kwargs={'email': email})) try: email = request.POST['email'] @@ -750,6 +752,8 @@ def create_realm(request): {'form': form, 'current_url': request.get_full_path}, request=request) +def confirmation_key(request): + return json_success(request.session.get('confirmation_key')) def accounts_home(request): # type: (HttpRequest) -> HttpResponse diff --git a/zproject/dev_urls.py b/zproject/dev_urls.py index 7d38bf40b1..f59c80fb9b 100644 --- a/zproject/dev_urls.py +++ b/zproject/dev_urls.py @@ -8,6 +8,7 @@ use_prod_static = getattr(settings, 'PIPELINE', False) static_root = os.path.join(settings.DEPLOY_ROOT, 'prod-static/serve' if use_prod_static else 'static') urls = [url(r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': static_root})] +i18n_urls = [url(r'^confirmation_key/$', 'zerver.views.confirmation_key')] # These are used for voyager development. On a real voyager instance, # these files would be served by nginx. diff --git a/zproject/urls.py b/zproject/urls.py index 930184d4eb..02982b29f7 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -291,6 +291,7 @@ urls += [ if settings.DEVELOPMENT: urls += dev_urls.urls + i18n_urls += dev_urls.i18n_urls # The sequence is important; if i18n urls don't come first then # reverse url mapping points to i18n urls which causes the frontend