Exemplo n.º 1
0
 def test_googledrive_oauth_finish(self, mock_session,
                                   mock_auth_client_finish,
                                   mock_auth_client_userinfo):
     user_no_addon = AuthUserFactory()
     nid = self.project._primary_key
     state = '1234'
     mock_session.data = {
         'googledrive_auth_nid': nid,
         'googledrive_auth_state': state,
     }
     mock_auth_client_finish.return_value = {
         'access_token': '1111',
         'refresh_token': '2222',
         'expires_at': time.time() + 3600,
     }
     mock_auth_client_userinfo.return_value = {
         'sub': 'unique id',
         'name': 'test-user',
     }
     url = api_url_for('googledrive_oauth_finish',
                       user_no_addon.auth,
                       nid=self.project._primary_key,
                       code='1234',
                       state=state)
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 2
0
 def test_dropbox_oauth_finish(self, mock_get, mock_finish):
     mock_client = mock.MagicMock()
     mock_client.account_info.return_value = {'display_name': 'Mr. Drop Box'}
     mock_get.return_value = mock_client
     mock_finish.return_value = ('mytoken123', 'mydropboxid', 'done')
     url = api_url_for('dropbox_oauth_finish')
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 3
0
 def test_googledrive_oauth_finish_cancelled(self):
     user_no_addon = AuthUserFactory()
     url = api_url_for('googledrive_oauth_finish',
                       user_no_addon.auth,
                       nid=self.project._primary_key,
                       code='1234',
                       state='3322',
                       error='User declined!')
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 4
0
 def test_must_be_contributor_no_user(self):
     res = view_that_needs_contributor(
         pid=self.project._primary_key,
         user=None,
         api_key='123',
         api_node='abc',
     )
     assert_is_redirect(res)
     redirect_url = res.headers['Location']
     assert_equal(redirect_url, '/login/?next=/')
Exemplo n.º 5
0
 def test_must_be_contributor_no_user(self):
     res = view_that_needs_contributor(
         pid=self.project._primary_key,
         user=None,
         api_key='123',
         api_node='abc',
     )
     assert_is_redirect(res)
     redirect_url = res.headers['Location']
     assert_equal(redirect_url, '/login/?next=/')
Exemplo n.º 6
0
 def test_must_be_contributor_no_user_and_private_project(self):
     res = view_that_needs_contributor_or_public_but_not_anonymized(
         pid=self.private_project._primary_key,
         user=None,
     )
     assert_is_redirect(res)
     # redirects to login url
     redirect_url = res.headers['Location']
     login_url = cas.get_login_url(service_url='http://localhost/')
     assert_equal(redirect_url, login_url)
Exemplo n.º 7
0
 def test_must_be_contributor_no_user_and_private_project(self):
     res = view_that_needs_contributor_or_public_but_not_anonymized(
         pid=self.private_project._primary_key,
         user=None,
     )
     assert_is_redirect(res)
     # redirects to login url
     redirect_url = res.headers['Location']
     login_url = cas.get_login_url(service_url='http://localhost/')
     assert_equal(redirect_url, login_url)
Exemplo n.º 8
0
 def test_must_be_contributor_no_user(self):
     res = view_that_needs_contributor(
         pid=self.project._primary_key,
         user=None,
         api_key='123',
         api_node='abc',
     )
     assert_is_redirect(res)
     # redirects to login url
     redirect_url = res.headers['Location']
     login_url = cas.get_login_url(service_url='http://localhost/')
     assert_equal(redirect_url, login_url)
Exemplo n.º 9
0
 def test_googledrive_oauth_finish_cancelled(self):
     user_no_addon = AuthUserFactory()
     url = api_url_for(
         'googledrive_oauth_finish',
         user_no_addon.auth,
         nid=self.project._primary_key,
         code='1234',
         state='3322',
         error='User declined!'
     )
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 10
0
 def test_googledrive_oauth_finish_user_only(self, mock_session, mock_auth_client_finish, mock_auth_client_userinfo):
     user_no_addon = AuthUserFactory()
     state = "1234"
     mock_session.data = {"googledrive_auth_state": state}
     mock_auth_client_finish.return_value = {
         "access_token": "1111",
         "refresh_token": "2222",
         "expires_at": time.time() + 3600,
     }
     mock_auth_client_userinfo.return_value = {"sub": "unique id", "name": "test-user"}
     url = api_url_for("googledrive_oauth_finish", user_no_addon.auth, code="1234", state=state)
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 11
0
    def test_dropbox_oauth_finish_cancelled(self, mock_finish, mock_session):
        node = ProjectFactory(creator=self.user)
        mock_session.data = {'dropbox_auth_nid': node._id}
        mock_response = mock.Mock()
        mock_response.status = 404
        mock_finish.side_effect = DropboxOAuth2Flow.NotApprovedException
        settings = self.user.get_addon('dropbox')
        url = api_url_for('dropbox_oauth_finish')
        res = self.app.get(url)

        assert_is_redirect(res)
        assert_in(node._id, res.headers["location"])
        assert_false(settings)
