You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/06/04 22:52:10 UTC

[11/16] git commit: [#1687] ticket:574 Remove/fix tests in Allura core

[#1687] ticket:574 Remove/fix tests in Allura core


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

Branch: refs/heads/master
Commit: 5b0522b1f328ad4ac0f5b0e51a96410fe6c714c1
Parents: 7b65cf2
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 2 17:14:37 2014 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Tue Jun 3 15:27:22 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/functional/test_auth.py     | 12 ---
 Allura/allura/tests/functional/test_rest.py     | 31 ++-----
 .../tests/functional/test_rest_api_tickets.py   | 87 --------------------
 Allura/allura/tests/model/test_auth.py          | 17 ----
 4 files changed, 6 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/5b0522b1/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 0d4f8f7..f35f5f1 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -196,18 +196,6 @@ class TestAuth(TestController):
         r = self.app.get('/auth/subscriptions/')
         assert '<option selected value="both">Combined</option>' in r
 
-    def test_api_key(self):
-        r = self.app.get('/auth/preferences/')
-        assert 'No API token generated' in r
-        r = self.app.post('/auth/preferences/gen_api_token', status=302)
-        r = self.app.get('/auth/preferences/')
-        assert 'No API token generated' not in r
-        assert 'API Key:' in r
-        assert 'Secret Key:' in r
-        r = self.app.post('/auth/preferences/del_api_token', status=302)
-        r = self.app.get('/auth/preferences/')
-        assert 'No API token generated' in r
-
     def test_create_account(self):
         r = self.app.get('/auth/create_account')
         assert 'Create an Account' in r

http://git-wip-us.apache.org/repos/asf/allura/blob/5b0522b1/Allura/allura/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py
index 83889c1..51ae930 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -17,8 +17,6 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-from datetime import datetime, timedelta
-
 from pylons import app_globals as g
 import mock
 from nose.tools import assert_equal, assert_in, assert_not_in
@@ -30,38 +28,20 @@ from allura.lib import helpers as h
 from allura.lib.exceptions import Invalid
 from allura import model as M
 
-from forgetracker.tracker_main import ForgeTrackerApp
-
 
 class TestRestHome(TestRestApiBase):
 
-    def test_bad_signature(self):
-        r = self.api_post('/rest/p/test/wiki/', api_signature='foo')
-        assert r.status_int == 403
-
-    def test_bad_token(self):
-        r = self.api_post('/rest/p/test/wiki/', api_key='foo')
-        assert r.status_int == 403
-
-    def test_bad_timestamp(self):
-        r = self.api_post('/rest/p/test/wiki/',
-                          api_timestamp=(datetime.utcnow() + timedelta(days=1)).isoformat())
-        assert r.status_int == 403
-
-    @mock.patch('allura.controllers.rest.M.OAuthAccessToken')
-    @mock.patch('allura.controllers.rest.request')
-    def test_bearer_token_non_ssl(self, request, OAuthAccessToken):
-        request.params = {'access_token': 'foo'}
-        request.scheme = 'http'
-        r = self.api_post('/rest/p/test/wiki', access_token='foo')
-        assert_equal(r.status_int, 403)
-        assert_equal(OAuthAccessToken.query.get.call_count, 0)
+    def _patch_token(self, OAuthAccessToken):
+        at = OAuthAccessToken.return_value
+        at.__ming__ = mock.MagicMock()
+        at.api_key = 'foo'
 
     @mock.patch('allura.controllers.rest.M.OAuthAccessToken')
     @mock.patch('allura.controllers.rest.request')
     def test_bearer_token_non_bearer(self, request, OAuthAccessToken):
         request.params = {'access_token': 'foo'}
         request.scheme = 'https'
+        self._patch_token(OAuthAccessToken)
         access_token = OAuthAccessToken.query.get.return_value
         access_token.is_bearer = False
         r = self.api_post('/rest/p/test/wiki', access_token='foo')
@@ -73,6 +53,7 @@ class TestRestHome(TestRestApiBase):
     def test_bearer_token_invalid(self, request, OAuthAccessToken):
         request.params = {'access_token': 'foo'}
         request.scheme = 'https'
+        self._patch_token(OAuthAccessToken)
         OAuthAccessToken.query.get.return_value = None
         r = self.api_post('/rest/p/test/wiki', access_token='foo')
         assert_equal(r.status_int, 403)

http://git-wip-us.apache.org/repos/asf/allura/blob/5b0522b1/Allura/allura/tests/functional/test_rest_api_tickets.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest_api_tickets.py b/Allura/allura/tests/functional/test_rest_api_tickets.py
deleted file mode 100644
index 8185d5d..0000000
--- a/Allura/allura/tests/functional/test_rest_api_tickets.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-from datetime import datetime, timedelta
-
-from ming.orm import session
-
-from allura import model as M
-from allura.tests import decorators as td
-from alluratest.controller import TestRestApiBase
-
-
-class TestApiTicket(TestRestApiBase):
-
-    def set_api_ticket(self, expire=None):
-        if not expire:
-            expire = timedelta(days=1)
-        test_admin = M.User.query.get(username='test-admin')
-        api_ticket = M.ApiTicket(
-            user_id=test_admin._id, capabilities={
-                'import': ['Projects', 'test']},
-            expires=datetime.utcnow() + expire)
-        session(api_ticket).flush()
-        self.set_api_token(api_ticket)
-
-    def test_bad_signature(self):
-        self.set_api_ticket()
-        r = self.api_post('/rest/p/test/wiki/', api_signature='foo')
-        assert r.status_int == 403
-
-    def test_bad_token(self):
-        self.set_api_ticket()
-        r = self.api_post('/rest/p/test/wiki/', api_key='foo')
-        assert r.status_int == 403
-
-    def test_bad_timestamp(self):
-        self.set_api_ticket()
-        r = self.api_post('/rest/p/test/wiki/',
-                          api_timestamp=(datetime.utcnow() + timedelta(days=1)).isoformat())
-        assert r.status_int == 403
-
-    def test_bad_path(self):
-        self.set_api_ticket()
-        r = self.api_post('/rest/1/test/wiki/')
-        assert r.status_int == 404
-        r = self.api_post('/rest/p/1223/wiki/')
-        assert r.status_int == 404
-        r = self.api_post('/rest/p/test/12wiki/')
-        assert r.status_int == 404
-
-    def test_no_api(self):
-        self.set_api_ticket()
-        r = self.api_post('/rest/p/test/admin/')
-        assert r.status_int == 404
-
-    @td.with_wiki
-    def test_project_ping(self):
-        self.set_api_ticket()
-        r = self.api_get('/rest/p/test/wiki/Home/')
-        assert r.status_int == 200
-        assert r.json['title'] == 'Home', r.json
-
-    def test_project_ping_expired_ticket(self):
-        self.set_api_ticket(timedelta(seconds=-1))
-        r = self.api_post('/rest/p/test/wiki/')
-        assert r.status_int == 403
-
-    @td.with_tool('test/sub1', 'Wiki', 'wiki')
-    def test_subproject_ping(self):
-        self.set_api_ticket()
-        r = self.api_get('/rest/p/test/sub1/wiki/Home/')
-        assert r.status_int == 200
-        assert r.json['title'] == 'Home', r.json

http://git-wip-us.apache.org/repos/asf/allura/blob/5b0522b1/Allura/allura/tests/model/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index 1c76611..35f056e 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -173,23 +173,6 @@ def test_default_project_roles():
 
 
 @with_setup(setUp)
-def test_dup_api_token():
-    from ming.orm import session
-    u = M.User.register(dict(username='nosetest-user'))
-    ThreadLocalORMSession.flush_all()
-    tok = M.ApiToken(user_id=u._id)
-    session(tok).flush()
-    tok2 = M.ApiToken(user_id=u._id)
-    try:
-        session(tok2).flush()
-        assert False, "Entry with duplicate unique key was inserted"
-    except DuplicateKeyError:
-        pass
-    assert len(M.ApiToken.query.find().all()
-               ) == 1, "Duplicate entries with unique key found"
-
-
-@with_setup(setUp)
 def test_email_address_claimed_by_user():
     addr = M.EmailAddress(_id='test_admin@domain.net',
                           claimed_by_user_id=c.user._id)