incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [41/44] git commit: [#6656] ticket:437 OAuth tests
Date Wed, 13 Nov 2013 22:58:01 GMT
[#6656] ticket:437 OAuth tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/5f434893
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5f434893
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5f434893

Branch: refs/heads/cj/6815
Commit: 5f434893f43098a8720eb9b34c8b995da13bb72a
Parents: ac8fa2c
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Oct 25 17:12:28 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Nov 13 20:47:42 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_code.py    |  7 ++++
 .../forgeimporters/github/tests/test_tracker.py |  8 ++++
 .../forgeimporters/github/tests/test_wiki.py    |  7 ++++
 .../tests/github/functional/test_github.py      | 44 ++++++++++++++++++++
 .../forgeimporters/tests/github/test_tasks.py   |  3 +-
 5 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5f434893/ForgeImporters/forgeimporters/github/tests/test_code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_code.py b/ForgeImporters/forgeimporters/github/tests/test_code.py
index 4ad8dac..7c85058 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_code.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_code.py
@@ -23,6 +23,7 @@ from allura.tests import TestController
 from allura.tests.decorators import with_tool
 from allura import model as M
 from forgeimporters.github.code import GitHubRepoImporter
+from forgeimporters.github import GitHubOAuthMixin
 
 
 # important to be distinct from 'test' which ForgeGit uses, so that the tests can run in
parallel and not clobber each other
@@ -105,3 +106,9 @@ class TestGitHubImportController(TestController, TestCase):
                 status=302).follow()
         self.assertIn('Please wait and try again', r)
         self.assertEqual(import_tool.post.call_count, 0)
+
+    @with_git
+    @patch.object(GitHubOAuthMixin, 'oauth_begin')
+    def test_oauth(self, oauth_begin):
+        r = self.app.get('/p/{}/admin/ext/import/github-repo/'.format(test_project_with_repo))
+        oauth_begin.assert_called_once()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5f434893/ForgeImporters/forgeimporters/github/tests/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_tracker.py b/ForgeImporters/forgeimporters/github/tests/test_tracker.py
index 938a194..d63b4d6 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_tracker.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_tracker.py
@@ -23,6 +23,8 @@ from allura.tests import TestController
 from allura.tests.decorators import with_tool
 from allura import model as M
 
+from forgeimporters.github import GitHubOAuthMixin
+
 # important to be distinct from 'test' which ForgeTracker uses, so that the tests can run
in parallel and not clobber each other
 test_project_with_tracker = 'test2'
 with_tracker = with_tool(test_project_with_tracker, 'tickets', 'spooky-issues', 'tickets')
@@ -69,3 +71,9 @@ class TestGitHubTrackerImportController(TestController, TestCase):
         r = self.app.post(self.url + 'create', params, status=302).follow()
         self.assertIn('Please wait and try again', r)
         self.assertEqual(import_tool.post.call_count, 0)
+
+    @with_tracker
+    @patch.object(GitHubOAuthMixin, 'oauth_begin')
+    def test_oauth(self, oauth_begin):
+        r = self.app.get(self.url)
+        oauth_begin.assert_called_once()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5f434893/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index dec92a4..70ea74d 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -29,6 +29,7 @@ from allura.tests.decorators import with_tool, without_module
 from alluratest.controller import setup_basic_test
 from forgeimporters.github.wiki import GitHubWikiImporter
 from forgeimporters.github.utils import GitHubMarkdownConverter
+from forgeimporters.github import GitHubOAuthMixin
 
 
 # important to be distinct from 'test' which ForgeWiki uses, so that the tests can run in
parallel and not clobber each other
@@ -558,3 +559,9 @@ class TestGitHubWikiImportController(TestController, TestCase):
         r = self.app.post(self.url + 'create', params, status=302).follow()
         self.assertIn('Please wait and try again', r)
         self.assertEqual(import_tool.post.call_count, 0)
+
+    @with_wiki
+    @patch.object(GitHubOAuthMixin, 'oauth_begin')
+    def test_oauth(self, oauth_begin):
+        r = self.app.get(self.url)
+        oauth_begin.assert_called_once()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5f434893/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
index afc9bd0..a9c5052 100644
--- a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -15,8 +15,13 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+import tg
+from mock import patch, call, Mock
+from nose.tools import assert_equal
 from unittest import TestCase
+
 from allura.tests import TestController
+from allura import model as M
 
 class TestGitHubImportController(TestController, TestCase):
 
@@ -35,3 +40,42 @@ class TestGitHubImportController(TestController, TestCase):
 
         r = self.app.post('/p/import_project/github/process', extra_environ=dict(username='*anonymous'),
status=302)
         self.assertIn('/auth/', r.location)
+
+
+class TestGitHubOAuth(TestController):
+
+    def setUp(self):
+        super(TestGitHubOAuth, self).setUp()
+        tg.config['github_importer.client_id'] = 'client_id'
+        tg.config['github_importer.client_secret'] = 'secret'
+
+    @patch('forgeimporters.github.OAuth2Session')
+    @patch('forgeimporters.github.session')
+    def test_oauth_flow(self, session, oauth):
+        redirect = 'http://localhost/p/import_project/github/oauth_callback'
+        oauth_instance = Mock()
+        oauth_instance.authorization_url.return_value = (redirect, 'state')
+        oauth_instance.fetch_token.return_value = {'access_token': 'abc'}
+        oauth.return_value = oauth_instance
+
+        user = M.User.by_username('test-admin')
+        assert_equal(user.get_tool_data('GitHubProjectImport', 'token'), None)
+        r = self.app.get('/p/import_project/github/')
+        assert_equal(r.status_int, 302)
+        assert_equal(r.location, redirect)
+        session.__setitem__.assert_has_calls([
+            call('github.oauth.state', 'state'),
+            call('github.oauth.redirect', 'http://localhost/p/import_project/github/')
+        ])
+        session.save.assert_called_once()
+
+        r = self.app.get(redirect)
+        session.get.assert_has_calls([
+            call('github.oauth.state'),
+            call('github.oauth.redirect', '/')
+        ])
+        user = M.User.by_username('test-admin')
+        assert_equal(user.get_tool_data('GitHubProjectImport', 'token'), 'abc')
+
+        r = self.app.get('/p/import_project/github/')
+        assert_equal(r.status_int, 200)  # token in user data, so oauth isn't triggered

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5f434893/ForgeImporters/forgeimporters/tests/github/test_tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tasks.py b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
index 86b321e..cf58644 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tasks.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
@@ -25,8 +25,9 @@ from ...github import tasks
 @mock.patch.object(tasks, 'c')
 def test_import_project_info(c, session, ghpe):
     c.project = mock.Mock(name='project')
+    c.user = mock.Mock(name='user')
     tasks.import_project_info('my-project')
-    ghpe.assert_called_once_with('my-project')
+    ghpe.assert_called_once_with('my-project', user=c.user)
     ghpe.return_value.get_summary.assert_called_once_with()
     ghpe.return_value.get_homepage.assert_called_once_with()
     session.flush_all.assert_called_once_with()


Mime
View raw message