From faca7c10e05e73dce679ed95c3355a2146805dc4 Mon Sep 17 00:00:00 2001 From: Samuel Gaist <samuel.gaist@idiap.ch> Date: Wed, 22 Apr 2020 17:35:59 +0200 Subject: [PATCH] [libraries][tests] Add tests for field query string handling of PUT --- beat/web/libraries/tests/tests_api.py | 55 +++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/beat/web/libraries/tests/tests_api.py b/beat/web/libraries/tests/tests_api.py index 5cb871748..1a26fa1ee 100644 --- a/beat/web/libraries/tests/tests_api.py +++ b/beat/web/libraries/tests/tests_api.py @@ -835,7 +835,7 @@ class LibraryUpdate(LibrariesAPIBase): response = self.client.put(self.url) self.checkResponse(response, 200, content_type="application/json") - def test_successfull_update(self): + def test_successful_update(self): self.login_jackdoe() code = b"import numpy as np" @@ -867,7 +867,54 @@ class LibraryUpdate(LibrariesAPIBase): ) self.assertEqual(storage.code.load(), code) - def test_successfull_update_description_only(self): + def test_successful_update_with_specific_return_field(self): + self.login_jackdoe() + + code = b"""import numpy as np""" + + response = self.client.put( + self.url, + json.dumps( + { + "description": "blah", + "declaration": LibrariesAPIBase.UPDATE, + "code": code, + } + ), + content_type="application/json", + QUERY_STRING="fields=code", + ) + + self.checkResponse(response, 200, content_type="application/json") + answer = response.json() + self.assertEqual(len(answer), 1) + self.assertTrue("code" in answer) + + def test_successful_update_with_specific_return_several_fields(self): + self.login_jackdoe() + + code = b"""import numpy as np""" + + response = self.client.put( + self.url, + json.dumps( + { + "description": "blah", + "declaration": LibrariesAPIBase.UPDATE, + "code": code, + } + ), + content_type="application/json", + QUERY_STRING="fields=code,description", + ) + + self.checkResponse(response, 200, content_type="application/json") + answer = response.json() + self.assertEqual(len(answer), 2) + self.assertTrue("code" in answer) + self.assertTrue("description" in answer) + + def test_successful_update_description_only(self): self.login_jackdoe() response = self.client.put( @@ -883,7 +930,7 @@ class LibraryUpdate(LibrariesAPIBase): ) self.assertEqual(library.description, b"blah") - def test_successfull_update_declaration_only(self): + def test_successful_update_declaration_only(self): self.login_jackdoe() response = self.client.put( @@ -905,7 +952,7 @@ class LibraryUpdate(LibrariesAPIBase): json.loads(storage.json.load()), json.loads(LibrariesAPIBase.UPDATE) ) - def test_successfull_update_code_only(self): + def test_successful_update_code_only(self): self.login_jackdoe() code = b"import numpy as np" -- GitLab