diff --git a/src/backend/api/v1/projects/serializers.py b/src/backend/api/v1/projects/serializers.py index 8d3c155..8fee767 100644 --- a/src/backend/api/v1/projects/serializers.py +++ b/src/backend/api/v1/projects/serializers.py @@ -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 @@ -183,6 +184,7 @@ class Meta: "id", "full_name", "department", + "image", "position", ) diff --git a/tests/test_04_members.py b/tests/test_04_members.py index a662ee7..1c35cae 100644 --- a/tests/test_04_members.py +++ b/tests/test_04_members.py @@ -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}/" @@ -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( diff --git a/tests/utils.py b/tests/utils.py index 0d90fc8..1f8a51d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -13,6 +13,7 @@ "image", "profile", ) +MEMBER_FIELDS = ("id", "full_name", "department", "image", "position") USER_PROJECT_FIELDS = USER_FIELDS + ("projects",) USER_DATA = { "email": "fake1@fake.com", @@ -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 = [ @@ -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: