Created
August 11, 2015 11:35
-
-
Save miohtama/7b13c7ef5e4ffe840bac to your computer and use it in GitHub Desktop.
py.test + splinter + authomatic + Facebook login functional test for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pytest | |
def do_facebook_login(browser): | |
fb_user = os.environ.get("FACEBOOK_USER") | |
assert fb_user, "Please configure your Facebook secrets as environment variables to run the tests" | |
fb_password = os.environ["FACEBOOK_PASSWORD"] | |
b = browser | |
assert b.is_text_present("Facebook Login") | |
# FB login | |
b.fill("email", fb_user) | |
b.fill("pass", fb_password) | |
b.find_by_css("input[name='login']").click() | |
# FB allow app confirmation dialog - this is only once per user unless you reset in in your FB profile | |
if b.is_text_present("will receive the following info"): | |
b.find_by_css("button[name='__CONFIRM__']").click() | |
@pytest.mark.skipif("FACEBOOK_USER" not in os.environ, reason="Give Facebook user/pass as environment variables") | |
def test_facebook_login(web_server, browser, DBSession, init): | |
""" | |
Facebook application must be configurd as web application, running in http://localhost:8521/. | |
Example invocation: FACEBOOK_USER="040xxxXXXX" FACEBOOK_PASSWORD="yyyy" py.test trees -s --splinter-webdriver=firefox --splinter-make-screenshot-on-failure=false --ini=test.ini -k test_facebook_login | |
:param web_server: Py.text fixture, gives HTTP address where the functional test web server is running, ``http://localhost:8521/`` | |
:param browser: Py.test Splinter Browser fixture | |
:param DBSession: Py.test SQLALchemy session | |
:param init: Websauna configuration object | |
""" | |
b = browser | |
# Initiate Facebook login with Authomatic | |
b.visit("{}/login".format(web_server)) | |
b.find_by_css(".btn-login-facebook").click() | |
do_facebook_login(b) | |
# Generated by our backend on succesful oauth login | |
assert b.is_text_present("You are now logged in") | |
assert b.is_text_present("Log out") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment