From 058a4e860fabe0c0a01bc96a3e7b37d108b700e8 Mon Sep 17 00:00:00 2001 From: Daniel McDonald Date: Wed, 28 Jun 2023 14:06:20 -0700 Subject: [PATCH 1/2] BUG/TST: latin1 bug --- redbiom/tests/test_admin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/redbiom/tests/test_admin.py b/redbiom/tests/test_admin.py index 5f3d627..4bb4b40 100644 --- a/redbiom/tests/test_admin.py +++ b/redbiom/tests/test_admin.py @@ -343,8 +343,14 @@ def test_load_sample_metadata_content_type_sample_id_bug(self): 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) + md = metadata.copy() + + # valid portion of a name in Czech Republic, but which does not encode + # in python's http client + md.iloc[0]['STATE'] = "Vysočina" + + redbiom.admin.load_sample_metadata(md) + redbiom.admin.load_sample_metadata_full_search(md) tests = [('agp-skin', {'10317.000003302', }), # an example of a misleading query. only those AG samples From 8d38b43cc1cde88f5077337aac1fc0d6b4640612 Mon Sep 17 00:00:00 2001 From: Daniel McDonald Date: Wed, 28 Jun 2023 14:27:28 -0700 Subject: [PATCH 2/2] BUG: allow posting with bytes --- redbiom/_requests.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/redbiom/_requests.py b/redbiom/_requests.py index 916287b..ba4473e 100644 --- a/redbiom/_requests.py +++ b/redbiom/_requests.py @@ -6,12 +6,17 @@ def _parse_validate_request(req, command): return req.json()[command] -def _format_request(context, command, other): +def _format_request(context, command, other, as_bytes=False): """Merge commands, context and payload""" if context is None: - return "%s/%s.json" % (command, other) + data = "%s/%s.json" % (command, other) else: - return "%s/%s:%s.json" % (command, context, other) + data = "%s/%s:%s.json" % (command, context, other) + + if as_bytes: + return data.encode('utf-8') + else: + return data def get_session(): @@ -55,7 +60,8 @@ def f(context, cmd, payload): else: def f(context, cmd, payload, verbose=False): req = s.post(config['hostname'], - data=_format_request(context, cmd, payload)) + data=_format_request(context, cmd, payload, + as_bytes=True)) if verbose: print(context, cmd, payload[:100])