From e66b356f900bc9899a5506378163ffaadd4a32b5 Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Wed, 27 Jan 2016 13:56:41 +0100 Subject: Add a login multi user functional test - Issue #576 - Extended AppTestClient with multi user support --- service/test/functional/features/environment.py | 17 +++++++---- service/test/functional/features/login.feature | 28 ++++++++++++++++++ service/test/functional/features/steps/common.py | 6 ++++ service/test/functional/features/steps/compose.py | 1 - .../test/functional/features/steps/data_setup.py | 25 +++++++++++++++- service/test/functional/features/steps/login.py | 34 ++++++++++++++++++++++ .../test/functional/features/steps/mail_list.py | 1 + 7 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 service/test/functional/features/login.feature create mode 100644 service/test/functional/features/steps/login.py (limited to 'service/test/functional') diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py index a41329dd..847322ff 100644 --- a/service/test/functional/features/environment.py +++ b/service/test/functional/features/environment.py @@ -19,6 +19,8 @@ import uuid from crochet import setup, wait_for from leap.common.events.server import ensure_server from twisted.internet import defer + +from pixelated.application import UserAgentMode from test.support.dispatcher.proxy import Proxy from test.support.integration import AppTestClient from selenium import webdriver @@ -31,21 +33,26 @@ setup() @wait_for(timeout=5.0) -def start_app_test_client(client): - ensure_server() - return client.start_client() +def start_app_test_client(client, mode): + return client.start_client(mode=mode) def before_all(context): + ensure_server() logging.disable('INFO') client = AppTestClient() - start_app_test_client(client) + start_app_test_client(client, UserAgentMode(is_single_user=True)) client.listenTCP() proxy = Proxy(proxy_port='8889', app_port='4567') FeaturesResource.DISABLED_FEATURES.append('autoRefresh') context.client = client context.call_to_terminate_proxy = proxy.run_on_a_thread() + multi_user_client = AppTestClient() + start_app_test_client(multi_user_client, UserAgentMode(is_single_user=False)) + multi_user_client.listenTCP(port=MULTI_USER_PORT) + context.multi_user_client = multi_user_client + def after_all(context): context.call_to_terminate_proxy() @@ -57,7 +64,7 @@ def before_feature(context, feature): context.browser.set_window_size(1280, 1024) context.browser.implicitly_wait(DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S) context.browser.set_page_load_timeout(60) # wait for data - context.browser.get('http://localhost:8889/') + context.browser.get(HOMEPAGE_URL) def after_step(context, step): diff --git a/service/test/functional/features/login.feature b/service/test/functional/features/login.feature new file mode 100644 index 00000000..9a353d74 --- /dev/null +++ b/service/test/functional/features/login.feature @@ -0,0 +1,28 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . + +Feature: login and logout + As a user of Pixelated + I want to log in to my account + So I can see my emails + + Scenario: Existing user logs into his account + Given Account for user username exists + And I have a mail for username in my inbox + When I open the login page + And I enter username and password as credentials + And I click on the login button + Then I have mails diff --git a/service/test/functional/features/steps/common.py b/service/test/functional/features/steps/common.py index 9a547375..fb5698f0 100644 --- a/service/test/functional/features/steps/common.py +++ b/service/test/functional/features/steps/common.py @@ -26,6 +26,12 @@ TIMEOUT_IN_S = 20 DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S = 10.0 +HOMEPAGE_URL = 'http://localhost:8889/' + +MULTI_USER_PORT = 4568 + +MULTI_USER_URL = 'http://localhost:%d/' % MULTI_USER_PORT + class ImplicitWait(object): def __init__(self, context, timeout=5.0): diff --git a/service/test/functional/features/steps/compose.py b/service/test/functional/features/steps/compose.py index f0bed86e..67b1bd51 100644 --- a/service/test/functional/features/steps/compose.py +++ b/service/test/functional/features/steps/compose.py @@ -21,7 +21,6 @@ from common import * @when('I compose a message with') def impl(context): - take_screenshot(context, '/tmp/screenshot.jpeg') toggle = context.browser.find_element_by_id('compose-mails-trigger') toggle.click() diff --git a/service/test/functional/features/steps/data_setup.py b/service/test/functional/features/steps/data_setup.py index fb825aba..167acf9a 100644 --- a/service/test/functional/features/steps/data_setup.py +++ b/service/test/functional/features/steps/data_setup.py @@ -17,6 +17,7 @@ from uuid import uuid4 from test.support.integration import MailBuilder from behave import given from common import wait_for_condition +from crochet import wait_for @given('I have a mail in my inbox') @@ -24,8 +25,30 @@ def add_mail_impl(context): subject = 'Hi! This the subject %s' % uuid4() input_mail = MailBuilder().with_subject(subject).build_input_mail() - context.client.add_mail_to_inbox(input_mail) + context.client.add_mail_to_inbox(input_mail) wait_for_condition(context, lambda _: context.client.search_engine.search(subject)[1] > 0, poll_frequency=0.1) context.last_subject = subject + + +@given('I have a mail for {username} in my inbox') +def add_mail_to_user_inbox(context, username): + subject = 'Hi! This the subject %s' % uuid4() + + input_mail = MailBuilder().with_subject(subject).build_input_mail() + + context.multi_user_client.add_mail_to_user_inbox(input_mail, username) + wait_for_condition(context, lambda _: context.multi_user_client.account_for(username).search_engine.search(subject)[1] > 0, poll_frequency=0.1) + + context.last_subject = subject + + +@wait_for(timeout=10.0) +def add_multi_user_account(context, username): + return context.multi_user_client.create_user('username') + + +@given(u'Account for user {username} exists') +def add_account(context, username): + add_multi_user_account(context, username) diff --git a/service/test/functional/features/steps/login.py b/service/test/functional/features/steps/login.py new file mode 100644 index 00000000..3c80e819 --- /dev/null +++ b/service/test/functional/features/steps/login.py @@ -0,0 +1,34 @@ +# +# Copyright (c) 2016 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +from behave import when, then +from common import * + + +@when(u'I open the login page') +def login_page(context): + context.browser.get(MULTI_USER_URL + '/login') + + +@when(u'I enter {username} and {password} as credentials') +def enter_credentials(context, username, password): + fill_by_css_selector(context, 'input#email', username) + fill_by_css_selector(context, 'input#password', password) + + +@when(u'I click on the login button') +def click_login(context): + login_button = wait_until_element_is_visible_by_locator(context, (By.CSS_SELECTOR, 'input[name="login"]')) + login_button.click() diff --git a/service/test/functional/features/steps/mail_list.py b/service/test/functional/features/steps/mail_list.py index 1b850578..d19de6cd 100644 --- a/service/test/functional/features/steps/mail_list.py +++ b/service/test/functional/features/steps/mail_list.py @@ -76,6 +76,7 @@ def impl(context): @given('I have mails') +@then(u'I have mails') def impl(context): emails = wait_until_elements_are_visible_by_locator(context, (By.CSS_SELECTOR, '#mail-list li span a')) assert len(emails) > 0 -- cgit v1.2.3