MetaData Sharing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
1.4 KiB

  1. #!/usr/bin/env python
  2. # Notes:
  3. # Python requests: https://2.python-requests.org/en/master/
  4. # IRequest interface: https://twistedmatrix.com/documents/current/api/twisted.web.iweb.IRequest.html
  5. # IResource interface: https://twistedmatrix.com/documents/current/api/twisted.web.resource.IResource.html
  6. # Twisted TDD: https://twistedmatrix.com/documents/current/core/howto/trial.html
  7. # Hypothesis: https://hypothesis.readthedocs.io/en/latest/
  8. # Going Async from Flask to Twisted Klein: https://crossbario.com/blog/Going-Asynchronous-from-Flask-to-Twisted-Klein/
  9. # Klein POST docs: https://klein.readthedocs.io/en/latest/examples/handlingpost.html
  10. from klein import Klein
  11. from twisted.trial import unittest
  12. from twisted.web.iweb import IRequest
  13. from kleintest import *
  14. import hashlib
  15. import os.path
  16. import shutil
  17. import tempfile
  18. class MEDAStore:
  19. app = Klein()
  20. @app.route('/')
  21. def home(request):
  22. return 'hello'
  23. # twistd support
  24. #medastore = MEDAStore()
  25. #resource = medastore.app.resource
  26. class Test(unittest.TestCase):
  27. def setUp(self):
  28. d = os.path.realpath(tempfile.mkdtemp())
  29. self.basetempdir = d
  30. self.medastore = MEDAStore()
  31. self.requests = FakeRequests(self.medastore.app)
  32. def tearDown(self):
  33. shutil.rmtree(self.basetempdir)
  34. self.basetempdir = None
  35. def test_404(self):
  36. h = hashlib.sha256(open('fixtures/testfiles/test.txt').read()).hexdigest()
  37. r = self.requests.get('/chash/%s' % h)
  38. self.assertEqual(r.status_code, 404)