test_pagure_flask_ui_app_index.py 2.6 KB

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