[PATCH 1 of 2] tests: add basic tests for canonical_url
Thomas De Schampheleire
patrickdepinguin at gmail.com
Tue Sep 18 18:53:25 UTC 2018
# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1537216437 -7200
# Mon Sep 17 22:33:57 2018 +0200
# Node ID e97e2effbc17f9209e388afa1f3618401cc34432
# Parent d63018164a308f1005c250a284279fe6f15cf8a3
tests: add basic tests for canonical_url
diff --git a/kallithea/tests/other/test_libs.py b/kallithea/tests/other/test_libs.py
--- a/kallithea/tests/other/test_libs.py
+++ b/kallithea/tests/other/test_libs.py
@@ -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
More information about the kallithea-general
mailing list