def test_complete_for_user(self): # create second token TokensDAO('test').create(self.userid, self.email) # complete all tokens for user TokensDAO('test').complete_for_user(self.userid) # check there are no incomplete token for the user inv = TokensDAO('test').get_for_user(self.userid) self.assertEquals(inv, None)
def test_create(self): token = TokensDAO('test').create(self.userid, self.email) self.assertEquals(token.user_id, self.userid) self.assertEquals(token.email, self.email) self.assertTrue(len(token.code) > 10) self.assertEquals(token.token_type, 'test') self.assertEquals(token.complete, False)
from altai_api import exceptions as exc from altai_api.schema import Schema from altai_api.schema import types as st from altai_api.auth import current_user_id from altai_api.utils import make_json_response, parse_request_data from altai_api.utils.decorators import (no_auth_endpoint, user_endpoint, root_endpoint) from altai_api.utils.mail import send_reset_password from altai_api.blueprints.users import get_user, fetch_user, update_user_data from altai_api.db.tokens import TokensDAO BP = Blueprint('me', __name__) ResetTokensDAO = TokensDAO('password-reset') @BP.route('') @user_endpoint @root_endpoint('me') def get_current_user(): """Current user resource shortcut""" return get_user(current_user_id()) def _find_user(data): if 1 != sum((1 if 'id' in data else 0, 1 if 'name' in data else 0, 1 if 'email' in data else 0)): raise exc.InvalidRequest('Exactly one element of id, name or email' ' must be present')
from altai_api.utils import * from altai_api.utils.decorators import root_endpoint, user_endpoint from altai_api.schema import Schema from altai_api.schema import types as st from altai_api.blueprints.projects import link_for_project from altai_api.db.tokens import TokensDAO from altai_api.utils.mail import send_invitation BP = Blueprint('users', __name__) # NOTE(imelnikov): we put it here instead of invites.py in hope # to avoid circular dependencies InvitesDAO = TokensDAO('invite') def link_for_user(user): return link_for_user_id(user.id, user.name) def link_for_user_id(user_id, user_name=None): if user_name is None: try: user_name = fetch_user(user_id, g.is_admin).name except HTTPException: user_name = None return { u'id': user_id, u'name': user_name,
def test_complete_wrong_type(self): inv = TokensDAO('test').get(self.code) self.assertRaises(ValueError, TokensDAO('xxx').complete, inv) inv = TokensDAO('test').get(self.code) self.assertEquals(False, inv.complete) self.assertEquals(None, inv.complete_at)
def test_complete(self): dao = TokensDAO('test') inv = dao.get(self.code) dao.complete(inv) inv = TokensDAO('test').get(self.code) self.assertEquals(True, inv.complete)
def test_get_not_found(self): self.assertAborts(404, TokensDAO('test').get, 'wrong code')
def test_get_token(self): inv = TokensDAO('test').get(self.code) self.assertEquals(self.userid, inv.user_id) self.assertEquals(self.email, inv.email) self.assertEquals(self.code, inv.code) self.assertEquals(False, inv.complete)
def test_wrong_type_get(self): self.assertAborts(404, TokensDAO('wrong type').get, self.code)
def test_get_for_user_respects_order(self): # create second token TokensDAO('test').create(self.userid, self.email) # check that we get first token back inv = TokensDAO('test').get_for_user(self.userid) self.assertEquals(self.code, inv.code)
def test_get_for_user_no_complete(self): dao = TokensDAO('test') inv = dao.get(self.code) dao.complete(inv) inv = TokensDAO('test').get_for_user(self.userid) self.assertEquals(inv, None)
def test_wrong_type_for_user(self): inv = TokensDAO('wrong type').get_for_user(self.userid) self.assertEquals(inv, None)
def test_get_for_wrong_user(self): inv = TokensDAO('test').get_for_user('wrong user') self.assertEquals(inv, None)
def setUp(self): super(TokensDAOTestCase, self).setUp() token = TokensDAO('test').create(self.userid, self.email) self.code = token.code