|
|
@@ -15,27 +15,48 @@ from twisted.web.iweb import IRequest |
|
|
|
from kleintest import * |
|
|
|
|
|
|
|
import hashlib |
|
|
|
import mock |
|
|
|
import os.path |
|
|
|
import shutil |
|
|
|
import tempfile |
|
|
|
|
|
|
|
class MEDAStore: |
|
|
|
class MEDAServer: |
|
|
|
app = Klein() |
|
|
|
|
|
|
|
def store(self): |
|
|
|
pass |
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
def home(request): |
|
|
|
return 'hello' |
|
|
|
|
|
|
|
# twistd support |
|
|
|
#medastore = MEDAStore() |
|
|
|
#resource = medastore.app.resource |
|
|
|
#medaserver = MEDAServer() |
|
|
|
#resource = medaserver.app.resource |
|
|
|
|
|
|
|
def main(): |
|
|
|
from optparse import OptionParser |
|
|
|
|
|
|
|
parser = OptionParser() |
|
|
|
|
|
|
|
options, args = parser.parse_args() |
|
|
|
|
|
|
|
medaserver = MEDAServer() |
|
|
|
|
|
|
|
try: |
|
|
|
medaserver.app.run() |
|
|
|
finally: |
|
|
|
medaserver.store() |
|
|
|
|
|
|
|
if __name__ == '__main__': # pragma: no cover |
|
|
|
main() |
|
|
|
|
|
|
|
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) |
|
|
|
self.medaserver = MEDAServer() |
|
|
|
self.requests = FakeRequests(self.medaserver.app) |
|
|
|
|
|
|
|
def tearDown(self): |
|
|
|
shutil.rmtree(self.basetempdir) |
|
|
@@ -45,3 +66,17 @@ class _TestCases(unittest.TestCase): |
|
|
|
h = hashlib.sha256(open('fixtures/testfiles/test.txt').read()).hexdigest() |
|
|
|
r = self.requests.get('/chash/%s' % h) |
|
|
|
self.assertEqual(r.status_code, 404) |
|
|
|
|
|
|
|
def test_addpubkey(self): |
|
|
|
import cli |
|
|
|
|
|
|
|
persona = cli.Persona() |
|
|
|
persona.generate_key() |
|
|
|
|
|
|
|
@mock.patch('server.MEDAServer.store') |
|
|
|
@mock.patch('klein.Klein.run') |
|
|
|
def test_appruns(self, kleinrun, storefun): |
|
|
|
main() |
|
|
|
|
|
|
|
kleinrun.assert_called() |
|
|
|
storefun.assert_called() |