test_pagure_flask_ui_app_index.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2017 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import datetime
  9. import unittest
  10. import shutil
  11. import sys
  12. import os
  13. import six
  14. import json
  15. import pygit2
  16. from mock import patch, MagicMock
  17. sys.path.insert(0, os.path.join(os.path.dirname(
  18. os.path.abspath(__file__)), '..'))
  19. import pagure.lib.query
  20. import tests
  21. class PagureFlaskAppIndextests(tests.Modeltests):
  22. """ Tests for the index page of flask app controller of pagure """
  23. def test_index_logged_out(self):
  24. """ Test the index endpoint when logged out. """
  25. output = self.app.get('/')
  26. self.assertEqual(output.status_code, 200)
  27. output_text = output.get_data(as_text=True)
  28. self.assertIn('<title>Home - Pagure</title>', output_text)
  29. self.assertIn(
  30. '<h3 class="m-0 font-weight-bold">All Projects '
  31. '<span class="badge badge-secondary">0</span></h3>',
  32. output_text)
  33. tests.create_projects(self.session)
  34. output = self.app.get('/?page=abc')
  35. self.assertEqual(output.status_code, 200)
  36. self.assertIn(
  37. '<h3 class="m-0 font-weight-bold">All Projects '
  38. '<span class="badge badge-secondary">3</span></h3>',
  39. output.get_data(as_text=True))
  40. def test_index_logged_in(self):
  41. """
  42. Test the index endpoint when logged in.
  43. It should redirect to the userdash.
  44. """
  45. tests.create_projects(self.session)
  46. # Add a 3rd project with a long description
  47. item = pagure.lib.model.Project(
  48. user_id=2, # foo
  49. name='test3',
  50. description='test project #3 with a very long description',
  51. hook_token='aaabbbeeefff',
  52. )
  53. self.session.add(item)
  54. self.session.commit()
  55. user = tests.FakeUser(username='foo')
  56. with tests.user_set(self.app.application, user):
  57. output = self.app.get('/', follow_redirects=True)
  58. self.assertEqual(output.status_code, 200)
  59. output_text = output.get_data(as_text=True)
  60. self.assertIn(
  61. '<span class="btn btn-outline-secondary disabled '
  62. 'opacity-100 border-0 ml-auto font-weight-bold">'
  63. '1 Projects</span>\n',
  64. output_text)
  65. self.assertNotIn(
  66. '<h3 class="m-0 font-weight-bold">All Projects '
  67. '<span class="badge badge-secondary">3</span></h3>',
  68. output_text)
  69. if __name__ == '__main__':
  70. unittest.main(verbosity=2)