From cca2c8dbf8d0df66205fc563348ac304f707e311 Mon Sep 17 00:00:00 2001 From: Daniel McDonald Date: Wed, 20 Oct 2021 14:25:04 -0700 Subject: [PATCH] Force json (#113) * 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 --- redbiom/_requests.py | 4 ++-- redbiom/tests/test_admin.py | 26 ++++++++++++++++++++------ redbiom/tests/test_requests.py | 9 +++++---- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/redbiom/_requests.py b/redbiom/_requests.py index 74f0e66..24b783c 100644 --- a/redbiom/_requests.py +++ b/redbiom/_requests.py @@ -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(): diff --git a/redbiom/tests/test_admin.py b/redbiom/tests/test_admin.py index 7e1a18d..0ebc6c2 100644 --- a/redbiom/tests/test_admin.py +++ b/redbiom/tests/test_admin.py @@ -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) diff --git a/redbiom/tests/test_requests.py b/redbiom/tests/test_requests.py index 7cbcc67..c58820a 100644 --- a/redbiom/tests/test_requests.py +++ b/redbiom/tests/test_requests.py @@ -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)