From 5834387a0b9675c656364dc1977b989bf6a61118 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sun, 8 Sep 2019 23:00:59 -0700 Subject: [PATCH] add the basics for running the server, still incomplete.. --- ui/server.py | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/ui/server.py b/ui/server.py index 660da1d..120c027 100644 --- a/ui/server.py +++ b/ui/server.py @@ -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()