Added a better way to delete users. Catched the exception for perm_list.
[e_cidadania.git] / tests / functional_utils.py
blobe03bcb611473d550a51346de3f7be1970ba60d22
1 #/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Copyright (c) 2010-2012 Cidadania S. Coop. Galega
6 # This file is part of e-cidadania.
8 # e-cidadania is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # e-cidadania is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with e-cidadania. If not, see <http://www.gnu.org/licenses/>.
21 import time
23 from selenium import webdriver
24 from selenium.webdriver.common.keys import Keys
26 from django.test import LiveServerTestCase
28 from tests.test_utils import ECDTestCase
32 class FunctionalTestCase(ECDTestCase, LiveServerTestCase):
33 """
34 Class which provides functional testing capabilities. It subclasses both
35 our custom ECDTestCase and django's LiveServerTestCase. LiveServerTestCase
36 was introduced in Django 1.4 to support functional testing.
37 """
39 def init(self):
40 ECDTestCase.init(self)
41 self.browser = webdriver.Firefox()
43 def setUp(self):
44 """
45 Setup done prior to a test run.
46 """
47 self.init()
49 def tearDown(self):
50 """
51 Actions taken after a test run.
52 """
53 self.browser.quit()
55 def wait(self, sec):
56 """
57 Halts script execution for `sec` seconds.
59 This is necessary because the script executes faster than the browser.
60 """
61 time.sleep(sec)
62 return
64 def login(self, browser, username='test_user', password='test_password'):
65 """
66 Logs into e-cidadania.
67 """
68 username_field = browser.find_element_by_name('username')
69 username_field.send_keys(username)
71 password_field = browser.find_element_by_name('password')
72 password_field.send_keys(password)
73 self.wait(2)
74 password_field.send_keys(Keys.RETURN)