test_get_routes.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import pytest
  2. from .supports import login
  3. from app import models
  4. from lxml import html
  5. from random import choice
  6. #
  7. # GET simple routes
  8. #
  9. def test_favicon(client):
  10. r = client.get('/favicon.ico')
  11. assert r.status_code == 200, f'status code: {r.status_code}'
  12. def test_home(client, test_user):
  13. # unauthorized access
  14. r = client.get('/')
  15. assert r.status_code == 302, f'Unauthorized access. Status code: {r.status_code}'
  16. # assert redirection url
  17. page = html.fromstring(r.data)
  18. assert '/login?' in page.xpath('//a')[0].attrib.get('href'), 'Unauthorized access: wrong redirection'
  19. # authorized access
  20. login(client, test_user)
  21. r = client.get('/')
  22. # assert home page rendered
  23. assert r.status_code == 200, f'Authorized access. Status code: {r.status_code}'
  24. page = html.fromstring(r.data)
  25. title = page.xpath('./head/title')[0].text.strip()
  26. assert 'home' in title.lower(), f"Title: {title}. Should contain 'Home'"
  27. # assert links exist for every baangt element
  28. items = [link.text.lower() for link in page.xpath('//div[@id="item-list"]/a')]
  29. assert 'testruns' in items, "Item 'Testruns' is not in item list"
  30. assert 'test case sequences' in items, "Item 'Test Case Sequences' is not in list"
  31. assert 'test cases' in items, "Item 'Test Cases' is not in item list"
  32. assert 'test step sequences' in items, "Item 'Test Step Sequences' is not in item list"
  33. assert 'test steps' in items, "Item 'Test Steps' is not in item list"
  34. # assert item links are valid
  35. for link in page.xpath('//div[@id="item-list"]/a'):
  36. r = client.get(link.attrib['href'])
  37. assert r.status_code == 200, f'Accessing {link.attrib["href"]}. Status code: {r.status_code}'
  38. #
  39. # GET pages with baangt item lists
  40. #
  41. @pytest.mark.parametrize('count', [(1,2), (5,1)])
  42. def test_testruns(client, test_user, populate):
  43. url = '/testrun'
  44. # unauthorized access
  45. r = client.get(url)
  46. assert r.status_code == 302, f'Unauthorized access. Status code: {r.status_code}'
  47. # assert redirection url
  48. page = html.fromstring(r.data)
  49. assert '/login?' in page.xpath('//a')[0].attrib.get('href'), 'Unauthorized access: wrong redirection'
  50. # authorized access
  51. login(client, test_user)
  52. r = client.get(url)
  53. # assert testrun page rendered
  54. assert r.status_code == 200, f'Authorized access. Status code: {r.status_code}'
  55. page = html.fromstring(r.data)
  56. title = page.xpath('./head/title')[0].text.strip()
  57. assert 'testruns' in title.lower(), f"Title: {title}. Should contain 'Testruns'"
  58. # common buttons
  59. assert bool(page.xpath('//a[@id="create-testrun"]')), "Button 'Create Testrun' does not exist"
  60. assert bool(page.xpath('//button[@id="import-testrun"]')), "Button 'Import Testrun' does not exist"
  61. # search field
  62. assert bool(page.xpath('//input[@id="filter"]')), "Search field does not exist"
  63. # testrun details
  64. # count
  65. divs = page.xpath(f'//div[contains(@class, "testrun-item")]')
  66. items = models.Testrun.query.all()
  67. assert len(divs) == len(items)
  68. # get random item
  69. item = choice(items)
  70. div = list(filter(lambda d: d.attrib.get('id') == f'item{item.uuid}', divs))
  71. assert bool(div), 'Page does not contain the item'
  72. div = div[0]
  73. assert bool(div.xpath('.//*[contains(@class, "btn-edit")]')), "utton 'Edit' absents"
  74. assert bool(div.xpath('.//*[contains(@class, "btn-update")]')), "Button 'Update' absents"
  75. assert bool(div.xpath('.//*[contains(@class, "btn-export")]')), "Button 'Export' absents"
  76. assert bool(div.xpath('.//*[contains(@class, "btn-run")]')), "Button 'Run' absents"
  77. assert bool(div.xpath('.//*[contains(@class, "btn-delete")]')), "Button 'Delete' absents"
  78. @pytest.mark.parametrize('count', [(1,1), (1,5)])
  79. def test_testcase_sequence(client, test_user, populate):
  80. url = '/testcase_sequence'
  81. # unauthorized access
  82. r = client.get(url)
  83. assert r.status_code == 302, f'Unauthorized access. Status code: {r.status_code}'
  84. # assert redirection url
  85. page = html.fromstring(r.data)
  86. assert '/login?' in page.xpath('//a')[0].attrib.get('href'), 'Unauthorized access: wrong redirection'
  87. # authorized access
  88. login(client, test_user)
  89. r = client.get(url)
  90. # assert testcase_sequence page rendered
  91. assert r.status_code == 200, f'Authorized access. Status code: {r.status_code}'
  92. page = html.fromstring(r.data)
  93. title = page.xpath('./head/title')[0].text.strip()
  94. assert 'test case sequences' in title.lower(), f"Title: {title}. Should contain 'Test Case Sequences'"
  95. # common buttons
  96. assert bool(page.xpath('//a[@id="create-testcase_sequence"]')), "Button 'Create Test Case Sequence' does not exist"
  97. assert not bool(page.xpath('//button[@id="import-testrun"]')), "Button 'Import' should be hide"
  98. # search field
  99. assert bool(page.xpath('//input[@id="filter"]')), "Search field does not exist"
  100. # test case sequence details
  101. # count
  102. divs = page.xpath(f'//div[contains(@class, "testrun-item")]')
  103. items = models.TestCaseSequence.query.all()
  104. assert len(divs) == len(items)
  105. # get random item
  106. item = choice(items)
  107. div = list(filter(lambda d: d.attrib.get('id') == f'item{item.uuid}', divs))
  108. assert bool(div), 'Page does not contain the item'
  109. div = div[0]
  110. assert bool(div.xpath('.//*[contains(@class, "btn-edit")]')), "Button 'Edit' absents"
  111. assert not bool(div.xpath('.//*[contains(@class, "btn-update")]')), "Button 'Update' should be hide"
  112. assert not bool(div.xpath('.//*[contains(@class, "btn-export")]')), "Button 'Export' should be hide"
  113. assert not bool(div.xpath('.//*[contains(@class, "btn-run")]')), "Button 'Run' should be hide"
  114. assert bool(div.xpath('.//*[contains(@class, "btn-delete")]')), "Button 'Delete' absents"
  115. # datafile buttons
  116. assert bool(div.xpath('.//*[contains(@class, "btn-datafile-update")]')), "Datafile button 'Update' absents"
  117. assert bool(div.xpath('.//*[contains(@class, "btn-datafile-download")]')), "Datafile button 'Download' absents"
  118. @pytest.mark.parametrize('count', [(1,1), (1,5)])
  119. def test_testcase(client, test_user, populate):
  120. url = '/testcase'
  121. # unauthorized access
  122. r = client.get(url)
  123. assert r.status_code == 302, f'Unauthorized access. Status code: {r.status_code}'
  124. # assert redirection url
  125. page = html.fromstring(r.data)
  126. assert '/login?' in page.xpath('//a')[0].attrib.get('href'), 'Unauthorized access: wrong redirection'
  127. # authorized access
  128. login(client, test_user)
  129. r = client.get(url)
  130. # assert testcase_sequence page rendered
  131. assert r.status_code == 200, f'Authorized access. Status code: {r.status_code}'
  132. page = html.fromstring(r.data)
  133. title = page.xpath('./head/title')[0].text.strip()
  134. assert 'test case' in title.lower(), f"Title: {title}. Should contain 'Test Cases'"
  135. # common buttons
  136. assert bool(page.xpath('//a[@id="create-testcase"]')), "Button 'Create Test Case' does not exist"
  137. assert not bool(page.xpath('//button[@id="import-testrun"]')), "Button 'Import' should be hide"
  138. # search field
  139. assert bool(page.xpath('//input[@id="filter"]')), "Search field does not exist"
  140. # test case details
  141. # count
  142. divs = page.xpath(f'//div[contains(@class, "testrun-item")]')
  143. items = models.TestCase.query.all()
  144. assert len(divs) == len(items)
  145. # get random item
  146. item = choice(items)
  147. div = list(filter(lambda d: d.attrib.get('id') == f'item{item.uuid}', divs))
  148. assert bool(div), 'Page does not contain the item'
  149. div = div[0]
  150. assert bool(div.xpath('.//*[contains(@class, "btn-edit")]')), "Button 'Edit' absents"
  151. assert not bool(div.xpath('.//*[contains(@class, "btn-update")]')), "Button 'Update' should be hide"
  152. assert not bool(div.xpath('.//*[contains(@class, "btn-export")]')), "Button 'Export' should be hide"
  153. assert not bool(div.xpath('.//*[contains(@class, "btn-run")]')), "Button 'Run' should be hide"
  154. assert bool(div.xpath('.//*[contains(@class, "btn-delete")]')), "Button 'Delete' absents"
  155. @pytest.mark.parametrize('count', [(1,1), (2,5)])
  156. def test_teststep_sequence(client, test_user, populate):
  157. url = '/teststep_sequence'
  158. # unauthorized access
  159. r = client.get(url)
  160. assert r.status_code == 302, f'Unauthorized access. Status code: {r.status_code}'
  161. # assert redirection url
  162. page = html.fromstring(r.data)
  163. assert '/login?' in page.xpath('//a')[0].attrib.get('href'), 'Unauthorized access: wrong redirection'
  164. # authorized access
  165. login(client, test_user)
  166. r = client.get(url)
  167. # assert testcase_sequence page rendered
  168. assert r.status_code == 200, f'Authorized access. Status code: {r.status_code}'
  169. page = html.fromstring(r.data)
  170. title = page.xpath('./head/title')[0].text.strip()
  171. assert 'test step sequences' in title.lower(), f"Title: {title}. Should contain 'Test Step Sequences'"
  172. # common buttons
  173. assert bool(page.xpath('//a[@id="create-teststep_sequence"]')), "Button 'Create Test Step Sequence' does not exist"
  174. assert not bool(page.xpath('//button[@id="import-testrun"]')), "Button 'Import' should be hide"
  175. # search field
  176. assert bool(page.xpath('//input[@id="filter"]')), "Search field does not exist"
  177. # test step sequence details
  178. # count
  179. divs = page.xpath(f'//div[contains(@class, "testrun-item")]')
  180. items = models.TestStepSequence.query.all()
  181. assert len(divs) == len(items)
  182. # get random item
  183. item = choice(items)
  184. div = list(filter(lambda d: d.attrib.get('id') == f'item{item.uuid}', divs))
  185. assert bool(div), 'Page does not contain the item'
  186. div = div[0]
  187. assert bool(div.xpath('.//*[contains(@class, "btn-edit")]')), "Button 'Edit' absents"
  188. assert not bool(div.xpath('.//*[contains(@class, "btn-update")]')), "Button 'Update' should be hide"
  189. assert not bool(div.xpath('.//*[contains(@class, "btn-export")]')), "Button 'Export' should be hide"
  190. assert not bool(div.xpath('.//*[contains(@class, "btn-run")]')), "Button 'Run' should be hide"
  191. assert bool(div.xpath('.//*[contains(@class, "btn-delete")]')), "Button 'Delete' absents"
  192. @pytest.mark.parametrize('count', [(1,1), (2,5)])
  193. def test_teststep(client, test_user, populate):
  194. url = '/teststep'
  195. # unauthorized access
  196. r = client.get(url)
  197. assert r.status_code == 302, f'Unauthorized access. Status code: {r.status_code}'
  198. # assert redirection url
  199. page = html.fromstring(r.data)
  200. assert '/login?' in page.xpath('//a')[0].attrib.get('href'), 'Unauthorized access: wrong redirection'
  201. # authorized access
  202. login(client, test_user)
  203. r = client.get(url)
  204. # assert testcase_sequence page rendered
  205. assert r.status_code == 200, f'Authorized access. Status code: {r.status_code}'
  206. page = html.fromstring(r.data)
  207. title = page.xpath('./head/title')[0].text.strip()
  208. assert 'test steps' in title.lower(), f"Title: {title}. Should contain 'Test Steps'"
  209. # common buttons
  210. assert bool(page.xpath('//a[@id="create-teststep"]')), "Button 'Create Test Step' does not exist"
  211. assert not bool(page.xpath('//button[@id="import-testrun"]')), "Button 'Import' should be hide"
  212. # search field
  213. assert bool(page.xpath('//input[@id="filter"]')), "Search field does not exist"
  214. # test step details
  215. divs = page.xpath(f'//div[contains(@class, "testrun-item")]')
  216. items = models.TestStepExecution.query.all()
  217. assert len(divs) == len(items)
  218. # get random item
  219. item = choice(items)
  220. div = list(filter(lambda d: d.attrib.get('id') == f'item{item.uuid}', divs))
  221. assert bool(div), 'Page does not contain the item'
  222. div = div[0]
  223. assert bool(div.xpath('.//*[contains(@class, "btn-edit")]')), "Button 'Edit' absents"
  224. assert not bool(div.xpath('.//*[contains(@class, "btn-update")]')), "Button 'Update' should be hide"
  225. assert not bool(div.xpath('.//*[contains(@class, "btn-export")]')), "Button 'Export' should be hide"
  226. assert not bool(div.xpath('.//*[contains(@class, "btn-run")]')), "Button 'Run' should be hide"
  227. assert bool(div.xpath('.//*[contains(@class, "btn-delete")]')), "Button 'Delete' absents"
  228. def test_fake_item(client, test_user):
  229. url = '/fakeitem'
  230. # unauthorized access
  231. r = client.get(url)
  232. assert r.status_code == 302, f'Unauthorized access. Status code: {r.status_code}'
  233. # assert redirection url
  234. page = html.fromstring(r.data)
  235. assert '/login?' in page.xpath('//a')[0].attrib.get('href'), 'Unauthorized access: wrong redirection'
  236. # authorized access
  237. login(client, test_user)
  238. r = client.get(url, follow_redirects=True)
  239. assert r.status_code == 200, f'Authorized access. Status code: {r.status_code}'
  240. # assert warning message
  241. page = html.fromstring(r.data)
  242. flash_area = page.xpath('//div[@id="flash-area"]')
  243. assert bool(flash_area), 'Flash Messages absent'
  244. assert bool(flash_area[0].xpath('./div[contains(@class, "alert-warning")]')), 'Warning message is absent'