Exemplo n.º 12
0
    def test_dropbox_oauth_finish_cancelled(self, mock_finish, mock_session):
        node = ProjectFactory(creator=self.user)
        mock_session.data = {'dropbox_auth_nid': node._id}
        mock_response = mock.Mock()
        mock_response.status = 404
        mock_finish.side_effect = DropboxOAuth2Flow.NotApprovedException
        settings = self.user.get_addon('dropbox')
        url = api_url_for('dropbox_oauth_finish')
        res = self.app.get(url)

        assert_is_redirect(res)
        assert_in(node._id, res.headers["location"])
        assert_false(settings)
Exemplo n.º 13
0
 def test_box_oauth_finish(self, mock_get, mock_finish, mock_oauth):
     mock_client = mock.MagicMock()
     mock_client.get_user_info.return_value = {'name': 'Mr. Box', 'id': '1234567890'}
     mock_get.return_value = mock_client
     mock_finish.return_value = {
         'token_type': 'something',
         'access_token': 'something',
         'refresh_token': 'something'
     }
     mock_oauth.return_value = ('mytoken123', 'myboxid', 'done')
     url = api_url_for('box_oauth_finish')
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 14
0
 def test_googledrive_oauth_finish_cancelled(self, mock_flash):
     user_no_addon = AuthUserFactory()
     url = api_url_for(
         "googledrive_oauth_finish",
         user_no_addon.auth,
         nid=self.project._primary_key,
         code="1234",
         state="3322",
         error="User declined!",
     )
     res = self.app.get(url)
     assert_is_redirect(res)
     mock_flash.assert_called_once()
Exemplo n.º 15
0
 def test_box_oauth_finish(self, mock_get, mock_finish, mock_oauth):
     mock_client = mock.MagicMock()
     mock_client.get_user_info.return_value = {
         'name': 'Mr. Box',
         'id': '1234567890'
     }
     mock_get.return_value = mock_client
     mock_finish.return_value = {
         'token_type': 'something',
         'access_token': 'something',
         'refresh_token': 'something'
     }
     mock_oauth.return_value = ('mytoken123', 'myboxid', 'done')
     url = api_url_for('box_oauth_finish')
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 16
0
 def test_googledrive_oauth_finish_user_only(self, mock_session, mock_auth_client_finish, mock_auth_client_userinfo):
     user_no_addon = AuthUserFactory()
     state = '1234'
     mock_session.data = {
         'googledrive_auth_state': state,
     }
     mock_auth_client_finish.return_value = {
         'access_token': '1111',
         'refresh_token': '2222',
         'expires_at': time.time() + 3600,
     }
     mock_auth_client_userinfo.return_value = {
         'sub': 'unique id',
         'name': 'test-user',
     }
     url = api_url_for('googledrive_oauth_finish', user_no_addon.auth, code='1234', state=state)
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 17
0
 def test_box_oauth_start(self):
     url = api_url_for('box_oauth_start_user')
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 18
0
 def test_box_oauth_start(self):
     url = api_url_for('box_oauth_start_user')
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 19
0
 def test_menbib_oauth_finish(self, mock_finish):
     mock_finish.return_value = AuthResult('mytokenabc', 'myrefreshabc', 'cool', '3600')
     url = api_url_for('menbib_oauth_finish')
     res = self.app.get(url)
     assert_is_redirect(res)
Exemplo n.º 20
0
 def test_does_not_have_key(self, mock_from_kwargs):
     mock_from_kwargs.return_value = Auth(user=None)
     res = self.app.get('/project/{0}'.format(self.project._primary_key),
                        {'key': None})
     assert_is_redirect(res)
Exemplo n.º 21
0
 def test_box_oauth_finish_cancelled(self, mock_flash):
     url = api_url_for('box_oauth_finish', error='User declined!')
     res = self.app.get(url)
     assert_is_redirect(res)
     mock_flash.assert_called_once()
Exemplo n.º 22
0
 def test_does_not_have_key(self, mock_from_kwargs):
     mock_from_kwargs.return_value = Auth(user=None)
     res = self.app.get('/project/{0}'.format(self.project._primary_key),
         {'key': None})
     assert_is_redirect(res)
Exemplo n.º 23
0
 def test_box_oauth_finish_cancelled(self, mock_flash):
     url = api_url_for('box_oauth_finish', error='User declined!')
     res = self.app.get(url)
     assert_is_redirect(res)
     mock_flash.assert_called_once()
Exemplo n.º 24
0
 def test_dropbox_oauth_start(self):
     url = api_url_for('dropbox_oauth_start_user')
     res = self.app.get(url)
     assert_is_redirect(res)
     assert_in('&force_reapprove=true', res.location)