Skip to content

Commit

Permalink
Force json (#113)
Browse files Browse the repository at this point in the history
* TST: sample id content type bug

* MAINT: fix issue where samples with .raw as a suffix were triggering unexpected returns

* Don't suffix twice

* Adjsut to account for force of json
  • Loading branch information
wasade authored Oct 20, 2021
1 parent edca791 commit cca2c8d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
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

0 comments on commit cca2c8d

Please sign in to comment.