Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force json #113

Merged
merged 4 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions redbiom/_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def _parse_validate_request(req, command):
def _format_request(context, command, other):
"""Merge commands, context and payload"""
if context is None:
return "%s/%s" % (command, other)
return "%s/%s.json" % (command, other)
else:
return "%s/%s:%s" % (command, context, other)
return "%s/%s:%s.json" % (command, context, other)


def get_session():
Expand Down
26 changes: 20 additions & 6 deletions redbiom/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,36 @@ def test_load_sample_metadata_content_type_bug(self):
# Python's urllib.parse.quote_plus does not automatically encode
# "." characters.
# See: https://github.com/nicolasff/webdis#command-format

# expand the test set to include .raw and other format type requests
md = metadata.copy()
md['http_quoted_characters'] = ['a.html', 'b.html', 'foo/bar.html',
'baz.html', 'thing.html', 'stuff.html',
'asd#asd.html', 'a.html', 'b.html',
'foo.html']
'baz.raw', 'thing.msgpack',
'stuff.html', 'asd#asd.html',
'a.html', 'b.html', 'foo.html']
redbiom.admin.load_sample_metadata(md)

exp = ['foo', 'bar', 'foo/bar', 'baz$12',
'thing', 'stuff', 'asd#asd', 'a', 'b', 'foo.html']
exp = ['a.html', 'b.html', 'foo/bar.html', 'baz.html', 'thing.html',
exp = ['a.html', 'b.html', 'foo/bar.html', 'baz.raw', 'thing.msgpack',
'stuff.html', 'asd#asd.html', 'a.html', 'b.html', 'foo.html']
obs = self.get('metadata:category', 'HGETALL',
'http_quoted_characters')
self.assertEqual(sorted([v for k, v in obs.items()]),
sorted(exp))

def test_load_sample_metadata_content_type_sample_id_bug(self):
# similar as test_load_sample_metadata_content_type_bug but sample IDs
# are special...

# expand the test set to include .raw and other format type requests
md = metadata.copy()
cur = md['#SampleID'].iloc[0]
md.iloc[0]['#SampleID'] = cur + '.raw'
redbiom.admin.load_sample_metadata(md)

obs = self.get('metadata', 'smembers',
'samples-represented')
self.assertIn(cur + '.raw', obs)

def test_load_sample_metadata_full_search(self):
redbiom.admin.load_sample_metadata(metadata)
redbiom.admin.load_sample_metadata_full_search(metadata)
Expand Down
9 changes: 5 additions & 4 deletions redbiom/tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def test_parse_valid_request(self):
_parse_validate_request(req, 'EXISTS')

def test_format_request(self):
self.assertEqual(_format_request(None, 'foo', 'bar'), "foo/bar")
self.assertEqual(_format_request(None, 'foo', ''), "foo/")
self.assertEqual(_format_request(None, '', 'bar'), "/bar")
self.assertEqual(_format_request('baz', 'foo', 'bar'), "foo/baz:bar")
self.assertEqual(_format_request(None, 'foo', 'bar'), "foo/bar.json")
self.assertEqual(_format_request(None, 'foo', ''), "foo/.json")
self.assertEqual(_format_request(None, '', 'bar'), "/bar.json")
self.assertEqual(_format_request('baz', 'foo', 'bar'),
"foo/baz:bar.json")

def test_make_post(self):
post = make_post(config)
Expand Down