File: test_script.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 (89 lines) | stat: -rw-r--r-- 3,445 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import datetime
import time

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By

from .test_base import BaseLiveServerTestCase, WAIT_TIME

''' Tests disabled due to 'selenium.common.exceptions.NoSuchDriverException:
Message: Unable to obtain driver for firefox using Selenium Manager.'.
Futher investigation needed.

class ScriptTestCase(BaseLiveServerTestCase):


    def test_warning_shows_and_session_expires(self):
        start = datetime.datetime.now()

        for win in self.sel.window_handles:
            self.sel.switch_to.window(win)
            try:
                el = WebDriverWait(self.sel, self.max_warn_after).until(
                expected_conditions.visibility_of_element_located((By.ID, "session_security_warning")))
                assert(el.is_displayed())
            except:
                assert(False) #max_warn_after did not display el.
        end = datetime.datetime.now()
        delta = end - start

        self.assertGreaterEqual(delta.seconds, self.min_warn_after)
        self.assertLessEqual(delta.seconds, self.max_warn_after)

        for win in self.sel.window_handles:
            self.sel.switch_to.window(win)
            try:
                el = WebDriverWait(self.sel, self.max_expire_after).until(
                expected_conditions.visibility_of_element_located((By.ID, "id_password")))
                assert(el.is_displayed())
                delta = datetime.datetime.now() - start
                self.assertGreaterEqual(delta.seconds, self.min_expire_after)
                self.assertLessEqual(delta.seconds, self.max_expire_after)
            except:
                assert(False) #Test fails if timeout expires

    def test_activity_hides_warning(self):
        time.sleep(6 * .7)
        try:
            WebDriverWait(self.sel, self.max_warn_after).until(
            expected_conditions.visibility_of_element_located((By.ID, "session_security_warning")))

            self.press_space()

            for win in self.sel.window_handles:
                self.sel.switch_to.window(win)

            try:
                el = WebDriverWait(self.sel, 20).until(
                expected_conditions.invisibility_of_element_located((By.ID, "session_security_warning")))

                assert(not el.is_displayed())
            except:
                assert(False)  #Test fails if element invisibilty times out
        except:
            assert(False)  #Test fails if element visility times out



    def test_activity_prevents_warning(self):
        time.sleep(self.min_warn_after * .7)
        self.press_space()
        start = datetime.datetime.now()
        try:
            el = WebDriverWait(self.sel, self.max_warn_after).until(
            expected_conditions.visibility_of_element_located((By.ID, "session_security_warning")))
            assert(el.is_displayed())

            for win in self.sel.window_handles:
                self.sel.switch_to.window(win)

            delta = datetime.datetime.now() - start
            self.assertGreaterEqual(delta.seconds, self.min_warn_after)
        except:
            assert(False)
'''