|
Pierre-Yves Chibon |
893d4f |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
"""
|
|
Pierre-Yves Chibon |
893d4f |
(c) 2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
Authors:
|
|
Pierre-Yves Chibon |
893d4f |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
"""
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
from __future__ import unicode_literals
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
893d4f |
import pkg_resources
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
import unittest
|
|
Pierre-Yves Chibon |
893d4f |
import sys
|
|
Pierre-Yves Chibon |
893d4f |
import os
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
893d4f |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
from pagure.utils import ssh_urlpattern
|
|
Pierre-Yves Chibon |
893d4f |
import tests
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
class PagureUtilSSHPatterntests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
893d4f |
""" Tests for the ssh_urlpattern in pagure.util """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_ssh_pattern_valid(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the ssh_urlpattern with valid patterns. """
|
|
Pierre-Yves Chibon |
893d4f |
patterns = [
|
|
Pierre-Yves Chibon |
893d4f |
'ssh://user@host.com/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'git+ssh://user@host.com/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'ssh://host.com/repo.git'
|
|
Pierre-Yves Chibon |
893d4f |
'git+ssh://host.com/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'ssh://127.0.0.1/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'git+ssh://127.0.0.1/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
]
|
|
Pierre-Yves Chibon |
893d4f |
for pattern in patterns:
|
|
Pierre-Yves Chibon |
893d4f |
print(pattern)
|
|
Pierre-Yves Chibon |
893d4f |
self.assertTrue(ssh_urlpattern.match(pattern))
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_ssh_pattern_invalid(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the ssh_urlpattern with invalid patterns. """
|
|
Pierre-Yves Chibon |
893d4f |
patterns = [
|
|
Pierre-Yves Chibon |
893d4f |
'http://user@host.com/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'git+http://user@host.com/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'https://user@host.com/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'git+https://user@host.com/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'ssh://localhost/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'git+ssh://localhost/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'ssh://0.0.0.0/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
'git+ssh://0.0.0.0/repo.git',
|
|
Pierre-Yves Chibon |
893d4f |
]
|
|
Pierre-Yves Chibon |
893d4f |
for pattern in patterns:
|
|
Pierre-Yves Chibon |
893d4f |
print(pattern)
|
|
Pierre-Yves Chibon |
893d4f |
self.assertFalse(ssh_urlpattern.match(pattern))
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
893d4f |
unittest.main(verbosity=2)
|