# HG changeset patch # User Thomas De Schampheleire # Date 2016-05-06 21:21:50 # Node ID 313930ae35adb377524316074e54828abb5cb17f # Parent ab36d9a31a2d8f891faca35b4a92ce0d9e694437 pytest migration: other: convert to TestControllerPytest diff --git a/kallithea/tests/other/manual_test_vcs_operations.py b/kallithea/tests/other/manual_test_vcs_operations.py --- a/kallithea/tests/other/manual_test_vcs_operations.py +++ b/kallithea/tests/other/manual_test_vcs_operations.py @@ -166,14 +166,14 @@ def _check_proper_git_push(stdout, stder assert 'master -> master' in stderr -class TestVCSOperations(BaseTestCase): +class TestVCSOperations(TestControllerPytest): @classmethod def setup_class(cls): #DISABLE ANONYMOUS ACCESS set_anonymous_access(False) - def setUp(self): + def setup_method(self, method): r = Repository.get_by_repo_name(GIT_REPO) Repository.unlock(r) r.enable_locking = False 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 @@ -67,19 +67,20 @@ TEST_URLS += [ ] -class TestLibs(BaseTestCase): +class TestLibs(TestControllerPytest): - @parameterized.expand(TEST_URLS) + @parametrize('test_url,expected,expected_creds', TEST_URLS) def test_uri_filter(self, test_url, expected, expected_creds): from kallithea.lib.utils2 import uri_filter self.assertEqual(uri_filter(test_url), expected) - @parameterized.expand(TEST_URLS) + @parametrize('test_url,expected,expected_creds', TEST_URLS) def test_credentials_filter(self, test_url, expected, expected_creds): from kallithea.lib.utils2 import credentials_filter self.assertEqual(credentials_filter(test_url), expected_creds) - @parameterized.expand([('t', True), + @parametrize('str_bool,expected', [ + ('t', True), ('true', True), ('y', True), ('yes', True), @@ -116,7 +117,7 @@ class TestLibs(BaseTestCase): 'marian.user', 'marco-polo', 'marco_polo', 'world']) self.assertEqual(expected, set(extract_mentioned_usernames(sample))) - @parameterized.expand([ + @parametrize('age_args,expected', [ (dict(), u'just now'), (dict(seconds= -1), u'1 second ago'), (dict(seconds= -60 * 2), u'2 minutes ago'), @@ -139,7 +140,7 @@ class TestLibs(BaseTestCase): delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) self.assertEqual(age(n + delt(**age_args), now=n), expected) - @parameterized.expand([ + @parametrize('age_args,expected', [ (dict(), u'just now'), (dict(seconds= -1), u'1 second ago'), (dict(seconds= -60 * 2), u'2 minutes ago'), @@ -163,7 +164,7 @@ class TestLibs(BaseTestCase): delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) self.assertEqual(age(n + delt(**age_args), show_short_version=True, now=n), expected) - @parameterized.expand([ + @parametrize('age_args,expected', [ (dict(), u'just now'), (dict(seconds=1), u'in 1 second'), (dict(seconds=60 * 2), u'in 2 minutes'), @@ -248,7 +249,7 @@ class TestLibs(BaseTestCase): grav = gravatar_url(email_address=em, size=24) assert grav == 'https://example.com/%s/%s' % (_md5(em), 24) - @parameterized.expand([ + @parametrize('tmpl,repo_name,overrides,prefix,expected', [ (Repository.DEFAULT_CLONE_URI, 'group/repo1', {}, '', 'http://vps1:8000/group/repo1'), (Repository.DEFAULT_CLONE_URI, 'group/repo1', {'user': 'username'}, '', 'http://username@vps1:8000/group/repo1'), (Repository.DEFAULT_CLONE_URI, 'group/repo1', {}, '/prefix', 'http://vps1:8000/prefix/group/repo1'), @@ -285,7 +286,7 @@ class TestLibs(BaseTestCase): return tmpl % (url_ or '/some-url', _url) return URL_PAT.sub(url_func, text) - @parameterized.expand([ + @parametrize('sample,expected', [ ("", ""), ("git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1441655 13f79535-47bb-0310-9956-ffa450edef68", @@ -323,7 +324,7 @@ class TestLibs(BaseTestCase): from kallithea.lib.helpers import urlify_changesets self.assertEqual(urlify_changesets(sample, 'repo_name'), expected) - @parameterized.expand([ + @parametrize('sample,expected,url_', [ ("", "", ""), @@ -350,7 +351,7 @@ class TestLibs(BaseTestCase): tmpl="""%s""", url_=url_) self.assertEqual(urlify_text(sample), expected) - @parameterized.expand([ + @parametrize('test,expected', [ ("", None), ("/_2", '2'), ("_2", '2'), diff --git a/kallithea/tests/other/test_mail.py b/kallithea/tests/other/test_mail.py --- a/kallithea/tests/other/test_mail.py +++ b/kallithea/tests/other/test_mail.py @@ -21,7 +21,7 @@ class smtplib_mock(object): pass @mock.patch('kallithea.lib.rcmail.smtp_mailer.smtplib', smtplib_mock) -class TestMail(BaseTestCase): +class TestMail(TestControllerPytest): def test_send_mail_trivial(self): mailserver = 'smtp.mailserver.org' diff --git a/kallithea/tests/other/test_validators.py b/kallithea/tests/other/test_validators.py --- a/kallithea/tests/other/test_validators.py +++ b/kallithea/tests/other/test_validators.py @@ -14,12 +14,9 @@ from kallithea.tests.fixture import Fixt fixture = Fixture() -class TestRepoGroups(BaseTestCase): +class TestRepoGroups(TestControllerPytest): - def setUp(self): - pass - - def tearDown(self): + def teardown_method(self, method): Session.remove() def test_Message_extractor(self): @@ -164,7 +161,7 @@ class TestRepoGroups(BaseTestCase): # this uses ValidRepoName validator assert True - @parameterized.expand([ + @parametrize('name,expected', [ ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'), ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'), ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'),