| |
| |
| |
| """ |
| (c) 2016 - Copyright Red Hat Inc |
| |
| Authors: |
| Adam Williamson <awilliam@redhat.com> |
| |
| Tests for the Pagure streaming server. |
| |
| """ |
| |
| |
| |
| |
| import logging |
| import os |
| import sys |
| import unittest |
| |
| import mock |
| |
| sys.path.insert(0, os.path.join(os.path.dirname( |
| os.path.abspath(__file__)), '..')) |
| sys.path.insert(0, os.path.join(os.path.dirname( |
| os.path.abspath(__file__)), '../ev-server')) |
| |
| import pagure |
| from pagure.exceptions import PagureEvException |
| import tests |
| |
| import pagure_stream_server as pss |
| |
| logging.basicConfig(stream=sys.stderr) |
| |
| |
| class StreamingServerTests(tests.Modeltests): |
| """Tests for the streaming server.""" |
| |
| def setUp(self): |
| """Set up the environnment, run before every test.""" |
| super(StreamingServerTests, self).setUp() |
| pagure.SESSION = self.session |
| |
| |
| self.mailpatcher = mock.patch('pagure.lib.notify.send_email') |
| self.mailpatcher.start() |
| |
| |
| tests.create_projects(self.session) |
| self.repo = pagure.lib.get_project(self.session, 'test') |
| self.repo2 = pagure.lib.get_project(self.session, 'test2') |
| |
| |
| pagure.lib.update_project_settings( |
| session=self.session, |
| repo=self.repo2, |
| user='pingou', |
| settings={ |
| 'issue_tracker': False, |
| 'pull_requests': False, |
| } |
| ) |
| |
| |
| pagure.lib.new_issue( |
| session=self.session, |
| repo=self.repo, |
| title='Test issue', |
| content='We should work on this', |
| user='pingou', |
| ticketfolder=None |
| ) |
| |
| |
| pagure.lib.new_issue( |
| session=self.session, |
| repo=self.repo, |
| title='Private issue #2', |
| content='The world can see my porn folder', |
| user='pingou', |
| private=True, |
| ticketfolder=None |
| ) |
| |
| |
| pagure.lib.new_pull_request( |
| session=self.session, |
| repo_from=self.repo, |
| repo_to=self.repo, |
| branch_from='feature', |
| branch_to='master', |
| title='Test PR', |
| user='pingou', |
| requestfolder=None |
| ) |
| |
| def tearDown(self): |
| "Stop the patchers, as well as calling super.""" |
| super(StreamingServerTests, self).tearDown() |
| self.mailpatcher.stop() |
| |
| def test_parse_path(self): |
| """Tests for _parse_path.""" |
| |
| |
| result = pss._parse_path('/pagure/issue/1') |
| self.assertEqual(result, (None, None, 'pagure', 'issue', '1')) |
| |
| |
| result = pss._parse_path('/fedora-qa/fedfind/pull-request/2') |
| self.assertEqual(result, (None, 'fedora-qa', 'fedfind', 'pull-request', '2')) |
| |
| |
| result = pss._parse_path('/fork/adamwill/pagure/issue/3') |
| self.assertEqual(result, ('adamwill', None, 'pagure', 'issue', '3')) |
| |
| |
| result = pss._parse_path('/fork/pingou/fedora-qa/fedfind/issue/4') |
| self.assertEqual(result, ('pingou', 'fedora-qa', 'fedfind', 'issue', '4')) |
| |
| |
| result = pss._parse_path('/pull-request/issue/5') |
| self.assertEqual(result, (None, None, 'pull-request', 'issue', '5')) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"No known object", |
| pss._parse_path, '/pagure/unexpected/1' |
| ) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"No project or object ID", |
| pss._parse_path, '/pagure/issue' |
| ) |
| |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"No project or object ID", |
| pss._parse_path, '/issue/1' |
| ) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"no user found!", |
| pss._parse_path, '/fork/pagure/issue/1' |
| ) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"More path components", |
| pss._parse_path, '/fork/adamwill/fedora-qa/fedfind/unexpected/issue/1' |
| ) |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"More path components", |
| pss._parse_path, '/fedora-qa/fedfind/unexpected/issue/1' |
| ) |
| |
| def test_get_issue(self): |
| """Tests for _get_issue.""" |
| |
| result = pss._get_issue(self.repo, '1') |
| self.assertEqual(result.id, 1) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"Issue '3' not found", |
| pss._get_issue, self.repo, '3' |
| ) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"issue is private", |
| pss._get_issue, self.repo, '2' |
| ) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"No issue tracker found", |
| pss._get_issue, self.repo2, '1' |
| ) |
| |
| def test_get_pull_request(self): |
| """Tests for _get_pull_request.""" |
| |
| result = pss._get_pull_request(self.repo, '3') |
| self.assertEqual(result.id, 3) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"Pull-Request '2' not found", |
| pss._get_pull_request, self.repo, '2' |
| ) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"No pull-request tracker found", |
| pss._get_pull_request, self.repo2, '1' |
| ) |
| |
| def test_get_obj_from_path(self): |
| """Tests for get_obj_from_path.""" |
| |
| result = pss.get_obj_from_path('/test/issue/1') |
| self.assertEqual(result.id, 1) |
| |
| |
| result = pss.get_obj_from_path('/test/pull-request/3') |
| self.assertEqual(result.id, 3) |
| |
| |
| self.assertRaisesRegexp( |
| PagureEvException, |
| r"Project 'foo' not found", |
| pss.get_obj_from_path, '/foo/issue/1' |
| ) |
| |
| |
| |
| |
| if __name__ == '__main__': |
| SUITE = unittest.TestLoader().loadTestsFromTestCase(StreamingServerTests) |
| unittest.TextTestRunner(verbosity=2).run(SUITE) |