Makes minor improvements to ui_settings API testing

This commit is contained in:
Trenton Holmes 2022-05-11 11:33:08 -07:00 committed by Michael Shamoon
parent b21edde1bc
commit 0613e3ab12
2 changed files with 27 additions and 10 deletions

View File

@ -1370,21 +1370,38 @@ class TestDocumentApiV2(DirectoriesMixin, APITestCase):
test_user = User.objects.create_superuser(username="test") test_user = User.objects.create_superuser(username="test")
self.client.force_login(user=test_user) 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(response.status_code, 200)
self.assertEqual( self.assertDictEqual(
response.data["settings"], response.data["settings"],
[], {},
) )
UiSettings.objects.create( settings = {
user=test_user, "settings": {
settings='{"dark_mode":[{"enabled":"true"}]}', "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"], response.data["settings"],
"{}", settings["settings"],
) )

View File

@ -732,7 +732,7 @@ class UiSettingsView(GenericAPIView):
displayname = user.username displayname = user.username
if user.first_name or user.last_name: if user.first_name or user.last_name:
displayname = " ".join([user.first_name, user.last_name]) displayname = " ".join([user.first_name, user.last_name])
settings = [] settings = {}
if hasattr(user, "ui_settings"): if hasattr(user, "ui_settings"):
settings = user.ui_settings.settings settings = user.ui_settings.settings
return Response( return Response(