Skip to content

Commit

Permalink
Merge pull request #245 from candango/develop
Browse files Browse the repository at this point in the history
Merging develop to master.
  • Loading branch information
piraz committed Dec 1, 2018
2 parents ff66214 + b818dfc commit dc5c37a
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release notes
.. toctree::
:maxdepth: 2

releases/v0.1.7.4
releases/v0.1.7.3
releases/v0.1.7.2
releases/v0.1.7.1
Expand Down
36 changes: 36 additions & 0 deletions docs/releases/v0.1.7.4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
What's new in Firenado 0.1.7.4
==============================

Dec 01, 2018
------------

We are pleased to announce the release of Firenado 0.1.7.4.

With launcher loading separately from the launch method we can use it to
retrieve applications in management tasks and tests.

Services will retrieve a data connected consumer when calling the get data
connected method.

Fixed an attempt to write a none session. This is happening when we have a
handler with error set by tornado. The error was noticed in a post method
without xsrf argument/cookie. The handler was set with a 403 and other
exception as raised because we were waiting for a valid session. Now a warning
will be logged regarding the issue of a none session in this case.

Here are the highlights:

Refactory
~~~~~~~~~

* Launcher should load the application before launch. `#243 <https://github.com/candango/firenado/issues/243>`_

New Features
~~~~~~~~~~~~

* Service should return the consumer if it is a data connected. `#152 <https://github.com/candango/firenado/issues/152>`_

Bug Fixes
~~~~~~~~~

* When xsrf argument is missing from post we try to write an empty session. `#241 <https://github.com/candango/firenado/issues/241>`_
2 changes: 1 addition & 1 deletion firenado/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
from __future__ import (absolute_import, division, print_function,
with_statement)

__version__ = (0, 1, 7, 3)
__version__ = (0, 1, 7, 4)
1 change: 1 addition & 0 deletions firenado/management/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def run(self, namespace):

app_type = firenado.conf.app['types'][firenado.conf.app['type']]
launcher = get_class_from_config(app_type['launcher'])(**parameters)
launcher.load()
launcher.launch()


Expand Down
3 changes: 3 additions & 0 deletions firenado/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def data_connected(self):
"""
if self.consumer is None:
return None
from firenado.data import DataConnectedMixin
if isinstance(self.consumer, DataConnectedMixin):
return self.consumer
invert_op = getattr(self.consumer, "get_data_connected", None)
if callable(invert_op):
return self.consumer.get_data_connected()
Expand Down
10 changes: 8 additions & 2 deletions firenado/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,14 @@ def write(method):
def wrapper(self, *args, **kwargs):
retval = method(self, *args, **kwargs)
if firenado.conf.session['enabled']:
logging.debug("Writing session %s." % self.session.id)
self.application.session_engine.store_session(self)
if self.session is None:
logging.error("The handler session is None. Something wrong"
" happened during the handler execution. The"
" current handler status is: %s." %
self.get_status())
else:
logging.debug("Writing session %s." % self.session.id)
self.application.session_engine.store_session(self)
return retval
return wrapper

Expand Down
15 changes: 9 additions & 6 deletions firenado/tornadoweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def __init__(self, addresses=None, dir=None, port=None):
os.chdir(self.dir)
reload(firenado.conf)

def load(self):
return None

def launch(self):
return None

Expand Down Expand Up @@ -187,23 +190,23 @@ class TornadoLauncher(FirenadoLauncher):
def __init__(self, addresses=None, dir=None, port=None):
super(TornadoLauncher, self).__init__(addresses, dir, port)
self.http_server = None
self.application = None
self.MAX_WAIT_SECONDS_BEFORE_SHUTDOWN = firenado.conf.app[
'wait_before_shutdown']

def launch(self):
import signal

def load(self):
# TODO: Resolve module if doesn't exists
if firenado.conf.app['pythonpath']:
sys.path.append(firenado.conf.app['pythonpath'])
self.application = TornadoApplication(debug=firenado.conf.app['debug'])

def launch(self):
import signal
signal.signal(signal.SIGTERM, self.sig_handler)
signal.signal(signal.SIGINT, self.sig_handler)
if os.name == "posix":
signal.signal(signal.SIGTSTP, self.sig_handler)
self.application = TornadoApplication(debug=firenado.conf.app['debug'])
self.http_server = tornado.httpserver.HTTPServer(
self.application)
self.http_server = tornado.httpserver.HTTPServer(self.application)
if firenado.conf.app['socket']:
from tornado.netutil import bind_unix_socket
socket = bind_unix_socket(firenado.conf.app['socket'])
Expand Down
18 changes: 18 additions & 0 deletions tests/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
from firenado.service import served_by, FirenadoService


class MockServiceDataConnected(FirenadoService):
""" Serves a data connected method directly.
When decorating a data connected directly the service must return the
consumer.
"""
pass


class MockDataConnected(DataConnectedMixin):
""" Data connected mock object. This object holds the data sources to be
used in the test cases.
Expand All @@ -32,6 +40,9 @@ def __init__(self):
self.data_sources['datasource1'] = 'DataSource1'
self.data_sources['datasource2'] = 'DataSource2'

@served_by(MockServiceDataConnected)
def get_service_data_sources_directly(self):
return self.mock_service_data_connected.get_data_sources()

class MockTestService(FirenadoService):
""" Service that decorates the instance to be served directly and
Expand Down Expand Up @@ -156,6 +167,13 @@ def test_get_data_source_from_service(self):
self.assertEqual(data_sources['datasource1'], "DataSource1")
self.assertEqual(data_sources['datasource2'], "DataSource2")

def test_get_data_source_from_data_connected(self):
data_sources = self.data_connected_instance.\
get_service_data_sources_directly()
self.assertTrue(len(data_sources) == 2)
self.assertEqual(data_sources['datasource1'], "DataSource1")
self.assertEqual(data_sources['datasource2'], "DataSource2")

def test_get_data_source_from_service_recursively(self):
data_sources = self.served_by_instance.\
get_service_data_sources_recursively()
Expand Down
8 changes: 7 additions & 1 deletion tests/tornadoweb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import firenado.conf
from firenado.tornadoweb import TornadoApplication
from firenado.tornadoweb import TornadoHandler
from firenado.tornadoweb import FirenadoLauncher
from firenado.tornadoweb import FirenadoLauncher, TornadoLauncher
from firenado.tornadoweb import TornadoComponent
import unittest
from tests import chdir_app
Expand Down Expand Up @@ -137,3 +137,9 @@ def test_parameters_set(self):
self.assertEqual(addresses, launcher.addresses)
self.assertEqual(dir, launcher.dir)
self.assertEqual(port, launcher.port)

def test_load(self):
chdir_app('tornadoweb')
launcher = TornadoLauncher()
launcher.load()
self.assertTrue(isinstance(launcher.application, TornadoApplication))

0 comments on commit dc5c37a

Please sign in to comment.