+# -*- coding: utf-8 -*-\r
import os\r
import inspect\r
-from urlparse import urlparse\r
\r
from django.test import LiveServerTestCase\r
from django.test.client import Client\r
from django.conf import settings\r
-from django.contrib.auth.models import User, Permission\r
+from django.contrib.auth.models import User\r
from django.utils.translation import ugettext as _\r
\r
-from selenium import webdriver, selenium\r
-from selenium.webdriver.support.wait import WebDriverWait\r
+from selenium import webdriver\r
\r
\r
class SeleniumTestCase(LiveServerTestCase):\r
LiveServerTestCase.setUpClass()\r
cls.browser = getattr(webdriver, os.environ.get('TEST_BROWSER', 'Firefox'))()\r
cls.browser.implicitly_wait(5)\r
- \r
+\r
@classmethod\r
def tearDownClass(cls):\r
LiveServerTestCase.tearDownClass()\r
cls.browser.quit()\r
- \r
+\r
def setUp(self):\r
self.browser.delete_all_cookies()\r
- \r
- def create_user(self, username = 'testuser', passwd = 'passwd', do_login = False):\r
+\r
+ def create_user(self, username='testuser', passwd='passwd', do_login=False):\r
user = User.objects.create_user(username, '', passwd)\r
user._plain_passwd = passwd\r
if do_login:\r
self.login_user(user)\r
return user\r
- \r
+\r
def create_super_user(self, *args, **kwargs):\r
user = self.create_user(*args, **kwargs)\r
user.is_superuser = True\r
user.save()\r
return user\r
- \r
+\r
def login_user(self, user):\r
client = Client()\r
- client.login(username = user.username, password = user._plain_passwd)\r
+ client.login(username=user.username, password=user._plain_passwd)\r
\r
if not self.browser.current_url.startswith(self.live_server_url):\r
self.browser.get(self.live_server_url+'/not_existing_url')\r
- \r
- self.browser.find_element_by_tag_name('body') # Make sure the page is actually loaded before setting the cookie\r
+\r
+ self.browser.find_element_by_tag_name('body') # Make sure the page is actually loaded before setting the cookie\r
self.browser.delete_cookie(settings.SESSION_COOKIE_NAME)\r
- self.browser.add_cookie(dict(name = settings.SESSION_COOKIE_NAME, \r
- value = client.cookies[settings.SESSION_COOKIE_NAME].value,\r
- path = '/')\r
- )\r
- \r
+ self.browser.add_cookie(dict(name=settings.SESSION_COOKIE_NAME,\r
+ value=client.cookies[settings.SESSION_COOKIE_NAME].value,\r
+ path='/'))\r
+\r
def get_main_page(self):\r
self.browser.get(self.live_server_url)\r
self.browser.find_element_by_tag_name('body')\r
return MainPage(self.browser)\r
\r
- \r
+\r
class Page(object):\r
def __init__(self, browser):\r
self.browser = browser\r
- \r
- \r
+\r
+\r
class MainPage(Page):\r
\r
def __init__(self, browser):\r
Page.__init__(self, browser)\r
self.tab = None\r
- \r
+\r
@property\r
def element(self):\r
return self.browser.find_element_by_tag_name('body')\r
- \r
+\r
def select_tab(self, tab_title):\r
for a in self.element.find_element_by_id('tabs-nav-left').find_elements_by_tag_name('a'):\r
if a.text == tab_title:\r
a.click()\r
self.tab = find_tab_class(tab_title)(self.browser)\r
return\r
- raise Exception, 'Tab not found'\r
- \r
- \r
-def find_tab_class(tab_title): \r
+ raise Exception('Tab not found')\r
+\r
+\r
+def find_tab_class(tab_title):\r
for obj in globals().values():\r
if inspect.isclass(obj) and issubclass(obj, MainPageTabBase) and getattr(obj, 'tab_title', None) == tab_title:\r
return obj\r
raise NotImplementedError\r
- \r
+\r
\r
class MainPageTabBase(Page):\r
def __init__(self, browser):\r
Page.__init__(self, browser)\r
- \r
+\r
@property\r
def element(self):\r
return self.browser.find_element_by_id('content')\r
- \r
+\r
\r
class AddBookPage(MainPageTabBase):\r
tab_title = _('Add')\r
- \r
+\r
def put_title(self, title):\r
self.element.find_element_by_id('id_title').send_keys(title)\r
- \r
+\r
def put_text(self, text):\r
self.element.find_element_by_id('id_text').send_keys(text)\r
- \r
+\r
def submit(self):\r
self.browser.find_element_by_css_selector('table.editable button').click()\r
return self.browser\r
- \r
- \r
+\r
+\r
class BooksListPage(MainPageTabBase):\r
tab_title = _('All')\r
- \r
+\r
@property\r
def visible_books_count(self):\r
return len(self.element.find_element_by_id('file-list').find_elements_by_tag_name('tr')) - 2\r
- \r
-
\ No newline at end of file