Skip to content

Commit

Permalink
Merge pull request ckan#18 from qld-gov-au/fix-tests-pre-githubActions
Browse files Browse the repository at this point in the history
Fix tests pre GitHub actions
  • Loading branch information
ThrawnCA authored Feb 14, 2021
2 parents b4125b9 + 85f4261 commit 484d1b6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ckanext/qa/sniff_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def sniff_file_format(filepath):
if has_rdfa(buf):
format_ = {'format': 'RDFa'}

else:
if not format_:
# Excel files sometimes not picked up by magic, so try alternative
if is_excel(filepath):
format_ = {'format': 'XLS'}
Expand Down
18 changes: 14 additions & 4 deletions ckanext/qa/tests/mock_remote_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class MockEchoTestServer(MockHTTPServer):
a 500 error response: 'http://localhost/?status=500'
a 200 OK response, returning the function's docstring:
'http://localhost/?status=200;content-type=text/plain;content_var=ckan.tests.lib.test_package_search:test_wsgi_app.__doc__'
'http://localhost/?status=200;content-type=text/plain;content_var
=ckan.tests.lib.test_package_search:test_wsgi_app.__doc__'
To specify content, use:
Expand All @@ -114,19 +115,28 @@ def __call__(self, environ, start_response):
if 'content_var' in request.str_params:
content = request.str_params.get('content_var')
content = self.get_content(content)
elif 'content_long' in request.str_params:
content = '*' * 1000001
else:
content = request.str_params.get('content', '')
if 'method' in request.str_params \
and request.method.lower() != request.str_params['method'].lower():
content = ''
status = 405

if isinstance(content, six.string_types):
if isinstance(content, six.text_type):
raise TypeError("Expected raw byte string for content")

headers = [
item
for item in request.str_params.items()
if item[0] not in ('content', 'status')
]
if content:
headers += [('Content-Length', str(len(content)))]
if 'length' in request.str_params:
cl = request.str_params.get('length')
headers += [('Content-Length', cl)]
elif content and 'no-content-length' not in request.str_params:
headers += [('Content-Length', six.binary_type(len(content)))]
start_response(
'%d %s' % (status, responses[status]),
headers
Expand Down
11 changes: 3 additions & 8 deletions ckanext/qa/tests/test_sniff_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def assert_file_has_format_sniffed_correctly(cls, format_extension, filepath):
'''Given a filepath, checks the sniffed format matches the format_extension.'''
expected_format = format_extension
sniffed_format = sniff_file_format(filepath)
assert sniffed_format, expected_format
assert sniffed_format, "Expected {} but failed to sniff any format for file: {}".format(expected_format, filepath)
expected_format_without_zip = expected_format.replace('.zip', '')
assert_equal(sniffed_format['format'].lower(), expected_format_without_zip)

Expand All @@ -49,16 +49,11 @@ def assert_file_has_format_sniffed_correctly(cls, format_extension, filepath):
def check_format(cls, format, filename=None):
for format_extension, filepath in cls.fixture_files:
if format_extension == format:
if filename:
if filename in filepath:
break
else:
continue
else:
if not filename or filename in filepath:
cls.assert_file_has_format_sniffed_correctly(format_extension, filepath)
break
else:
assert 0, format # Could not find fixture for format
cls.assert_file_has_format_sniffed_correctly(format_extension, filepath)

def test_xls(self):
self.check_format('xls', '10-p108-data-results')
Expand Down
4 changes: 1 addition & 3 deletions test-core.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ port = 5000
[app:main]
use = config:../ckan/test-core.ini

ckan.plugins = qa

# Logging configuration
[loggers]
keys = root, ckan, ckanext, sqlalchemy
Expand Down Expand Up @@ -52,7 +50,7 @@ propagate = 0
[logger_sqlalchemy]
handlers =
qualname = sqlalchemy.engine
level = WARN
level = WARN
propagate = 0

[handler_console]
Expand Down
4 changes: 3 additions & 1 deletion test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use = config:test-core.ini
# run fast.
faster_db_test_hacks = True
sqlalchemy.url = sqlite:///

ckan.plugins = qa
# NB: other test configuration should go in test-core.ini, which is
# what the postgres tests use.

Expand Down Expand Up @@ -54,7 +56,7 @@ propagate = 0
[logger_sqlalchemy]
handlers = console
qualname = sqlalchemy.engine
level = WARN
level = WARN

[logger_harvest]
level = WARNING
Expand Down

0 comments on commit 484d1b6

Please sign in to comment.