Skip to content

Commit

Permalink
Updates to model with choices and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
seijihg committed Feb 12, 2024
1 parent 825c9ab commit 2649680
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 30 deletions.
38 changes: 38 additions & 0 deletions api/survey/enums.py
Original file line number Diff line number Diff line change
@@ -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"),
]
40 changes: 33 additions & 7 deletions api/survey/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,7 +14,7 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="Survey",
name="SurveyResponse",
fields=[
(
"created_at",
Expand All @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions api/survey/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions api/survey/serializers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
9 changes: 5 additions & 4 deletions api/survey/tests/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand All @@ -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})
Expand All @@ -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."
4 changes: 2 additions & 2 deletions api/survey/urls.py
Original file line number Diff line number Diff line change
@@ -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(
"<uuid:pk>/",
SurveyDetailUpdateAPIView.as_view(),
Expand Down
16 changes: 8 additions & 8 deletions api/survey/views.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2649680

Please sign in to comment.