File: test_base.py

package info (click to toggle)
django-session-security 2.6.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 660 kB
  • sloc: javascript: 6,675; python: 594; makefile: 134; sh: 10
file content (59 lines) | stat: -rw-r--r-- 2,048 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import time
import atexit

from django.contrib.auth.models import User

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver;
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver import Remote
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.test import LiveServerTestCase

from selenium.common.exceptions import NoSuchElementException

from session_security.settings import WARN_AFTER, EXPIRE_AFTER


WAIT_TIME = 5 if not os.environ.get('CI', False) else 30


class SettingsMixin(object):
    def setUp(self):
        # Give some time for selenium lag
        self.min_warn_after = WARN_AFTER
        self.max_warn_after = EXPIRE_AFTER * 0.9
        self.min_expire_after = EXPIRE_AFTER
        self.max_expire_after = EXPIRE_AFTER * 1.5
        super(SettingsMixin, self).setUp()


class BaseLiveServerTestCase(SettingsMixin, StaticLiveServerTestCase,
                             LiveServerTestCase):

    fixtures = ['session_security_test_user']

    def setUp(self):
        SettingsMixin.setUp(self)
        from selenium.webdriver.firefox.options import Options as FirefoxOptions

        options = FirefoxOptions()
        options.add_argument("--headless")
        super(LiveServerTestCase, self).setUp()
        self.sel= webdriver.Firefox(options=options)
        self.sel.get('%s%s' % (self.live_server_url, '/admin/'))
        self.sel.find_element_by_name('username').send_keys('test')
        self.sel.find_element_by_name('password').send_keys('test')
        self.sel.find_element_by_xpath('//input[@value="Log in"]').click()
        self.sel.execute_script('window.open("/admin/", "other")')

    def press_space(self):
        body = self.sel.find_element_by_tag_name("body")
        body.send_keys(Keys.SPACE)
    def tearDown(self):
        self.sel.quit()
    @classmethod
    def tearDownClass(cls):
        super(BaseLiveServerTestCase, cls).tearDownClass()