Skip to content

Commit

Permalink
✅Add test for operations related bug on nested fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yezyilomo committed Jan 25, 2024
1 parent 6879e61 commit 05b2140
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
39 changes: 36 additions & 3 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@ def test_patch_with_update_operation_missing_one_required_nested_field(self):
}
)

def test_patch_on_deep_nested_fields(self):
def test_patch_with_mixed_operations(self):
url = reverse_lazy("wstudent-detail", args=[self.student.id])
data = {
"name": "yezy",
Expand All @@ -2544,7 +2544,34 @@ def test_patch_on_deep_nested_fields(self):
"name": "Programming",
"code": "CS50",
"books": {
"remove": [1]
"update": {
1: {
"title": "React Programming",
"author": "K.Kennedy",
"genres": {
# update_operations applies here since the parent is "update"
"remove": [],
"add": [],
"create": [
{"title": "Modern Programming", "description": "New tools"}
],
"update": {}
}
}
},
"create": [
{
"title": "CS Foundation",
"author": "T.Howard",
"genres": {
# create_operations applies here since the parent is "create"
"add": [],
"create": [
{"title": "Classical Programming", "description": "Classical tech tools"}
]
}
}
]
}
}
}
Expand All @@ -2557,7 +2584,13 @@ def test_patch_on_deep_nested_fields(self):
'course': {
'name': 'Programming', 'code': 'CS50',
'books': [
{'title': 'Basic Data Structures', 'author': 'S.Mobit', "genres": []}
{'title': 'React Programming', 'author': 'K.Kennedy', "genres": [
{"title": "Modern Programming", "description": "New tools"}
]},
{'title': 'Basic Data Structures', 'author': 'S.Mobit', 'genres': []},
{'title': 'CS Foundation', 'author': 'T.Howard', "genres": [
{"title": "Classical Programming", "description": "Classical tech tools"}
]}
],
'instructor': None
},
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Meta:

############### Serializers for Nested Data Mutation Testing ##############
class WritableBookSerializer(DynamicFieldsMixin, NestedModelSerializer):
genres = NestedField(GenreSerializer, many=True, required=False)
genres = NestedField(GenreSerializer, many=True, required=False, partial=False)

class Meta:
model = Book
Expand Down

0 comments on commit 05b2140

Please sign in to comment.