Changeset - d8b23000aad6
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 7 years ago 2018-09-17 22:33:57
thomas.de_schampheleire@nokia.com
tests: add basic tests for canonical_url
1 file changed with 48 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -551,3 +551,51 @@ class TestLibs(TestController):
 
        from kallithea.lib.utils import _extract_id_from_repo_name
 
        _test = _extract_id_from_repo_name(test)
 
        assert _test == expected, 'url:%s, got:`%s` expected: `%s`' % (test, _test, expected)
 

	
 

	
 
    @parametrize('canonical,test,expected', [
 
        ('http://www.example.org/', '/abc/xyz', 'http://www.example.org/abc/xyz'),
 
        ('http://www.example.org', '/abc/xyz', 'http://www.example.org/abc/xyz'),
 
        ('http://www.example.org', '/abc/xyz/', 'http://www.example.org/abc/xyz/'),
 
        ('http://www.example.org', 'abc/xyz/', 'http://www.example.org/abc/xyz/'),
 
        ('http://www.example.org', 'about', 'http://www.example.org/about-page'),
 
    ])
 
    def test_canonical_url(self, canonical, test, expected):
 
        from kallithea.lib.helpers import canonical_url
 
        from tg import request
 

	
 
        # setup url(), used by canonical_url
 
        import routes
 
        m = routes.Mapper()
 
        m.connect('about', '/about-page')
 
        url = routes.URLGenerator(m, {'HTTP_HOST': 'http_host.example.org'})
 

	
 
        config_mock = {
 
            'canonical_url': canonical,
 
        }
 

	
 
        with test_context(self.app):
 
            request.environ['routes.url'] = url
 
            with mock.patch('kallithea.CONFIG', config_mock):
 
                assert canonical_url(test) == expected
 

	
 
    @parametrize('canonical,expected', [
 
        ('http://www.example.org', 'www.example.org'),
 
    ])
 
    def test_canonical_hostname(self, canonical, expected):
 
        from kallithea.lib.helpers import canonical_hostname
 
        from tg import request
 

	
 
        # setup url(), used by canonical_hostname
 
        import routes
 
        m = routes.Mapper()
 
        url = routes.URLGenerator(m, {'HTTP_HOST': 'http_host.example.org'})
 

	
 
        config_mock = {
 
            'canonical_url': canonical,
 
        }
 

	
 
        with test_context(self.app):
 
            request.environ['routes.url'] = url
 
            with mock.patch('kallithea.CONFIG', config_mock):
 
                assert canonical_hostname() == expected
0 comments (0 inline, 0 general)