Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Use existing users for most tests due to the site being shut down for…
Browse files Browse the repository at this point in the history
… new users
  • Loading branch information
davehunt committed Aug 14, 2015
1 parent 7074e73 commit f5f442c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 45 deletions.
14 changes: 1 addition & 13 deletions pages/base.py
@@ -1,12 +1,7 @@
#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import urllib2
import json

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
Expand Down Expand Up @@ -42,14 +37,7 @@ def is_user_logged_in(self):
def username(self):
return self.selenium.find_element(*self._username_locator).text

def _create_persona_test_user(self):
response = urllib2.urlopen('http://personatestuser.org/email/').read()
user = json.loads(response)
return user['email'], user['pass']

def login(self, email=None, password=None):
if not all([email, password]):
email, password = self._create_persona_test_user()
def login(self, email, password):
self.click_login()
from browserid import BrowserID
pop_up = BrowserID(self.selenium, self.timeout)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -3,6 +3,7 @@ execnet==1.1
py==1.4.26
pytest==2.7.0
pytest-mozwebqa
pytest-variables
pytest-xdist==1.11
selenium
-e git+https://github.com/mozilla/bidpom.git@master#egg=browserid
21 changes: 21 additions & 0 deletions tests/conftest.py
@@ -0,0 +1,21 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import json
import urllib2

import pytest


@pytest.fixture
def existing_user(variables):
return variables['users']['default']


@pytest.fixture
def new_user(variables):
response = urllib2.urlopen('http://personatestuser.org/email/').read()
user = json.loads(response)
return {'email': user['email'],
'password': user['pass']}
4 changes: 2 additions & 2 deletions tests/test_about_page.py
Expand Up @@ -15,9 +15,9 @@
class TestAboutPage:

@nondestructive
def test_about_page_has_proper_layout(self, mozwebqa):
def test_about_page_has_proper_layout(self, mozwebqa, existing_user):
start_page = StartPage(mozwebqa)
home_page = start_page.login()
home_page = start_page.login(existing_user['email'], existing_user['password'])
about_page = home_page.click_about_nav_link()
Assert.true(about_page.is_the_current_url)
Assert.equal(about_page.faq_header, 'Frequently Asked Questions',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_banner.py
Expand Up @@ -17,9 +17,9 @@ class TestBanners:
@destructive
@pytest.mark.xfail("'affiliates.allizom' in config.getvalue('base_url')",
reason="Bug 1053752 - [stage] Newly created banners don't show up on dashboard page")
def test_user_can_create_banner(self, mozwebqa):
def test_user_can_create_banner(self, mozwebqa, existing_user):
start_page = StartPage(mozwebqa)
home_page = start_page.login()
home_page = start_page.login(existing_user['email'], existing_user['password'])

create_banner_page = home_page.click_create_banner()
create_banner_page.choose_category()
Expand Down
42 changes: 18 additions & 24 deletions tests/test_profile.py
Expand Up @@ -7,6 +7,8 @@
from datetime import datetime

import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from unittestzero import Assert

from pages.start_page import StartPage
Expand All @@ -17,12 +19,11 @@
class TestProfilePage:

@destructive
def test_edit_profile_change_display_name(self, mozwebqa):
def test_edit_profile_change_display_name(self, mozwebqa, existing_user):
new_username = "Testbot: %s" % (datetime.now())

start_page = StartPage(mozwebqa)
email, password = start_page._create_persona_test_user()
home_page = start_page.login(email, password)
home_page = start_page.login(existing_user['email'], existing_user['password'])
profile_page = home_page.click_profile()

# verify changing username, update username to include a timestamp
Expand All @@ -36,7 +37,7 @@ def test_edit_profile_change_display_name(self, mozwebqa):

# verify username persists after logging out and then logging back in
logged_out = profile_page.logout()
home_page = logged_out.login(email, password)
home_page = logged_out.login(existing_user['email'], existing_user['password'])
profile_page = home_page.click_profile()

actual_username = profile_page.profile_username
Expand All @@ -55,13 +56,10 @@ def test_edit_profile_change_display_name(self, mozwebqa):
"to 'Affiliate'. Expected 'Affiliate', but returned '%s'" % actual_username)

