1
0

test_pagure_flask_util.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2018 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import unittest
  9. import sys
  10. import os
  11. from mock import patch, MagicMock
  12. sys.path.insert(
  13. 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
  14. )
  15. from pagure.utils import ssh_urlpattern
  16. import tests
  17. class PagureUtilSSHPatterntests(tests.Modeltests):
  18. """ Tests for the ssh_urlpattern in pagure.util """
  19. def test_ssh_pattern_valid(self):
  20. """ Test the ssh_urlpattern with valid patterns. """
  21. patterns = [
  22. "ssh://user@host.com/repo.git",
  23. "git+ssh://user@host.com/repo.git",
  24. "ssh://user@host.lcl:/path/to/repo.git",
  25. "git@github.com:user/project.git",
  26. "ssh://user@host.org/target",
  27. "git+ssh://user@host.org/target",
  28. "git+ssh://user@host.lcl:/path/to/repo.git",
  29. ]
  30. for pattern in patterns:
  31. print(pattern)
  32. self.assertIsNotNone(ssh_urlpattern.match(pattern))
  33. def test_ssh_pattern_invalid(self):
  34. """ Test the ssh_urlpattern with invalid patterns. """
  35. patterns = [
  36. "http://user@host.com/repo.git",
  37. "git+http://user@host.com/repo.git",
  38. "https://user@host.com/repo.git",
  39. "git+https://user@host.com/repo.git",
  40. "ssh://localhost/repo.git",
  41. "ssh://host.com/repo.git",
  42. "git+ssh://localhost/repo.git",
  43. "ssh://0.0.0.0/repo.git",
  44. "git+ssh://0.0.0.0/repo.git",
  45. "git+ssh://host.com/repo.git",
  46. "ssh://127.0.0.1/repo.git",
  47. "git+ssh://127.0.0.1/repo.git",
  48. ]
  49. for pattern in patterns:
  50. print(pattern)
  51. self.assertIsNone(ssh_urlpattern.match(pattern))
  52. if __name__ == "__main__":
  53. unittest.main(verbosity=2)