1
|
|
|
from pyvirtualdisplay import Display |
2
|
|
|
from selenium import webdriver |
3
|
|
|
from selenium.common.exceptions import NoSuchElementException |
4
|
|
|
from django.core.urlresolvers import reverse |
5
|
|
|
from django.contrib.staticfiles.testing import StaticLiveServerTestCase |
6
|
|
|
from django.utils import formats |
7
|
|
|
from ..testing_utilities import populate_test_db |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class FunctionalTest(StaticLiveServerTestCase): |
11
|
|
|
def setUp(self): |
12
|
|
|
display = Display(visible=0, size=(800, 600)) |
13
|
|
|
display.start() |
14
|
|
|
|
15
|
|
|
self.selenium = webdriver.Firefox() |
16
|
|
|
self.selenium.implicitly_wait(3) |
17
|
|
|
populate_test_db() |
18
|
|
|
|
19
|
|
|
def tearDown(self): |
20
|
|
|
self.selenium.quit() |
21
|
|
|
|
22
|
|
|
# Auxiliary function to add view subdir to URL |
23
|
|
|
def _get_full_url(self, namespace): |
24
|
|
|
return self.live_server_url + namespace |
25
|
|
|
|
26
|
|
|
def _is_text_present(self, text): |
27
|
|
|
try: |
28
|
|
|
body = self.selenium.find_element_by_tag_name("body") |
29
|
|
|
except NoSuchElementException, e: |
30
|
|
|
return False |
31
|
|
|
return text in body.text # check if the text is in body's text |
32
|
|
|
|
33
|
|
|
def test_home_title(self): |
34
|
|
|
""" |
35
|
|
|
Tests that Home is loading properly |
36
|
|
|
""" |
37
|
|
|
self.selenium.get(self._get_full_url("/")) |
38
|
|
|
self.assertIn(u'Metadata Explorer Tool', self.selenium.title) |
39
|
|
|
|
40
|
|
|
def test_home_sections(self): |
41
|
|
|
""" |
42
|
|
|
Tests that Home is showing the right sections |
43
|
|
|
""" |
44
|
|
|
self.selenium.get(self._get_full_url("/")) |
45
|
|
|
self.assertTrue(self._is_text_present("Entities summary")) |
46
|
|
|
|