Skip to content

Commit 2fb9dc5

Browse files
committed
update tests
1 parent e2e4aef commit 2fb9dc5

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

app/tests.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,13 @@ def testGetAsAdmin(self):
246246
self.client.force_login(self.admin)
247247
r = self.client.get(self.url)
248248
self.assertEqual(r.status_code, status.HTTP_200_OK)
249-
self.assertEqual(len(r.json()), len(self.users))
250-
# TODO actually check the content
249+
data = r.json()
250+
self.assertEqual(len(data), len(self.users))
251+
252+
# Check that date_joined and last_login are present in response
253+
for user_data in data:
254+
self.assertIn("date_joined", user_data)
255+
self.assertIn("last_login", user_data)
251256

252257
def testGetAsUser(self):
253258
self.client.force_login(create_random_user())
@@ -262,6 +267,11 @@ def setUp(self):
262267
self.want = {
263268
"username": self.user.username,
264269
"name": self.user.name,
270+
"email": self.user.email,
271+
"is_staff": self.user.is_staff,
272+
"is_superuser": self.user.is_superuser,
273+
"is_approved": self.user.is_approved,
274+
"ssh_public_keys": self.user.ssh_public_keys,
265275
}
266276

267277
def testGetAsAnon(self):
@@ -272,13 +282,21 @@ def testGetAsAdmin(self):
272282
self.client.force_login(create_random_admin_user())
273283
r = self.client.get(self.url)
274284
self.assertEqual(r.status_code, status.HTTP_200_OK)
275-
assertDictContainsSubset(self.want, r.json())
285+
data = r.json()
286+
assertDictContainsSubset(self.want, data)
287+
self.assertIn("url", data)
288+
self.assertIn("date_joined", data)
289+
self.assertIn("last_login", data)
276290

277291
def testGetAsSelf(self):
278292
self.client.force_login(self.user)
279293
r = self.client.get(self.url)
280294
self.assertEqual(r.status_code, status.HTTP_200_OK)
281-
assertDictContainsSubset(self.want, r.json())
295+
data = r.json()
296+
assertDictContainsSubset(self.want, data)
297+
self.assertIn("url", data)
298+
self.assertIn("date_joined", data)
299+
self.assertIn("last_login", data)
282300

283301
def testGetAsOther(self):
284302
self.client.force_login(create_random_user())
@@ -296,16 +314,22 @@ def testGetAsUser(self):
296314
self.client.force_login(user)
297315
r = self.client.get("/users/~self")
298316
self.assertEqual(r.status_code, status.HTTP_200_OK)
317+
data = r.json()
299318
assertDictContainsSubset(
300319
{
301320
"username": user.username,
302321
"name": user.name,
322+
"email": user.email,
303323
"is_staff": user.is_staff,
304324
"is_superuser": user.is_superuser,
305325
"is_approved": user.is_approved,
326+
"ssh_public_keys": user.ssh_public_keys,
306327
},
307-
r.json(),
328+
data,
308329
)
330+
self.assertIn("url", data)
331+
self.assertIn("date_joined", data)
332+
self.assertIn("last_login", data)
309333

310334

311335
class TestUserProfileView(TestCase):

0 commit comments

Comments
 (0)