def test_complete_has_auth_not_verified(self): with mock_auth(self.user): self.user_settings.revoke_oauth_access(self.external_account) self.node_settings.reload() assert_false(self.node_settings.has_auth) assert_false(self.node_settings.complete)
def test_revoke_remote_access_called(self): with mock.patch.object(self.user_settings, 'revoke_remote_oauth_access') as mock_revoke: with mock_auth(self.user): self.user_settings.revoke_oauth_access(self.external_account) assert_equal(mock_revoke.call_count, 1)
def test_auth_login_with_campaign_logged_in(self): ensure_schemas() url = web_url_for('auth_login', campaign='prereg') user = factories.AuthUserFactory() with self.app.app.test_request_context(url), mock_auth(user): res = auth_views.auth_login() assert_equal(res.status_code, http.FOUND) assert_equal(res.location, campaigns.CAMPAIGNS['prereg']['redirect_url']())
def test_revoke_remote_access_not_called(self): user2 = UserFactory() user2.external_accounts.add(self.external_account) user2.save() with mock.patch.object(self.user_settings, 'revoke_remote_oauth_access') as mock_revoke: with mock_auth(self.user): self.user_settings.revoke_oauth_access(self.external_account) assert_equal(mock_revoke.call_count, 0)
def test_sanction_handler(self): if not self.kind: return approval_token = self.sanction.approval_state[self.user._id]['approval_token'] handler = TokenHandler.from_string(approval_token) with mock_auth(self.user): with mock.patch('osf.utils.tokens.handlers.{0}_handler'.format(self.kind)) as mock_handler: handler.to_response() mock_handler.assert_called_with('approve', self.reg, self.reg.registered_from)
def test_serialize_granted_node(self): with mock_auth(self.user): serialized = self.ser.serialize_granted_node(self.node, auth=Auth(self.user)) for key in ('id', 'title', 'urls'): assert_in(key, serialized) assert_equal(self.node._id, serialized['id']) assert_equal(self.node.title, serialized['title']) assert_in('view', serialized['urls']) assert_equal(serialized['urls']['view'], self.node.url)
def test_sanction_handler(self): if not self.kind: return approval_token = self.sanction.approval_state[self.user._id]['approval_token'] handler = TokenHandler.from_string(approval_token) with mock_auth(self.user): with mock.patch('website.tokens.handlers.{0}_handler'.format(self.kind)) as mock_handler: handler.to_response() mock_handler.assert_called_with('approve', self.reg, self.reg.registered_from)
def test_sanction_handler_no_sanction(self): if not self.kind: return approval_token = self.sanction.approval_state[self.user._id]['approval_token'] handler = TokenHandler.from_string(approval_token) self.Model.delete(self.sanction) with mock_auth(self.user): try: handler.to_response() except HTTPError as e: assert_equal(e.code, http.BAD_REQUEST) assert_equal(e.data['message_long'], NO_SANCTION_MSG.format(self.Model.DISPLAY_NAME))
def test_confirm_email_get_with_campaign(self): user = factories.UnconfirmedUserFactory() user.system_tags.append(campaigns.CAMPAIGNS['prereg']['system_tag']) user.save() token = user.get_confirmation_token(user.username) kwargs = { 'uid': user._id, } with self.app.app.test_request_context(), mock_auth(user): res = auth_views.confirm_email_get(token, **kwargs) assert_equal(res.status_code, http.FOUND) assert_equal(res.location, campaigns.CAMPAIGNS['prereg']['redirect_url']())
def test_sanction_handler_sanction_rejected(self): if not self.kind: return approval_token = self.sanction.approval_state[self.user._id]['approval_token'] handler = TokenHandler.from_string(approval_token) self.sanction.state = Sanction.REJECTED self.sanction.save() with mock_auth(self.user): try: handler.to_response() except HTTPError as e: assert_equal(e.code, http.GONE if self.kind in ['embargo', 'registration_approval'] else http.BAD_REQUEST) assert_equal(e.data['message_long'], REJECTED_MSG.format(self.sanction.DISPLAY_NAME))
def test_confirm_email_get_with_campaign(self): for key, value in campaigns.CAMPAIGNS.items(): user = factories.UnconfirmedUserFactory() user.add_system_tag(value.get('system_tag')) user.save() token = user.get_confirmation_token(user.username) kwargs = { 'uid': user._id, } with self.app.app.test_request_context(), mock_auth(user): res = auth_views.confirm_email_get(token, **kwargs) assert_equal(res.status_code, http.FOUND) assert_equal(res.location, campaigns.campaign_url_for(key))