Skip to content

Commit

Permalink
Merge pull request #25 from odin-detector/pin-tornado-version
Browse files Browse the repository at this point in the history
Pin tornado version to <5
  • Loading branch information
timcnicholls authored Jul 3, 2018
2 parents f7ba862 + 1e8b2db commit 7f8e96c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ tags
.tags
/.project
/.pydevproject

# Eclipse workspace metadata
.metadata/

2 changes: 1 addition & 1 deletion odin/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, debug_mode=False, access_logging=None,
access_log.setLevel(level_val)
except AttributeError:
logging.error(
"Access level logging level {} not recognised".format(access_logging)
"Access logging level {} not recognised".format(access_logging)
)

# Create an API route
Expand Down
19 changes: 18 additions & 1 deletion odin/testing/test_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

if sys.version_info[0] == 3: # pragma: no cover
from unittest.mock import Mock
else: # pragma: no cover
Expand All @@ -22,7 +23,8 @@ def setup_class(cls):
'background_task_interval': 0.1,
}
}
super(TestOdinServer, cls).setup_class(adapter_config)
access_logging='debug'
super(TestOdinServer, cls).setup_class(adapter_config, access_logging)

@classmethod
def teardown_class(cls):
Expand Down Expand Up @@ -140,6 +142,21 @@ def test_server_missing_adapters(self):

assert_true(no_adapters_msg_seen)

class TestOdinServerAccessLogging():

def test_bad_access_log_level(self):

log_capture_filter = LogCaptureFilter()
bad_level='wibble'
http_server = HttpServer(adapters=[], access_logging=bad_level)

msg_seen = False
expected_msg = 'Access logging level {} not recognised'.format(bad_level)
for msg in log_capture_filter.log_error():
if msg == expected_msg:
msg_seen = True
assert_true(msg_seen)

class TestOdinHttpServerLogging():

@classmethod
Expand Down
11 changes: 7 additions & 4 deletions odin/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class OdinTestServer(object):
server_conf_file = None

@classmethod
def start_server(cls, adapter_config=None):
def start_server(cls, adapter_config=None, access_logging=None):

cls.server_conf_file = NamedTemporaryFile(mode='w+')
parser = SafeConfigParser()
Expand All @@ -73,11 +73,14 @@ def start_server(cls, adapter_config=None):
parser.set('server', 'http_port', str(cls.server_port))
parser.set('server', 'http_addr', '127.0.0.1')
parser.set('server', 'static_path', static_path)

if adapter_config is not None:
adapters = ', '.join([adapter for adapter in adapter_config])
parser.set('server', 'adapters', adapters)

if access_logging is not None:
parser.set("server", 'access_logging', 'debug')

parser.add_section('tornado')
parser.set('tornado', 'logging', 'debug')

Expand Down Expand Up @@ -108,10 +111,10 @@ def stop_server(cls):
cls.server_conf_file = None

@classmethod
def setup_class(cls, adapter_config=None):
def setup_class(cls, adapter_config=None, access_logging=None):
if cls.launch_server:
cls.log_capture_filter = LogCaptureFilter()
cls.start_server(adapter_config)
cls.start_server(adapter_config, access_logging)
time.sleep(0.2)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ coverage==4.1b2
codeclimate-test-reporter>=0.1.0
pyzmq>=15.2.0
requests>=2.9.1
tornado>=4.3
tornado>=4.3,<5.0
future

0 comments on commit 7f8e96c

Please sign in to comment.