From: Miguel Araujo Perez Date: Sun, 27 Mar 2011 17:58:26 +0000 (+0200) Subject: Adding Twitter Backend testing using Selenium2 aka "WebDriver" X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e4d25192be294a18ede2f6c77774003fb99c67ba;p=django-social-auth.git Adding Twitter Backend testing using Selenium2 aka "WebDriver" --- diff --git a/social_auth/tests/__init__.py b/social_auth/tests/__init__.py new file mode 100644 index 0000000..4d20f0e --- /dev/null +++ b/social_auth/tests/__init__.py @@ -0,0 +1 @@ +from test_core import * diff --git a/social_auth/tests/runtests.py b/social_auth/tests/runtests.py new file mode 100755 index 0000000..7ff2e20 --- /dev/null +++ b/social_auth/tests/runtests.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import os, sys + +os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings' +parent = os.path.dirname(os.path.dirname(os.path.dirname( + os.path.abspath(__file__)))) + +sys.path.insert(0, parent) + +from django.test.simple import run_tests +from django.conf import settings + +def runtests(): + failures = run_tests([ + 'social_auth.BackendTest', + ], verbosity=1, interactive=True) + sys.exit(failures) + +if __name__ == '__main__': + runtests() + diff --git a/social_auth/tests/test_core.py b/social_auth/tests/test_core.py new file mode 100644 index 0000000..79484f7 --- /dev/null +++ b/social_auth/tests/test_core.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +from selenium import webdriver + +from django.test import TestCase +from django.conf import settings + + +class BackendTest(TestCase): + def setUp(self): + self.driver = webdriver.Firefox() + + def test_twitter_backend(self): + # We grab the Twitter testing user details from settings file + TEST_TWITTER_USER = getattr(settings, 'TEST_TWITTER_USER', None) + TEST_TWITTER_PASSWORD = getattr(settings, 'TEST_TWITTER_PASSWORD', None) + self.assertTrue(TEST_TWITTER_USER) + self.assertTrue(TEST_TWITTER_PASSWORD) + + self.driver.get("http://social.matiasaguirre.net/login/twitter/") + + # We log in + username_field = self.driver.find_element_by_id("username_or_email") + username_field.send_keys(TEST_TWITTER_USER) + + password_field = self.driver.find_element_by_id("session[password]") + password_field.send_keys(TEST_TWITTER_PASSWORD) + password_field.submit() + + # The application might be already allowed + try: + self.driver.find_element_by_id("allow").click() + except: + pass + + # We check the user logged in + heading = self.driver.find_element_by_id("heading") + if not heading.text == u'Logged in!': + raise Exception("The user didn't logged in") + + # Here we could test the User's fields + + self.driver.quit() diff --git a/social_auth/tests/test_settings.py b/social_auth/tests/test_settings.py new file mode 100644 index 0000000..6f147fd --- /dev/null +++ b/social_auth/tests/test_settings.py @@ -0,0 +1,16 @@ +import os + +BASE_DIR = os.path.dirname(__file__) + +INSTALLED_APPS = ( + 'social_auth', +) + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + } +} + +TEST_TWITTER_USER = "" +TEST_TWITTER_PASSWORD = ""