@destructive
def test_edit_profiles_website(self, mozwebqa):
def test_edit_profiles_website(self, mozwebqa, existing_user):
start_page = StartPage(mozwebqa)
new_url = 'http://wiki.mozilla.org/' + datetime.utcnow().strftime("%s")

email, password = start_page._create_persona_test_user()

home_page = start_page.login(email, password)
home_page = start_page.login(existing_user['email'], existing_user['password'])
profile_page = home_page.click_profile()

# update profile website to include a timestamp
Expand All @@ -75,7 +73,7 @@ def test_edit_profiles_website(self, mozwebqa):

# verify username persists after logging out and then logging back in
logged_out = profile_page.logout()
home_page = logged_out.login(email, password)
home_page = logged_out.login(existing_user['email'], existing_user['password'])
profile_page = home_page.click_profile()

actual_website = profile_page.profile_website
Expand All @@ -94,9 +92,9 @@ def test_edit_profiles_website(self, mozwebqa):
"Expected '', returned '%s'" % actual_website)

@destructive
def test_verify_layout_logged_in_user(self, mozwebqa):
def test_verify_layout_logged_in_user(self, mozwebqa, existing_user):
start_page = StartPage(mozwebqa)
home_page = start_page.login()
home_page = start_page.login(existing_user['email'], existing_user['password'])
edit_page = home_page.click_profile()

Assert.true(edit_page.is_stats_section_visible())
Expand All @@ -107,18 +105,14 @@ def test_verify_layout_logged_in_user(self, mozwebqa):
Assert.true(edit_page.is_stats_clicks_visible())
Assert.not_none(edit_page.stats_clicks, 'Stats clicks is null')
Assert.true(edit_page.is_milestones_section_visible())
Assert.true(edit_page.is_newsletter_form_visible())

@destructive
def test_new_account_creation(self, mozwebqa):
def test_new_account_creation(self, mozwebqa, new_user):
start_page = StartPage(mozwebqa)
email, password = start_page._create_persona_test_user()
home_page = start_page.login(email, password)

Assert.true(home_page.is_user_logged_in)

logged_out = home_page.logout()
Assert.false(logged_out.is_user_logged_in)

logged_in = logged_out.login(email, password)
Assert.true(logged_in.is_user_logged_in)
start_page.click_login()
from browserid import BrowserID
pop_up = BrowserID(mozwebqa.selenium, mozwebqa.timeout)
pop_up.sign_in(new_user['email'], new_user['password'])
error = mozwebqa.selenium.find_element(By.CLASS_NAME, 'error')
WebDriverWait(mozwebqa.selenium, mozwebqa.timeout).until(
lambda s: error.text == 'Login failed. Firefox Affiliates has stopped accepting new users.')
8 changes: 4 additions & 4 deletions tests/test_start_page.py
Expand Up @@ -18,14 +18,14 @@ class TestStartPage:
def test_start_page_has_proper_titles(self, mozwebqa):
start_page = StartPage(mozwebqa)
Assert.true(start_page.is_the_current_page)
Assert.equal(start_page.header, 'Become a Firefox Affiliate today!')
Assert.equal(start_page.header, 'Important Notice: Firefox Affiliates is being discontinued')

@nondestructive
def test_login_logout_works_properly(self, mozwebqa):
def test_login_logout_works_properly(self, mozwebqa, existing_user):
start_page = StartPage(mozwebqa)
home_page = start_page.login()
home_page = start_page.login(existing_user['email'], existing_user['password'])
Assert.true(home_page.is_user_logged_in, 'User not logged in')
Assert.equal(home_page.header, 'Dashboard')
home_page.logout()
Assert.false(home_page.is_user_logged_in, 'User logged in')
Assert.equal(start_page.header, 'Become a Firefox Affiliate today!')
Assert.equal(start_page.header, 'Important Notice: Firefox Affiliates is being discontinued')
9 changes: 9 additions & 0 deletions variables.json
@@ -0,0 +1,9 @@
{
"users": {
"default": {
"email": "",
"password": "",
"name": ""
}
}
}

0 comments on commit f5f442c

Please sign in to comment.