Skip to content

Commit

Permalink
Add deselected to API response
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed Feb 28, 2024
1 parent f9d1978 commit 80ff09d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 11 additions & 6 deletions wcivf/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class PersonSerializer(serializers.ModelSerializer):

def get_absolute_url(self, obj):
if "request" in self.context:
return self.context["request"].build_absolute_uri(
obj.get_absolute_url()
)
return self.context["request"].build_absolute_uri(obj.get_absolute_url())
return obj.get_absolute_url()

class Meta:
Expand Down Expand Up @@ -49,14 +47,21 @@ class Meta:
"party",
"person",
"previous_party_affiliations",
"deselected",
"deselected_source",
)

person = PersonSerializer(many=False, read_only=True)
party = PartySerializer(many=False, read_only=True)
list_position = serializers.SerializerMethodField(allow_null=True)
previous_party_affiliations = serializers.SerializerMethodField(
allow_null=True
)
previous_party_affiliations = serializers.SerializerMethodField(allow_null=True)

def to_representation(self, instance):
ret = super().to_representation(instance)
if not ret["deselected"]:
del ret["deselected"]
del ret["deselected_source"]
return ret

def get_list_position(self, obj):
"""
Expand Down
9 changes: 9 additions & 0 deletions wcivf/apps/people/tests/test_person_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,15 @@ def test_deselected(self):
)
self.assertContains(response, "www.candidate-party-page.co.uk")

response = self.client.get(
f"/api/candidates_for_ballots/?ballot_ids={person_post.post_election.ballot_paper_id}"
)
self.assertTrue(response.json()[0]["candidates"][0]["deselected"])
self.assertEqual(
response.json()[0]["candidates"][0]["deselected_source"],
"www.candidate-party-page.co.uk",
)


class TestPersonViewUnitTests:
@pytest.fixture
Expand Down

0 comments on commit 80ff09d

Please sign in to comment.