diff --git a/popular_proposal/rest_api.py b/popular_proposal/rest_api.py index ebac7125..3c49f65b 100644 --- a/popular_proposal/rest_api.py +++ b/popular_proposal/rest_api.py @@ -4,7 +4,7 @@ class ProposalSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = PopularProposal - fields = ('title', 'slug') + fields = ('id','title', 'slug', 'get_absolute_url') class ProposalViewSet(viewsets.ModelViewSet): queryset = PopularProposal.objects.all() diff --git a/popular_proposal/tests/api_tests.py b/popular_proposal/tests/api_tests.py index f6b74c3c..83a723ef 100644 --- a/popular_proposal/tests/api_tests.py +++ b/popular_proposal/tests/api_tests.py @@ -3,6 +3,7 @@ from popular_proposal.models import ProposalTemporaryData, PopularProposal, ProposalLike from rest_framework.test import APIClient from rest_framework.reverse import reverse +import json class PopularProposalRestAPITestCase(ProposingCycleTestCaseBase): @@ -18,5 +19,10 @@ def test_get_proposal(self): clasification=u'education' ) url = reverse('popularproposal-list') - response = self.client.get(url) + response = self.client.get(url, format='json') self.assertEquals(response.status_code, 200) + content = json.loads(response.content) + self.assertEquals(len(content), 1) + self.assertEquals(content[0]['title'], popular_proposal.title) + self.assertEquals(content[0]['id'], popular_proposal.id) + self.assertIn(popular_proposal.get_absolute_url(), content[0]['get_absolute_url']) diff --git a/requirements.txt b/requirements.txt index fbb0cbcb..1e03f6a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -52,3 +52,4 @@ django-test-without-migrations==0.6 django-model-utils==3.0.0 django-multiselectfield==0.1.7 django-robots==3.0 +djangorestframework-csv==2.0.0 diff --git a/votainteligente/votainteligente_settings.py b/votainteligente/votainteligente_settings.py index 6cbb283e..47871df9 100644 --- a/votainteligente/votainteligente_settings.py +++ b/votainteligente/votainteligente_settings.py @@ -353,6 +353,15 @@ NEW_ANSWER_ENDPOINT = 'NEW_ANSWER_ENDPOINT' +REST_FRAMEWORK = { + # specifying the renderers + 'DEFAULT_RENDERER_CLASSES': ( + 'rest_framework.renderers.JSONRenderer', + 'rest_framework.renderers.BrowsableAPIRenderer', + 'rest_framework_csv.renderers.CSVRenderer', + ), +} + THEME = None