Browse Source

add the basics for running the server, still incomplete..

main
John-Mark Gurney 5 years ago
parent
commit
5834387a0b
1 changed files with 40 additions and 5 deletions
  1. +40
    -5
      ui/server.py

+ 40
- 5
ui/server.py View File

@@ -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()

Loading…
Cancel
Save