Skip to content

Commit

Permalink
add image to members
Browse files Browse the repository at this point in the history
  • Loading branch information
mxnoob committed Aug 23, 2024
1 parent b4853ec commit 6131164
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/backend/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class MemberSerializer(serializers.ModelSerializer):
department = serializers.SlugRelatedField(
slug_field="name", read_only=True
)
image = Base64ImageField(source="user.image")
full_name = serializers.SerializerMethodField(read_only=True)
position = serializers.CharField(
source="user.profile.position", read_only=True
Expand All @@ -183,6 +184,7 @@ class Meta:
"id",
"full_name",
"department",
"image",
"position",
)

Expand Down
10 changes: 4 additions & 6 deletions tests/test_04_members.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from rest_framework import status

from .utils import API_PREFIX
from .utils import API_PREFIX, MEMBER_FIELDS, check_fields

url_members = f"{API_PREFIX}/members/"
url_members_by_id = url_members + "{id}/"
Expand All @@ -11,13 +11,11 @@
def test_get_members(user_client):
response = user_client.get(url_members)
assert response.status_code == status.HTTP_200_OK
fields = ("id", "full_name", "department", "position")

json_response = response.json()
assert "results" in json_response
json_response = json_response["results"][0]
errors = [field for field in fields if field not in json_response]
assert not errors, f"Response must contain:\n" + "\n".join(errors)
assert len(fields) == len(json_response)

check_fields(json_response["results"][0], MEMBER_FIELDS)


@pytest.mark.parametrize(
Expand Down
11 changes: 8 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"image",
"profile",
)
MEMBER_FIELDS = ("id", "full_name", "department", "image", "position")
USER_PROJECT_FIELDS = USER_FIELDS + ("projects",)
USER_DATA = {
"email": "[email protected]",
Expand All @@ -21,9 +22,7 @@


def check_user_response(json_response, fields=USER_FIELDS):
errors = [field for field in fields if field not in json_response]
assert not errors, "Response must contain fields: " + ", ".join(errors)
assert len(fields) == len(json_response)
check_fields(json_response, fields)

profile_response = json_response["profile"]
profile_errors = [
Expand All @@ -35,6 +34,12 @@ def check_user_response(json_response, fields=USER_FIELDS):
assert len(PROFILE_FIELDS) == len(profile_response)


def check_fields(json_response, fields):
errors = [field for field in fields if field not in json_response]
assert not errors, "Response must contain fields: " + ", ".join(errors)
assert len(fields) == len(json_response)


def check_patch_me(json_response, new_data):
for field in USER_FIELDS:
if field in new_data:
Expand Down

0 comments on commit 6131164

Please sign in to comment.