diff --git a/djangoldp_polls/serializers.py b/djangoldp_polls/serializers.py index 7bf3e4520d7eaace879efd64f1675603237e3adf..93cdf907102c8856ed6a8f751f58fe67a8898c92 100644 --- a/djangoldp_polls/serializers.py +++ b/djangoldp_polls/serializers.py @@ -5,6 +5,7 @@ from djangoldp_polls.models import PollOption class PollOptionSerializer(LDPSerializer): total_votes = serializers.SerializerMethodField() + with_cache = False class Meta: model = PollOption diff --git a/djangoldp_polls/tests/tests_votes.py b/djangoldp_polls/tests/tests_votes.py index 5827435c2e0e963baeff898b0f6ca8ef7e01d85b..c95ccc0e0880d660afede0deb77e3a3a31595828 100644 --- a/djangoldp_polls/tests/tests_votes.py +++ b/djangoldp_polls/tests/tests_votes.py @@ -37,6 +37,16 @@ class PermissionsTestCase(APITestCase): 'chosenOption': {'@id': option.urlid} } + def test_get_total_votes_cache(self): + self.setUpPoll() + response = self.client.get('/polloptions/{}/'.format(self.poll_option_a.pk)) + self.assertFalse('total_votes' in response.data) + + response = self.client.get('/polls/total_votes/{}/'.format(self.poll.pk)) + print(str(response.data)) + self.assertTrue('total_votes' in response.data['ldp:contains'][0]) + self.assertTrue('total_votes' in response.data['ldp:contains'][1]) + def test_can_vote_view(self): # I should be able to vote self.setUpPoll()