# HG changeset patch # User Thomas De Schampheleire # Date 1461584121 -7200 # Node ID 72e8508d9758294bb71f0dbd3142b2c5fc384381 # Parent 1173317b4f1adf4176fed85c21660de28dc8602d pytest migration: convert functional tests with setup/teardown and parametrization diff -r 1173317b4f1a -r 72e8508d9758 kallithea/tests/functional/test_admin_users.py --- a/kallithea/tests/functional/test_admin_users.py Fri Mar 11 21:43:57 2016 +0100 +++ b/kallithea/tests/functional/test_admin_users.py Mon Apr 25 13:35:21 2016 +0200 @@ -26,7 +26,7 @@ fixture = Fixture() -class TestAdminUsersController(TestController): +class TestAdminUsersController(TestControllerPytest): test_user_1 = 'testme' @classmethod @@ -108,7 +108,7 @@ self.log_user() response = self.app.get(url('new_user')) - @parameterized.expand( + @parametrize('name,attrs', [('firstname', {'firstname': 'new_username'}), ('lastname', {'lastname': 'new_username'}), ('admin', {'admin': True}), @@ -387,7 +387,7 @@ response = self.app.get(url('edit_user_ips', id=user.user_id)) response.mustcontain('All IP addresses are allowed') - @parameterized.expand([ + @parametrize('test_name,ip,ip_range,failure', [ ('127/24', '127.0.0.1/24', '127.0.0.0 - 127.0.0.255', False), ('10/32', '10.0.0.10/32', '10.0.0.10 - 10.0.0.10', False), ('0/16', '0.0.0.0/16', '0.0.0.0 - 0.0.255.255', False), @@ -449,7 +449,7 @@ response.mustcontain(user.api_key) response.mustcontain('Expires: Never') - @parameterized.expand([ + @parametrize('desc,lifetime', [ ('forever', -1), ('5mins', 60*5), ('30days', 60*60*24*30), diff -r 1173317b4f1a -r 72e8508d9758 kallithea/tests/functional/test_login.py --- a/kallithea/tests/functional/test_login.py Fri Mar 11 21:43:57 2016 +0100 +++ b/kallithea/tests/functional/test_login.py Mon Apr 25 13:35:21 2016 +0200 @@ -19,8 +19,8 @@ fixture = Fixture() -class TestLoginController(TestController): - def setUp(self): +class TestLoginController(TestControllerPytest): + def setup_method(self, method): remove_all_notifications() self.assertEqual(Notification.query().all(), []) @@ -111,7 +111,7 @@ response = self.app.get(url(controller='login', action='index')) self.assertNotIn('authuser', response.session) - @parameterized.expand([ + @parametrize('url_came_from', [ ('data:text/html,',), ('mailto:test@example.com',), ('file:///etc/passwd',), @@ -146,7 +146,7 @@ # verify that get arguments are correctly passed along login redirection - @parameterized.expand([ + @parametrize('args,args_encoded', [ ({'foo':'one', 'bar':'two'}, (('foo', 'one'), ('bar', 'two'))), ({'blue': u'blå'.encode('utf-8'), 'green':u'grøn'}, (('blue', u'blå'.encode('utf-8')), ('green', u'grøn'.encode('utf-8')))), @@ -162,7 +162,7 @@ for encoded in args_encoded: self.assertIn(encoded, came_from_qs) - @parameterized.expand([ + @parametrize('args,args_encoded', [ ({'foo':'one', 'bar':'two'}, ('foo=one', 'bar=two')), ({'blue': u'blå', 'green':u'grøn'}, ('blue=bl%C3%A5', 'green=gr%C3%B8n')), @@ -174,7 +174,7 @@ for encoded in args_encoded: self.assertIn(encoded, came_from) - @parameterized.expand([ + @parametrize('args,args_encoded', [ ({'foo':'one', 'bar':'two'}, ('foo=one', 'bar=two')), ({'blue': u'blå', 'green':u'grøn'}, ('blue=bl%C3%A5', 'green=gr%C3%B8n')), @@ -188,7 +188,7 @@ for encoded in args_encoded: self.assertIn(encoded, response.location) - @parameterized.expand([ + @parametrize('args,args_encoded', [ ({'foo':'one', 'bar':'two'}, ('foo=one', 'bar=two')), ({'blue': u'blå', 'green':u'grøn'}, ('blue=bl%C3%A5', 'green=gr%C3%B8n')), @@ -435,7 +435,7 @@ config = {'api_access_controllers_whitelist': values or []} return config - @parameterized.expand([ + @parametrize('test_name,api_key', [ ('none', None), ('empty_string', ''), ('fake_number', '123456'), @@ -456,7 +456,7 @@ repo_name=HG_REPO, revision='tip', api_key=api_key), status=403) - @parameterized.expand([ + @parametrize('test_name,api_key,code', [ ('none', None, 302), ('empty_string', '', 302), ('fake_number', '123456', 302), diff -r 1173317b4f1a -r 72e8508d9758 kallithea/tests/functional/test_my_account.py --- a/kallithea/tests/functional/test_my_account.py Fri Mar 11 21:43:57 2016 +0100 +++ b/kallithea/tests/functional/test_my_account.py Mon Apr 25 13:35:21 2016 +0200 @@ -10,7 +10,7 @@ fixture = Fixture() -class TestMyAccountController(TestController): +class TestMyAccountController(TestControllerPytest): test_user_1 = 'testme' @classmethod @@ -86,7 +86,7 @@ response.mustcontain('No additional emails specified') - @parameterized.expand( + @parametrize('name,attrs', [('firstname', {'firstname': 'new_username'}), ('lastname', {'lastname': 'new_username'}), ('admin', {'admin': True}), @@ -192,7 +192,7 @@ response.mustcontain(user.api_key) response.mustcontain('Expires: Never') - @parameterized.expand([ + @parametrize('desc,lifetime', [ ('forever', -1), ('5mins', 60*5), ('30days', 60*60*24*30),