Exemplo n.º 1
0
def test_dup_api_token():
    from ming.orm import session
    u = M.User.register(dict(username='******'))
    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"
Exemplo n.º 2
0
 def setUp(self):
     super(TestRestApiBase, self).setUp()
     setup_global_objects()
     #        h.set_context('test', 'home')
     self.user = M.User.query.get(username='******')
     self.token = M.ApiToken(user_id=self.user._id)
     ming.orm.session(self.token).flush()
Exemplo n.º 3
0
 def gen_api_token(self):
     tok = M.ApiToken.query.get(user_id=c.user._id)
     if tok is None:
         tok = M.ApiToken(user_id=c.user._id)
     else:
         tok.secret_key = h.cryptographic_nonce()
     redirect(request.referer)
Exemplo n.º 4
0
    def token(self, username):
        if self._use_token:
            return self._use_token

        # only create token once, else ming gets dupe key error
        if username not in self._token_cache:
            user = M.User.query.get(username=username)
            token = M.ApiToken(user_id=user._id)
            ming.orm.session(token).flush()
            self._token_cache[username] = token

        return self._token_cache[username]