From 7be0d144bd7c4f25fd90272611b87345dcc4a426 Mon Sep 17 00:00:00 2001 From: Armin Samii Date: Tue, 23 Jul 2024 15:10:36 -0400 Subject: [PATCH 1/2] fix trailing slash, clarify rest API docs --- visualizer/tests/testRestApiExampleCode.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/visualizer/tests/testRestApiExampleCode.py b/visualizer/tests/testRestApiExampleCode.py index c41f98ed..2837bb46 100644 --- a/visualizer/tests/testRestApiExampleCode.py +++ b/visualizer/tests/testRestApiExampleCode.py @@ -165,7 +165,8 @@ def test_update_visualization(self): # In our tests, we are not hitting the real server. # Your code will use https://www.rcvis.com as the live_server_url. # To modify existing data, supply the visId - url = self.live_server_url + "/api/bp/" + str(visId) + # Note: the trailing slash is mandatory. Without it, it will fail silently. + url = self.live_server_url + "/api/bp/" + str(visId) + "/" # API key should only be created as needed, and reused and kept secure apiKey = self.get_api_key() @@ -179,9 +180,10 @@ def test_update_visualization(self): # PUT is also supported, but not shown here. data = {'dataSourceURL': 'https://www.example.com/a/different/url'} - # POST the data to create a visualization - response = requests.post(url, data=data, headers=headers, timeout=3) + # PATCH to update + response = requests.patch(url, data=data, headers=headers, timeout=3) - # The response is the same as when you created the data, sans any changes you just made + # Verify the change succeeded self.assertEqual(response.json()['slug'], 'favorite-ice-cream-flavors') self.assertEqual(response.json()['id'], visId) + self.assertEqual(response.json()['dataSourceURL'], 'https://www.example.com/a/different/url') From 9af73bfbb615ede45c7cc3c5e7a110a951331e7b Mon Sep 17 00:00:00 2001 From: Armin Samii Date: Tue, 23 Jul 2024 15:18:31 -0400 Subject: [PATCH 2/2] lint --- visualizer/tests/testRestApiExampleCode.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/visualizer/tests/testRestApiExampleCode.py b/visualizer/tests/testRestApiExampleCode.py index 2837bb46..5761c2dd 100644 --- a/visualizer/tests/testRestApiExampleCode.py +++ b/visualizer/tests/testRestApiExampleCode.py @@ -178,7 +178,8 @@ def test_update_visualization(self): # Modify the data with a PATCH. # PUT is also supported, but not shown here. - data = {'dataSourceURL': 'https://www.example.com/a/different/url'} + differentUrl = 'https://www.example.com/a/different/url' + data = {'dataSourceURL': differentUrl} # PATCH to update response = requests.patch(url, data=data, headers=headers, timeout=3) @@ -186,4 +187,4 @@ def test_update_visualization(self): # Verify the change succeeded self.assertEqual(response.json()['slug'], 'favorite-ice-cream-flavors') self.assertEqual(response.json()['id'], visId) - self.assertEqual(response.json()['dataSourceURL'], 'https://www.example.com/a/different/url') + self.assertEqual(response.json()['dataSourceURL'], differentUrl)