#!/usr/bin/env python # Notes: # Python requests: https://2.python-requests.org/en/master/ # IRequest interface: https://twistedmatrix.com/documents/current/api/twisted.web.iweb.IRequest.html # IResource interface: https://twistedmatrix.com/documents/current/api/twisted.web.resource.IResource.html # Twisted TDD: https://twistedmatrix.com/documents/current/core/howto/trial.html # Hypothesis: https://hypothesis.readthedocs.io/en/latest/ # Going Async from Flask to Twisted Klein: https://crossbario.com/blog/Going-Asynchronous-from-Flask-to-Twisted-Klein/ # Klein POST docs: https://klein.readthedocs.io/en/latest/examples/handlingpost.html from klein import Klein from twisted.trial import unittest from twisted.web.iweb import IRequest from kleintest import * import hashlib import os.path import shutil import tempfile class MEDAStore: app = Klein() @app.route('/') def home(request): return 'hello' # twistd support #medastore = MEDAStore() #resource = medastore.app.resource class _TestCases(unittest.TestCase): def setUp(self): d = os.path.realpath(tempfile.mkdtemp()) self.basetempdir = d self.medastore = MEDAStore() self.requests = FakeRequests(self.medastore.app) def tearDown(self): shutil.rmtree(self.basetempdir) self.basetempdir = None def test_404(self): h = hashlib.sha256(open('fixtures/testfiles/test.txt').read()).hexdigest() r = self.requests.get('/chash/%s' % h) self.assertEqual(r.status_code, 404)