|  | 
| 2 | 2 | 
 | 
| 3 | 3 | from django.test import RequestFactory, override_settings | 
| 4 | 4 | from django.utils import timezone | 
|  | 5 | +from rest_framework import status | 
| 5 | 6 | from rest_framework.exceptions import NotFound | 
| 6 | 7 | from rest_framework.request import Request | 
| 7 | 8 | from rest_framework.reverse import reverse | 
| @@ -174,16 +175,30 @@ def test_patch_one_to_many_relationship(self): | 
| 174 | 175 |         response = self.client.get(url) | 
| 175 | 176 |         assert response.data == request_data["data"] | 
| 176 | 177 | 
 | 
| 177 |  | -    def test_patch_one_to_many_relaitonship_with_none(self): | 
|  | 178 | +    def test_patch_one_to_many_relaitonship_with_empty(self): | 
| 178 | 179 |         url = f"/blogs/{self.first_entry.id}/relationships/entry_set" | 
| 179 |  | -        request_data = {"data": None} | 
|  | 180 | + | 
|  | 181 | +        request_data = {"data": []} | 
| 180 | 182 |         response = self.client.patch(url, data=request_data) | 
| 181 |  | -        assert response.status_code == 200, response.content.decode() | 
|  | 183 | +        assert response.status_code == status.HTTP_200_OK | 
| 182 | 184 |         assert response.data == [] | 
| 183 | 185 | 
 | 
| 184 | 186 |         response = self.client.get(url) | 
| 185 | 187 |         assert response.data == [] | 
| 186 | 188 | 
 | 
|  | 189 | +    def test_patch_one_to_many_relaitonship_with_none(self): | 
|  | 190 | +        """ | 
|  | 191 | +        None for a to many relationship is invalid and should return a request error. | 
|  | 192 | +
 | 
|  | 193 | +        see https://jsonapi.org/format/#crud-updating-to-many-relationships | 
|  | 194 | +        """ | 
|  | 195 | + | 
|  | 196 | +        url = f"/blogs/{self.first_entry.id}/relationships/entry_set" | 
|  | 197 | + | 
|  | 198 | +        request_data = {"data": None} | 
|  | 199 | +        response = self.client.patch(url, data=request_data) | 
|  | 200 | +        assert response.status_code == status.HTTP_400_BAD_REQUEST | 
|  | 201 | + | 
| 187 | 202 |     def test_patch_many_to_many_relationship(self): | 
| 188 | 203 |         url = f"/entries/{self.first_entry.id}/relationships/authors" | 
| 189 | 204 |         request_data = { | 
|  | 
0 commit comments