test_pagure_flask_ui_app_index.py 2.6 KB

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