@@ -108,7 +108,7 @@ async def test_identity(jp_fetch, identity, expected, identity_provider):
108108
109109 assert r .code == 200
110110 response = json .loads (r .body .decode ())
111- assert set (response .keys ()) == {"identity" , "permissions" }
111+ assert set (response .keys ()) == {"identity" , "permissions" , "updatable_fields" }
112112 identity_model = response ["identity" ]
113113 print (identity_model )
114114 for key , value in expected .items ():
@@ -117,6 +117,88 @@ async def test_identity(jp_fetch, identity, expected, identity_provider):
117117 assert set (identity_model .keys ()) == set (User .__dataclass_fields__ )
118118
119119
120+ @pytest .mark .parametrize ("identity" , [{"username" : "user.username" }])
121+ async def test_update_user_success (jp_fetch , identity , identity_provider ):
122+ """Test successful user update."""
123+ identity_provider .mock_user = MockUser (** identity )
124+ payload = {
125+ "color" : "#000000" ,
126+ }
127+ r = await jp_fetch (
128+ "/api/me" ,
129+ method = "PATCH" ,
130+ body = json .dumps (payload ),
131+ headers = {"Content-Type" : "application/json" },
132+ )
133+ assert r .code == 200
134+ response = json .loads (r .body .decode ())
135+ assert response ["status" ] == "success"
136+ assert response ["identity" ]["color" ] == "#000000"
137+
138+
139+ @pytest .mark .parametrize ("identity" , [{"username" : "user.username" }])
140+ async def test_update_user_raise (jp_fetch , identity , identity_provider ):
141+ """Test failing user update."""
142+ identity_provider .mock_user = MockUser (** identity )
143+ payload = {
144+ "name" : "Updated Name" ,
145+ "color" : "#000000" ,
146+ }
147+ with pytest .raises (HTTPError ) as exc :
148+ await jp_fetch (
149+ "/api/me" ,
150+ method = "PATCH" ,
151+ body = json .dumps (payload ),
152+ headers = {"Content-Type" : "application/json" },
153+ )
154+
155+
156+ @pytest .mark .parametrize (
157+ "identity, expected" ,
158+ [
159+ (
160+ {"username" : "user.username" },
161+ {
162+ "username" : "user.username" ,
163+ "name" : "Updated Name" ,
164+ "display_name" : "Updated Display Name" ,
165+ "color" : "#000000" ,
166+ },
167+ )
168+ ],
169+ )
170+ async def test_update_user_success_custom_updatable_fields (
171+ jp_fetch , identity , expected , identity_provider
172+ ):
173+ """Test successful user update."""
174+ identity_provider .mock_user = MockUser (** identity )
175+ identity_provider .updatable_fields = ["name" , "display_name" , "color" ]
176+ payload = {
177+ "name" : expected ["name" ],
178+ "display_name" : expected ["display_name" ],
179+ "color" : expected ["color" ],
180+ }
181+ r = await jp_fetch (
182+ "/api/me" ,
183+ method = "PATCH" ,
184+ body = json .dumps (payload ),
185+ headers = {"Content-Type" : "application/json" },
186+ )
187+ assert r .code == 200
188+ response = json .loads (r .body .decode ())
189+ identity_model = response ["identity" ]
190+ for key , value in expected .items ():
191+ assert identity_model [key ] == value
192+
193+ # Test GET request to ensure the updated fields are returned
194+ r = await jp_fetch ("api/me" )
195+ assert r .code == 200
196+ response = json .loads (r .body .decode ())
197+ identity_model = response ["identity" ]
198+ for key , value in expected .items ():
199+ assert identity_model [key ] == value
200+
201+
120202@pytest .mark .parametrize (
121203 "have_permissions, check_permissions, expected" ,
122204 [
@@ -157,7 +239,7 @@ async def test_identity_permissions(
157239 assert r is not None
158240 assert r .code == 200
159241 response = json .loads (r .body .decode ())
160- assert set (response .keys ()) == {"identity" , "permissions" }
242+ assert set (response .keys ()) == {"identity" , "permissions" , "updatable_fields" }
161243 assert response ["permissions" ] == expected
162244
163245
0 commit comments