Source code for backend.globaleaks.tests.handlers.test_token

# -*- coding: utf-8 -*-
from twisted.internet.defer import inlineCallbacks

from globaleaks.handlers import token
from globaleaks.jobs import anomalies
from globaleaks.rest import errors
from globaleaks.tests import helpers


[docs]class Test_TokenCreate(helpers.TestHandlerWithPopulatedDB):
[docs] _handler = token.TokenCreate
[docs] def assert_default_token_values(self, token): self.assertEqual(token['ttl'], 1800)
@inlineCallbacks
[docs] def test_post(self): yield anomalies.Anomalies().run() handler = self.request({}) handler.request.client_using_tor = True response = yield handler.post() self.assert_default_token_values(response)
[docs]class Test_TokenInstance(helpers.TestHandlerWithPopulatedDB):
[docs] _handler = token.TokenInstance
@inlineCallbacks
[docs] def test_put_right_answer(self): self.pollute_events() yield anomalies.Anomalies().run() token = self.getToken() request_payload = token.serialize() request_payload['answer'] = token.answer handler = self.request(request_payload) yield handler.put(token.id) token.tokenlist.use(token.id) self.assertTrue(token.solved)
@inlineCallbacks
[docs] def test_put_wrong_answer(self): self.pollute_events() yield anomalies.Anomalies().run() token = self.getToken() request_payload = token.serialize() request_payload['answer'] = 0 handler = self.request(request_payload) yield handler.put(token.id) self.assertRaises(Exception, token.tokenlist.use, token.id)