From 26496806e783f373b6ce94a68ad0c0d8ce0d9b11 Mon Sep 17 00:00:00 2001 From: Le H Ngo Date: Mon, 12 Feb 2024 01:01:52 +0000 Subject: [PATCH] Updates to model with choices and rename --- api/survey/enums.py | 38 +++++++++++++++++++++++++ api/survey/migrations/0001_initial.py | 40 ++++++++++++++++++++++----- api/survey/models.py | 17 +++++++----- api/survey/serializers.py | 4 +-- api/survey/tests/test_crud.py | 9 +++--- api/survey/urls.py | 4 +-- api/survey/views.py | 16 +++++------ 7 files changed, 98 insertions(+), 30 deletions(-) create mode 100644 api/survey/enums.py diff --git a/api/survey/enums.py b/api/survey/enums.py new file mode 100644 index 0000000000..5adc649733 --- /dev/null +++ b/api/survey/enums.py @@ -0,0 +1,38 @@ +class RecommendationChoiceType: + SATISFIED = "SATISFIED" + + choices = [ + (SATISFIED, "SATISFIED"), + ] + + +class HelpfulGuidanceChoiceType: + STRONGLY_DISAGREE = "STRONGLY DISAGREE" + DISAGREE = "DISAGREE" + NEITHER_AGREE_NOR_DISAGREE = "NEITHER AGREE NOR DISAGREE" + AGREE = "AGREE" + STRONGLY_AGREE = "STRONGLY AGREE" + + choices = [ + (STRONGLY_DISAGREE, "STRONGLY DISAGREE"), + (DISAGREE, "DISAGREE"), + (NEITHER_AGREE_NOR_DISAGREE, "NEITHER AGREE NOR DISAGREE"), + (AGREE, "AGREE"), + (STRONGLY_AGREE, "STRONGLY AGREE"), + ] + + +class UserAccountChoiceType: + VERY_DIFFICULT = "VERY DIFFICULT" + DIFFICULT = "DIFFICULT" + NEITHER_DIFFICULT_NOR_EASY = "NEITHER DIFFICULT NOR EASY" + EASY = "EASY" + VERY_EASY = "VERY EASY" + + choices = [ + (VERY_DIFFICULT, "VERY DIFFICULT"), + (DIFFICULT, "DIFFICULT"), + (NEITHER_DIFFICULT_NOR_EASY, "NEITHER DIFFICULT NOR EASY"), + (EASY, "EASY"), + (VERY_EASY, "VERY EASY"), + ] diff --git a/api/survey/migrations/0001_initial.py b/api/survey/migrations/0001_initial.py index 7e3ee7572f..10aeac7b90 100644 --- a/api/survey/migrations/0001_initial.py +++ b/api/survey/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.10 on 2024-02-08 22:37 +# Generated by Django 4.2.10 on 2024-02-12 01:00 from django.db import migrations, models import django.utils.timezone @@ -14,7 +14,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="Survey", + name="SurveyResponse", fields=[ ( "created_at", @@ -34,12 +34,38 @@ class Migration(migrations.Migration): db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False ), ), - ("recommendation", models.CharField(max_length=255)), - ("other_detail", models.CharField(blank=True, max_length=255, null=True)), + ("recommendation", models.TextField(choices=[("SATISFIED", "SATISFIED")])), + ("other_detail", models.TextField(blank=True, null=True)), ("experienced_issue", models.JSONField(blank=True, null=True)), - ("helpful_guidance", models.CharField(blank=True, max_length=255, null=True)), - ("user_account_process", models.CharField(blank=True, max_length=255, null=True)), - ("service_improvements_feedback", models.CharField(blank=True, max_length=255, null=True)), + ( + "helpful_guidance", + models.TextField( + blank=True, + choices=[ + ("STRONGLY DISAGREE", "STRONGLY DISAGREE"), + ("DISAGREE", "DISAGREE"), + ("NEITHER AGREE NOR DISAGREE", "NEITHER AGREE NOR DISAGREE"), + ("AGREE", "AGREE"), + ("STRONGLY AGREE", "STRONGLY AGREE"), + ], + default="", + ), + ), + ( + "user_account_process", + models.TextField( + blank=True, + choices=[ + ("VERY DIFFICULT", "VERY DIFFICULT"), + ("DIFFICULT", "DIFFICULT"), + ("NEITHER DIFFICULT NOR EASY", "NEITHER DIFFICULT NOR EASY"), + ("EASY", "EASY"), + ("VERY EASY", "VERY EASY"), + ], + default="", + ), + ), + ("service_improvements_feedback", models.TextField(blank=True, null=True)), ], options={ "abstract": False, diff --git a/api/survey/models.py b/api/survey/models.py index 3d4181a5bb..cee33413a7 100644 --- a/api/survey/models.py +++ b/api/survey/models.py @@ -2,17 +2,20 @@ from django.db import models from api.common.models import TimestampableModel +from api.survey.enums import HelpfulGuidanceChoiceType, RecommendationChoiceType, UserAccountChoiceType # Create your models here. -class Survey(TimestampableModel): +class SurveyResponse(TimestampableModel): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_index=True) - recommendation = models.CharField(max_length=255) - other_detail = models.CharField(max_length=255, blank=True, null=True) + recommendation = models.TextField( + choices=RecommendationChoiceType.choices, + ) + other_detail = models.TextField(blank=True, null=True) experienced_issue = models.JSONField(blank=True, null=True) - helpful_guidance = models.CharField(max_length=255, blank=True, null=True) - user_account_process = models.CharField(max_length=255, blank=True, null=True) - service_improvements_feedback = models.CharField(max_length=255, blank=True, null=True) + helpful_guidance = models.TextField(choices=HelpfulGuidanceChoiceType.choices, blank=True, default="") + user_account_process = models.TextField(choices=UserAccountChoiceType.choices, blank=True, default="") + service_improvements_feedback = models.TextField(blank=True, null=True) def __str__(self): - return "Survey #{0} - {1}".format(self.id, self.recommendation) + return "SurveyResponse #{0} - {1}".format(self.id, self.recommendation) diff --git a/api/survey/serializers.py b/api/survey/serializers.py index 33dd932d79..c230f1288e 100644 --- a/api/survey/serializers.py +++ b/api/survey/serializers.py @@ -1,11 +1,11 @@ from rest_framework import serializers -from .models import Survey +from .models import SurveyResponse class SurveySerializer(serializers.ModelSerializer): class Meta: - model = Survey + model = SurveyResponse fields = "__all__" def to_representation(self, instance): diff --git a/api/survey/tests/test_crud.py b/api/survey/tests/test_crud.py index 49406aa5cb..5fcd7789f9 100644 --- a/api/survey/tests/test_crud.py +++ b/api/survey/tests/test_crud.py @@ -2,13 +2,14 @@ from rest_framework import status from test_helpers.clients import DataTestClient -from api.survey.models import Survey +from api.survey.models import SurveyResponse +from api.survey.enums import RecommendationChoiceType class SurveyCreateTests(DataTestClient): def setUp(self): super().setUp() - self.survey = Survey.objects.create( + self.survey = SurveyResponse.objects.create( recommendation="SATISFIED", ) @@ -22,7 +23,7 @@ def test_create_survey(self): response_data = response.json() self.assertEqual(response.status_code, status.HTTP_201_CREATED) - self.assertEqual(response_data["recommendation"], data["recommendation"]) + self.assertEqual(response_data["recommendation"], RecommendationChoiceType.SATISFIED) def test_update_survey(self): url = reverse("survey:surveys_update", kwargs={"pk": self.survey.id}) @@ -40,6 +41,6 @@ def test_update_survey(self): response.status_code, status.HTTP_200_OK, ) - survey_instance = Survey.objects.get(id=self.survey.id) + survey_instance = SurveyResponse.objects.get(id=self.survey.id) for field, expected_value in data.items(): assert getattr(survey_instance, field) == expected_value, f"Field {field} does not match." diff --git a/api/survey/urls.py b/api/survey/urls.py index f1c5b6c3fa..030ded3b37 100644 --- a/api/survey/urls.py +++ b/api/survey/urls.py @@ -1,11 +1,11 @@ from django.urls import path -from api.survey.views import SurveyListCreateAPIView, SurveyDetailUpdateAPIView +from api.survey.views import SurveyCreateAPIView, SurveyDetailUpdateAPIView app_name = "survey" urlpatterns = [ - path("", SurveyListCreateAPIView.as_view(), name="surveys"), + path("", SurveyCreateAPIView.as_view(), name="surveys"), path( "/", SurveyDetailUpdateAPIView.as_view(), diff --git a/api/survey/views.py b/api/survey/views.py index 7c0d2648ca..007eedd392 100644 --- a/api/survey/views.py +++ b/api/survey/views.py @@ -1,20 +1,20 @@ -from rest_framework.generics import ListCreateAPIView, RetrieveUpdateAPIView +from rest_framework.generics import CreateAPIView, RetrieveUpdateAPIView -from api.core.authentication import GovAuthentication, ExporterAuthentication -from api.survey.models import Survey +from api.core.authentication import ExporterAuthentication +from api.survey.models import SurveyResponse from api.survey.serializers import SurveySerializer from api.conf.pagination import MaxPageNumberPagination # Create your views here. -class SurveyListCreateAPIView(ListCreateAPIView): - authentication_classes = (GovAuthentication, ExporterAuthentication) - queryset = Survey.objects.all() +class SurveyCreateAPIView(CreateAPIView): + authentication_classes = (ExporterAuthentication,) + queryset = SurveyResponse.objects.all() serializer_class = SurveySerializer pagination_class = MaxPageNumberPagination class SurveyDetailUpdateAPIView(RetrieveUpdateAPIView): - authentication_classes = (GovAuthentication, ExporterAuthentication) - queryset = Survey.objects.all() + authentication_classes = (ExporterAuthentication,) + queryset = SurveyResponse.objects.all() serializer_class = SurveySerializer