-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·107 lines (94 loc) · 4.28 KB
/
tests.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from urllib2 import Request, urlopen
from json import loads
URL = 'http://localhost:8080'
DELAY = 200
COUNTRY_ID = 'ESP'
class TestCase(unittest.TestCase):
def setUp(self):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox') # required when running as root user. otherwise you would get no sandbox errors.
self.browser = webdriver.Chrome('/var/www/files/chromedriver', chrome_options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
self.browser.implicitly_wait(DELAY)
def testElementsExists(self):
self.browser.get(URL)
self.assertTrue(self.browser.find_element_by_id('search-input'))
self.assertTrue(self.browser.find_element_by_id('search-button'))
self.assertTrue(self.browser.find_element_by_id('spinner'))
self.assertTrue(self.browser.find_element_by_id('switch-draw'))
self.assertTrue(self.browser.find_element_by_id('switch-draw'))
self.assertTrue(self.browser.find_element_by_id('panel'))
self.assertTrue(self.browser.find_element_by_id('button-about'))
self.assertTrue(self.browser.find_element_by_id('dialog'))
def testMapId(self):
self.browser.get(URL)
map_id = self.browser.find_element_by_id('input-save-map')
self.assertNotEquals('', map_id.get_attribute("value"))
def testChangeMap0(self):
self.browser.get(URL)
i = 0
try:
change_menu = WebDriverWait(self.browser, DELAY).until(EC.element_to_be_clickable((By.ID, 'menu-change-map')))
change_menu.click()
mapid = str(i)
search = "//li[@map_id='" + mapid + "']"
map = WebDriverWait(self.browser, DELAY).until(EC.element_to_be_clickable((By.XPATH, search)))
map.click()
map_id = self.browser.find_element_by_id('input-save-map')
self.assertEquals(mapid, map_id.get_attribute("value"))
except Exception as e:
print(e)
def testChangeMap1(self):
self.browser.get(URL)
i = 1
try:
change_menu = WebDriverWait(self.browser, DELAY).until(EC.element_to_be_clickable((By.ID, 'menu-change-map')))
change_menu.click()
mapid = str(i)
search = "//li[@map_id='" + mapid + "']"
map = WebDriverWait(self.browser, DELAY).until(EC.element_to_be_clickable((By.XPATH, search)))
map.click()
map_id = self.browser.find_element_by_id('input-save-map')
self.assertEquals(mapid, map_id.get_attribute("value"))
except Exception as e:
print(e)
def testChangeMap6(self):
self.browser.get(URL)
i = 6
try:
change_menu = WebDriverWait(self.browser, DELAY).until(EC.element_to_be_clickable((By.ID, 'menu-change-map')))
change_menu.click()
mapid = str(i)
search = "//li[@map_id='" + mapid + "']"
map = WebDriverWait(self.browser, DELAY).until(EC.element_to_be_clickable((By.XPATH, search)))
map.click()
map_id = self.browser.find_element_by_id('input-save-map')
self.assertEquals(mapid, map_id.get_attribute("value"))
except Exception as e:
print(e)
def testgetMap(self):
for i in range(0,6):
res = urlopen(URL + '/map/' + str(i))
self.assertEqual(res.code, 200)
text = res.read()
self.assertTrue(str(i) in text)
self.assertTrue("ESP" in text)
self.assertTrue("ZWE" in text)
def testgetCountryNotExists(self):
try:
urlopen(URL + '/details/5/' + 'ESN')
except Exception as e:
self.assertIn('500', str(e))
def testgetTimeSeriesNotExists(self):
try:
urlopen(URL + '/details/7/' + COUNTRY_ID)
except Exception as e:
self.assertIn('500', str(e))
if __name__ == '__main__':
unittest.main(verbosity = 2)