1
0

test_pagure_flask_util.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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
  8. __requires__ = ['SQLAlchemy >= 0.8']
  9. import pkg_resources
  10. import unittest
  11. import sys
  12. import os
  13. from mock import patch, MagicMock
  14. sys.path.insert(0, os.path.join(os.path.dirname(
  15. os.path.abspath(__file__)), '..'))
  16. from pagure.utils import ssh_urlpattern
  17. import tests
  18. class PagureUtilSSHPatterntests(tests.Modeltests):
  19. """ Tests for the ssh_urlpattern in pagure.util """
  20. def test_ssh_pattern_valid(self):
  21. """ Test the ssh_urlpattern with valid patterns. """
  22. patterns = [
  23. 'ssh://user@host.com/repo.git',
  24. 'git+ssh://user@host.com/repo.git',
  25. 'ssh://user@host.lcl:/path/to/repo.git',
  26. 'git@github.com:user/project.git',
  27. 'ssh://user@host.org/target',
  28. 'git+ssh://user@host.org/target',
  29. 'git+ssh://user@host.lcl:/path/to/repo.git',
  30. ]
  31. for pattern in patterns:
  32. print(pattern)
  33. self.assertIsNotNone(ssh_urlpattern.match(pattern))
  34. def test_ssh_pattern_invalid(self):
  35. """ Test the ssh_urlpattern with invalid patterns. """
  36. patterns = [
  37. 'http://user@host.com/repo.git',
  38. 'git+http://user@host.com/repo.git',
  39. 'https://user@host.com/repo.git',
  40. 'git+https://user@host.com/repo.git',
  41. 'ssh://localhost/repo.git',
  42. 'ssh://host.com/repo.git',
  43. 'git+ssh://localhost/repo.git',
  44. 'ssh://0.0.0.0/repo.git',
  45. 'git+ssh://0.0.0.0/repo.git',
  46. 'git+ssh://host.com/repo.git',
  47. 'ssh://127.0.0.1/repo.git',
  48. 'git+ssh://127.0.0.1/repo.git',
  49. ]
  50. for pattern in patterns:
  51. print(pattern)
  52. self.assertIsNone(ssh_urlpattern.match(pattern))
  53. if __name__ == '__main__':
  54. unittest.main(verbosity=2)