Permalink
Browse files

fixed web tests.

  • Loading branch information...
javipalanca committed Sep 7, 2018
1 parent d961790 commit 37c1dbbd282c7e2c3b7338f89f850c19a0ac422b
Showing with 110 additions and 144 deletions.
  1. +2 −2 requirements.txt
  2. +1 −0 requirements_dev.txt
  3. +7 −6 spade/agent.py
  4. +12 −8 spade/web.py
  5. +88 −128 tests/test_web.py
View
@@ -1,6 +1,6 @@
multidict<5.0,>=2.0
multidict==4.4.0
aioxmpp>=0.10
aiohttp>=2.3.1
aiohttp>=3.4.4
aiohttp_jinja2>=0.14.0
jinja2>=2.9.6
jinja2-time==0.2.0
View
@@ -21,3 +21,4 @@ parsel==1.4.0
docutils==0.12
sphinx_rtd_theme==0.4.0
testfixtures==6.3.0
pytest-aiohttp==0.3.0
View
@@ -246,10 +246,11 @@ def run(self):
self.loop.run_forever()
def finalize(self):
aexit = self.conn_coro.__aexit__(*sys.exc_info())
future = asyncio.run_coroutine_threadsafe(aexit, loop=self.loop)
try:
future.result(timeout=5)
except Exception as e: # pragma: no cover
logger.error("Could not disconnect from server: {}.".format(e))
if self.agent.is_alive():
aexit = self.conn_coro.__aexit__(*sys.exc_info())
future = asyncio.run_coroutine_threadsafe(aexit, loop=self.loop)
try:
future.result(timeout=5)
except Exception as e: # pragma: no cover
logger.error("Could not disconnect from server: {}.".format(e))
self.loop.call_soon_threadsafe(self.loop.stop)
View
@@ -34,27 +34,31 @@ def __init__(self, agent):
self.hostname = None
self.port = None
self.app = aioweb.Application()
internal_loader = jinja2.PackageLoader("spade", package_path='templates', encoding='utf-8')
cwd_loader = jinja2.FileSystemLoader(".")
self.loaders = [internal_loader, cwd_loader]
self._set_loaders()
def start(self, hostname=None, port=None, templates_path=None):
self.hostname = hostname if hostname else "localhost"
if port:
self.port = port
elif not self.port:
self.port = unused_port(self.hostname)
internal_loader = jinja2.PackageLoader("spade", package_path='templates', encoding='utf-8')
cwd_loader = jinja2.FileSystemLoader(".")
loaders = [internal_loader, cwd_loader]
if templates_path:
loaders.insert(0, jinja2.FileSystemLoader(templates_path))
loader = jinja2.ChoiceLoader(loaders)
self.loaders.insert(0, jinja2.FileSystemLoader(templates_path))
self._set_loaders()
self.setup_routes()
self.handler = self.app.make_handler()
self.agent.submit(start_server_in_aiothread(self.handler, self.hostname, self.port, self.agent))
def _set_loaders(self):
loader = jinja2.ChoiceLoader(self.loaders)
aiohttp_jinja2.setup(self.app, loader=loader,
extensions=['jinja2_time.TimeExtension'],
context_processors=[self.agent_processor,
aiohttp_jinja2.request_processor]
)
self.setup_routes()
self.handler = self.app.make_handler()
self.agent.submit(start_server_in_aiothread(self.handler, self.hostname, self.port, self.agent))
def setup_routes(self):
self.app.router.add_get("/", self.index)
Oops, something went wrong.

0 comments on commit 37c1dbb

Please sign in to comment.