No Description

test_base.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # -*- encoding: utf-8 -*-
  2. """
  3. License: MIT
  4. Copyright (c) 2019 - present AppSeed.us
  5. """
  6. from logging import CRITICAL, disable
  7. disable(CRITICAL)
  8. urls = {
  9. '': (
  10. '/fixed_sidebar',
  11. '/fixed_footer',
  12. '/plain_page',
  13. '/page_403',
  14. '/page_404',
  15. '/page_500'
  16. ),
  17. '/home': (
  18. '/index',
  19. '/index2',
  20. '/index3'
  21. ),
  22. '/forms': (
  23. '/form',
  24. '/form_advanced',
  25. '/form_validation',
  26. '/form_wizards',
  27. '/form_upload',
  28. '/form_buttons'
  29. ),
  30. '/ui': (
  31. '/general_elements',
  32. '/media_gallery',
  33. '/typography',
  34. '/icons',
  35. '/glyphicons',
  36. '/widgets',
  37. '/invoice',
  38. '/inbox',
  39. '/calendar'
  40. ),
  41. '/tables': (
  42. '/tables',
  43. '/tables_dynamic'
  44. ),
  45. '/data': (
  46. '/chartjs',
  47. '/chartjs2',
  48. '/morisjs',
  49. '/echarts',
  50. '/other_charts'
  51. ),
  52. '/additional': (
  53. '/ecommerce',
  54. '/projects',
  55. '/project_detail',
  56. '/contacts',
  57. '/profile',
  58. '/pricing'
  59. )
  60. }
  61. free_access = {'/', '/login', '/page_403', '/page_404', '/page_500'}
  62. def check_pages(*pages):
  63. def decorator(function):
  64. def wrapper(user_client):
  65. function(user_client)
  66. for page in pages:
  67. r = user_client.get(page, follow_redirects=True)
  68. assert r.status_code == 200
  69. return wrapper
  70. return decorator
  71. def check_blueprints(*blueprints):
  72. def decorator(function):
  73. def wrapper(user_client):
  74. function(user_client)
  75. for blueprint in blueprints:
  76. for page in urls[blueprint]:
  77. r = user_client.get(blueprint + page, follow_redirects=True)
  78. assert r.status_code == 200
  79. return wrapper
  80. return decorator
  81. ## Base test
  82. # test the login system: login, user creation, logout
  83. # test that all pages respond with HTTP 403 if not logged in, 200 otherwise
  84. def test_authentication(base_client):
  85. for blueprint, pages in urls.items():
  86. for page in pages:
  87. page_url = blueprint + page
  88. expected_code = 200 if page_url in free_access else 403
  89. r = base_client.get(page_url, follow_redirects=True)
  90. assert r.status_code == expected_code
  91. def test_urls(user_client):
  92. for blueprint, pages in urls.items():
  93. for page in pages:
  94. page_url = blueprint + page
  95. r = user_client.get(page_url, follow_redirects=True)
  96. assert r.status_code == 200
  97. # logout and test that we cannot access anything anymore
  98. r = user_client.get('/logout', follow_redirects=True)
  99. test_authentication(user_client)