File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -303,6 +303,7 @@ class EpisodeWriteSerializer(ModelSerializer):
303303 write_only = True , many = True , queryset = MedicalPersonnel .objects .all ()
304304 )
305305 episode_type = CharField ()
306+ comments = CharField (required = False )
306307 cepod = CharField ()
307308 side = CharField ()
308309 occurence = CharField ()
@@ -362,7 +363,7 @@ def create(self, validated_data):
362363 Episode .EpisodeChoices .choices ,
363364 validated_data ["episode_type" ],
364365 ),
365- comments = validated_data [ "comments" ] ,
366+ comments = validated_data . get ( "comments" , "" ) ,
366367 cepod = get_text_choice_value_from_label (
367368 Episode .CepodChoices .choices , validated_data ["cepod" ]
368369 ),
Original file line number Diff line number Diff line change @@ -176,3 +176,14 @@ def test_create_episode_successful(self):
176176 Episode .AnaestheticChoices .choices , data ["anaesthetic_type" ]
177177 ),
178178 )
179+
180+ def test_create_successful_without_optional_fields (self ):
181+ data = self .get_episode_test_data ()
182+ data .pop ("comments" )
183+ response = self .client .post (
184+ "/api/v1/episodes/" , data = data , format = "json"
185+ )
186+
187+ self .assertEqual (HTTP_201_CREATED , response .status_code )
188+
189+ self .assertEqual (response .data ["comments" ], "" )
You can’t perform that action at this time.
0 commit comments