diff --git a/runtests.sh b/runtests.sh index eb8063b..3ceec59 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,3 +1,5 @@ #!/bin/bash -PYTHONPATH=pagure ./nosetests --with-coverage --cover-erase --cover-package=pagure $* +PAGURE_CONFIG=`pwd`/tests/test_config \ +PYTHONPATH=pagure \ +./nosetests --with-coverage --cover-erase --cover-package=pagure $* diff --git a/tests/test_pagure_flask_docs.py b/tests/test_pagure_flask_docs.py index bb2d419..de232f8 100644 --- a/tests/test_pagure_flask_docs.py +++ b/tests/test_pagure_flask_docs.py @@ -237,7 +237,7 @@ class PagureFlaskDocstests(tests.Modeltests): self.assertEqual(output.status_code, 500) output = self.app.get('/test/folder1') - self.assertEqual(output.status_code, 500) + self.assertEqual(output.status_code, 200) if __name__ == '__main__': diff --git a/tests/test_pagure_flask_ui_plugins_pagure_ci.py b/tests/test_pagure_flask_ui_plugins_pagure_ci.py index b7589fa..e063420 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_ci.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_ci.py @@ -12,6 +12,11 @@ import os import pygit2 from mock import patch +# Insert the PAGURE_CONFIG env variable before we do the imports +HERE = os.path.join(os.path.dirname(os.path.abspath(__file__))) +CONFIG = os.path.join(HERE, 'test_config') +os.environ['PAGURE_CONFIG'] = CONFIG + sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) @@ -103,9 +108,6 @@ class PagureFlaskPluginPagureCItests(tests.Modeltests): data['csrf_token'] = csrf_token - if not pagure.APP.config.get('PAGURE_CI_SERVICES'): - return - # Activate hook output = self.app.post( '/test/settings/Pagure CI', data=data, follow_redirects=True) @@ -132,6 +134,9 @@ class PagureFlaskPluginPagureCItests(tests.Modeltests): self.assertTrue( '' in output.data) + self.assertIn( + '
\nhttps://pagure.org/api/0/ci/jenkins/test/', + output.data) # De-activate the hook data = { @@ -180,6 +185,68 @@ class PagureFlaskPluginPagureCItests(tests.Modeltests): '', output.data) + def test_plugin_pagure_ci_namespaced(self): + """ Test the pagure ci plugin on/off endpoint. """ + + tests.create_projects(self.session) + tests.create_projects_git(self.path) + + user = tests.FakeUser(username='pingou') + with tests.user_set(pagure.APP, user): + output = self.app.get('/somenamespace/test3/settings/Pagure CI') + self.assertEqual(output.status_code, 200) + self.assertIn( + '\n' + 'namespaced test project', output.data) + self.assertTrue('Pagure CI settings
' in output.data) + self.assertIn( + '' , output.data) + self.assertIn( + '', + output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + # Activate hook + data = { + 'active': 'y', + 'ci_url': 'https://jenkins.fedoraproject.org', + 'ci_type': 'jenkins', + 'csrf_token': csrf_token, + } + + # Activate hook + output = self.app.post( + '/somenamespace/test3/settings/Pagure CI', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + ' \n' + 'namespaced test project', output.data) + self.assertIn( + 'Settings - somenamespace/test3 - Pagure ', output.data) + self.assertIn('Settings for somenamespace/test3
', output.data) + self.assertIn( + '\n Hook Pagure CI activated', + output.data) + + output = self.app.get('/somenamespace/test3/settings/Pagure CI') + self.assertEqual(output.status_code, 200) + self.assertIn( + '\n' + 'namespaced test project', output.data) + self.assertTrue('Pagure CI settings
' in output.data) + self.assertIn( + '' , output.data) + self.assertTrue( + '' + in output.data) + self.assertIn( + ' \nhttps://pagure.org/api/0/ci/jenkins/somenamespace/test3/', + output.data) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(