|
24 | 24 | import pynag.Parsers |
25 | 25 | import os |
26 | 26 | from django.test.client import RequestFactory |
| 27 | +from django.test import LiveServerTestCase |
27 | 28 | import adagios.status |
28 | 29 | import adagios.status.utils |
29 | 30 | import adagios.status.graphite |
30 | 31 | import adagios.settings |
31 | 32 | import adagios.utils |
32 | 33 | import simplejson as json |
33 | 34 |
|
| 35 | +try: |
| 36 | + from selenium.webdriver.common.by import By |
| 37 | +except ImportError: |
| 38 | + pass |
| 39 | + |
34 | 40 |
|
35 | 41 | class LiveStatusTestCase(unittest.TestCase): |
36 | 42 |
|
@@ -103,7 +109,7 @@ def test_status_detail(self): |
103 | 109 | tmp = self.loadPage('/status/detail?contactgroup_name=admins') |
104 | 110 | self.assertTrue('nagiosadmin' in tmp.content) |
105 | 111 |
|
106 | | - |
| 112 | + |
107 | 113 | def testStateHistory(self): |
108 | 114 | request = self.factory.get('/status/state_history') |
109 | 115 | adagios.status.views.state_history(request) |
@@ -171,3 +177,54 @@ def test_get(self): |
171 | 177 | self.assertTrue(len(result) == 1) |
172 | 178 | self.assertTrue('rta' in result[0]['metrics']) |
173 | 179 | self.assertTrue('packetloss' in result[0]['metrics']) |
| 180 | + |
| 181 | + |
| 182 | +class SeleniumStatusTestCase(adagios.utils.SeleniumTestCase): |
| 183 | + def test_network_parents(self): |
| 184 | + """Status Overview, Network Parents should show an integer""" |
| 185 | + self.driver.get(self.live_server_url + "/status") |
| 186 | + |
| 187 | + # Second link is Network Parents in overview |
| 188 | + self.assertEqual(self.driver.find_elements(By.XPATH, |
| 189 | + "//a[@href='/status/parents']")[1].text.isdigit(), True) |
| 190 | + |
| 191 | + def test_services_select_all(self): |
| 192 | + """Loads services list and tries to select everything |
| 193 | +
|
| 194 | + Flow: |
| 195 | + Load http://<url>/status/services |
| 196 | + Click select all |
| 197 | + Look for statustable rows |
| 198 | + Assert that all rows are checked""" |
| 199 | + |
| 200 | + self.driver.get(self.live_server_url + "/status/services") |
| 201 | + |
| 202 | + self.driver.find_element_by_xpath("//input[@class='select_many']").click() |
| 203 | + self.driver.find_element_by_xpath("//a[@class='select_all']").click() |
| 204 | + |
| 205 | + # Get all statustable rows |
| 206 | + status_table_rows = self.driver.find_element_by_xpath( |
| 207 | + "//table[contains(@class, 'statustable')]" |
| 208 | + ).find_elements(By.XPATH, "//tbody/tr[contains(@class, 'mainrow')]") |
| 209 | + |
| 210 | + # Sub-select non-selected |
| 211 | + for row in status_table_rows: |
| 212 | + self.assertTrue('row_selected' in row.get_attribute('class'), |
| 213 | + "Non selected row found after selecting all: " + \ |
| 214 | + row.text) |
| 215 | + |
| 216 | + def test_status_overview_top_alert_producers(self): |
| 217 | + """Check the top alert producers part of status overview""" |
| 218 | + |
| 219 | + self.driver.get(self.live_server_url + "/status") |
| 220 | + |
| 221 | + top_alert_table_rows = self.driver.find_elements(By.XPATH, |
| 222 | + "//table[@id='top_alert_producers']/tbody/tr" |
| 223 | + ) |
| 224 | + |
| 225 | + count = 0 |
| 226 | + for row in top_alert_table_rows: |
| 227 | + if 'display' not in row.get_attribute('style'): |
| 228 | + count += 1 |
| 229 | + |
| 230 | + self.assertTrue(count <= 3, "Top alert producers returns too many rows") |
0 commit comments