Blame tests/test_pagure_flask_util.py

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 67d1cc
from __future__ import unicode_literals, absolute_import
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 73d120
sys.path.insert(
Pierre-Yves Chibon 73d120
    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
Pierre-Yves Chibon 73d120
)
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 73d120
            "ssh://user@host.com/repo.git",
Pierre-Yves Chibon 73d120
            "git+ssh://user@host.com/repo.git",
Pierre-Yves Chibon 73d120
            "ssh://user@host.lcl:/path/to/repo.git",
Pierre-Yves Chibon 73d120
            "git@github.com:user/project.git",
Pierre-Yves Chibon 73d120
            "ssh://user@host.org/target",
Pierre-Yves Chibon 73d120
            "git+ssh://user@host.org/target",
Pierre-Yves Chibon 73d120
            "git+ssh://user@host.lcl:/path/to/repo.git",
Pierre-Yves Chibon 893d4f
        ]
Pierre-Yves Chibon 893d4f
        for pattern in patterns:
Pierre-Yves Chibon 893d4f
            print(pattern)
Pierre-Yves Chibon 55de1c
            self.assertIsNotNone(ssh_urlpattern.match(pattern))
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 73d120
            "http://user@host.com/repo.git",
Pierre-Yves Chibon 73d120
            "git+http://user@host.com/repo.git",
Pierre-Yves Chibon 73d120
            "https://user@host.com/repo.git",
Pierre-Yves Chibon 73d120
            "git+https://user@host.com/repo.git",
Pierre-Yves Chibon 73d120
            "ssh://localhost/repo.git",
Pierre-Yves Chibon 73d120
            "ssh://host.com/repo.git",
Pierre-Yves Chibon 73d120
            "git+ssh://localhost/repo.git",
Pierre-Yves Chibon 73d120
            "ssh://0.0.0.0/repo.git",
Pierre-Yves Chibon 73d120
            "git+ssh://0.0.0.0/repo.git",
Pierre-Yves Chibon 73d120
            "git+ssh://host.com/repo.git",
Pierre-Yves Chibon 73d120
            "ssh://127.0.0.1/repo.git",
Pierre-Yves Chibon 73d120
            "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 55de1c
            self.assertIsNone(ssh_urlpattern.match(pattern))
Pierre-Yves Chibon 893d4f
Pierre-Yves Chibon 893d4f
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon 893d4f
    unittest.main(verbosity=2)