Skip to content

Commit

Permalink
Merge pull request breatheco-de#1391 from gustavomm19/serializer-date…
Browse files Browse the repository at this point in the history
…-joined

add date_joined to user_me serializer
  • Loading branch information
tommygonzaleza authored Jun 10, 2024
2 parents d089d5e + 26b31b3 commit e9006df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions breathecode/authenticate/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ class AppUserSerializer(serpy.Serializer):
username = serpy.Field()
first_name = serpy.Field()
last_name = serpy.Field()
date_joined = serpy.Field()
github = serpy.MethodField()
profile = serpy.MethodField()

Expand Down
22 changes: 18 additions & 4 deletions breathecode/authenticate/tests/urls/tests_app_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def profile_serializer(credentials_github):
}


def get_serializer(user, credentials_github=None, profile=None):
def get_serializer(user, credentials_github=None, profile=None, **data):
return {
'email': user.email,
'username': user.username,
Expand All @@ -33,6 +33,7 @@ def get_serializer(user, credentials_github=None, profile=None):
'id': user.id,
'last_name': user.last_name,
'profile': profile_serializer(profile) if profile else None,
**data,
}


Expand Down Expand Up @@ -82,7 +83,12 @@ def test_sign_with_user__get_own_info(self):
response = self.client.get(url)

json = response.json()
expected = [get_serializer(model.user[0], model.credentials_github[0], model.profile[0])]
expected = [
get_serializer(model.user[0],
model.credentials_github[0],
model.profile[0],
date_joined=self.bc.datetime.to_iso_string(model.user[0].date_joined))
]

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down Expand Up @@ -134,7 +140,10 @@ def test_sign_without_user(self):
response = self.client.get(url)

json = response.json()
expected = get_serializer(user, model.credentials_github[user.id - 1], model.profile[user.id - 1])
expected = get_serializer(user,
model.credentials_github[user.id - 1],
model.profile[user.id - 1],
date_joined=self.bc.datetime.to_iso_string(user.date_joined))

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down Expand Up @@ -176,7 +185,12 @@ def test_user_with_agreement(self):
response = self.client.get(url)

json = response.json()
expected = [get_serializer(model.user, model.credentials_github, model.profile)]
expected = [
get_serializer(model.user,
model.credentials_github,
model.profile,
date_joined=self.bc.datetime.to_iso_string(model.user.date_joined))
]

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down
19 changes: 15 additions & 4 deletions breathecode/authenticate/tests/urls/tests_app_user_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ def profile_serializer(credentials_github):
}


def get_serializer(user, credentials_github=None, profile=None):
def get_serializer(user, credentials_github=None, profile=None, **data):
return {
'email': user.email,
'username': user.username,
'first_name': user.first_name,
'github': credentials_github_serializer(credentials_github) if credentials_github else None,
'id': user.id,
'last_name': user.last_name,
'date_joined': user.date_joined,
'profile': profile_serializer(profile) if profile else None,
**data
}


Expand Down Expand Up @@ -82,7 +84,10 @@ def test_sign_with_user__get_own_info(self):
response = self.client.get(url)

json = response.json()
expected = get_serializer(model.user[0], model.credentials_github[0], model.profile[0])
expected = get_serializer(model.user[0],
model.credentials_github[0],
model.profile[0],
date_joined=self.bc.datetime.to_iso_string(model.user[0].date_joined))

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down Expand Up @@ -134,7 +139,10 @@ def test_sign_without_user(self):
response = self.client.get(url)

json = response.json()
expected = get_serializer(user, model.credentials_github[user.id - 1], model.profile[user.id - 1])
expected = get_serializer(user,
model.credentials_github[user.id - 1],
model.profile[user.id - 1],
date_joined=self.bc.datetime.to_iso_string(user.date_joined))

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down Expand Up @@ -181,7 +189,10 @@ def test_user_with_agreement(self):
response = self.client.get(url)

json = response.json()
expected = get_serializer(model.user, model.credentials_github, model.profile)
expected = get_serializer(model.user,
model.credentials_github,
model.profile,
date_joined=self.bc.datetime.to_iso_string(model.user.date_joined))

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down
2 changes: 2 additions & 0 deletions breathecode/authenticate/tests/urls/tests_user_me.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def get_serializer(self,
user.first_name,
'last_name':
user.last_name,
'date_joined':
self.bc.datetime.to_iso_string(user.date_joined),
'username':
user.username,
'settings':
Expand Down

0 comments on commit e9006df

Please sign in to comment.