From a73a7d1e7b4d96d209d029db6d72d2818330bce9 Mon Sep 17 00:00:00 2001 From: Stefano Palazzo Date: Fri, 23 Dec 2016 11:42:00 +0100 Subject: [PATCH 1/2] Make it possible to disable the logo by subclassing Config --- sanic/sanic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sanic/sanic.py b/sanic/sanic.py index 98bb230d..2ef3507e 100644 --- a/sanic/sanic.py +++ b/sanic/sanic.py @@ -294,7 +294,8 @@ class Sanic: if debug: log.setLevel(logging.DEBUG) - log.debug(self.config.LOGO) + if self.config.LOGO is not None: + log.debug(self.config.LOGO) # Serve log.info('Goin\' Fast @ http://{}:{}'.format(host, port)) From 6a322ba3f8076d6e914a51f2028f38114f1f0d68 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Wed, 1 Feb 2017 09:00:57 -0600 Subject: [PATCH 2/2] Updates static tests to test for issue #374 Adds a test to test for serving a static directory at the root uri '/' to address concerns found in #374. Also rewrites the tests so that they are parametrized and do more with less. --- tests/test_static.py | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/tests/test_static.py b/tests/test_static.py index 82b0d1f9..629ee95c 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -16,47 +16,35 @@ def static_file_directory(): return static_directory -@pytest.fixture(scope='module') -def static_file_path(static_file_directory): - """The path to the static file that we want to serve""" - return os.path.join(static_file_directory, 'test.file') +def get_file_path(static_file_directory, file_name): + return os.path.join(static_file_directory, file_name) -@pytest.fixture(scope='module') -def static_file_content(static_file_path): +def get_file_content(static_file_directory, file_name): """The content of the static file to check""" - with open(static_file_path, 'rb') as file: + with open(get_file_path(static_file_directory, file_name), 'rb') as file: return file.read() -def test_static_file(static_file_path, static_file_content): +@pytest.mark.parametrize('file_name', ['test.file', 'decode me.txt']) +def test_static_file(static_file_directory, file_name): app = Sanic('test_static') - app.static('/testing.file', static_file_path) + app.static( + '/testing.file', get_file_path(static_file_directory, file_name)) request, response = sanic_endpoint_test(app, uri='/testing.file') assert response.status == 200 - assert response.body == static_file_content + assert response.body == get_file_content(static_file_directory, file_name) -def test_static_directory( - static_file_directory, static_file_path, static_file_content): +@pytest.mark.parametrize('file_name', ['test.file', 'decode me.txt']) +@pytest.mark.parametrize('base_uri', ['/static', '', '/dir']) +def test_static_directory(file_name, base_uri, static_file_directory): app = Sanic('test_static') - app.static('/dir', static_file_directory) + app.static(base_uri, static_file_directory) - request, response = sanic_endpoint_test(app, uri='/dir/test.file') + request, response = sanic_endpoint_test( + app, uri='{}/{}'.format(base_uri, file_name)) assert response.status == 200 - assert response.body == static_file_content - - -def test_static_url_decode_file(static_file_directory): - decode_me_path = os.path.join(static_file_directory, 'decode me.txt') - with open(decode_me_path, 'rb') as file: - decode_me_contents = file.read() - - app = Sanic('test_static') - app.static('/dir', static_file_directory) - - request, response = sanic_endpoint_test(app, uri='/dir/decode me.txt') - assert response.status == 200 - assert response.body == decode_me_contents + assert response.body == get_file_content(static_file_directory, file_name)