From 0613e3ab1232ebc4a01d9f09618735c4c4ad4152 Mon Sep 17 00:00:00 2001 From: Trenton Holmes Date: Wed, 11 May 2022 11:33:08 -0700 Subject: [PATCH] Makes minor improvements to ui_settings API testing --- src/documents/tests/test_api.py | 35 ++++++++++++++++++++++++--------- src/documents/views.py | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py index 38a377c15..2b3643136 100644 --- a/src/documents/tests/test_api.py +++ b/src/documents/tests/test_api.py @@ -1370,21 +1370,38 @@ class TestDocumentApiV2(DirectoriesMixin, APITestCase): test_user = User.objects.create_superuser(username="test") self.client.force_login(user=test_user) - response = self.client.get(f"/api/ui_settings/", format="json") + response = self.client.get("/api/ui_settings/", format="json") self.assertEqual(response.status_code, 200) - self.assertEqual( + self.assertDictEqual( response.data["settings"], - [], + {}, ) - UiSettings.objects.create( - user=test_user, - settings='{"dark_mode":[{"enabled":"true"}]}', + settings = { + "settings": { + "dark_mode": { + "enabled": True, + }, + }, + } + + response = self.client.post( + "/api/ui_settings/", + json.dumps(settings), + content_type="application/json", ) - response = self.client.get(f"/api/ui_settings/", format="json") - self.assertNotEqual( + + self.assertEqual(response.status_code, 200) + + response = self.client.get("/api/ui_settings/", format="json") + + print(response) + print(response.data) + + self.assertEqual(response.status_code, 200) + self.assertDictEqual( response.data["settings"], - "{}", + settings["settings"], ) diff --git a/src/documents/views.py b/src/documents/views.py index 16bb28e15..e718d5c43 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -732,7 +732,7 @@ class UiSettingsView(GenericAPIView): displayname = user.username if user.first_name or user.last_name: displayname = " ".join([user.first_name, user.last_name]) - settings = [] + settings = {} if hasattr(user, "ui_settings"): settings = user.ui_settings.settings return Response(