'Test a related ToMany resource with a nested full ToMany resource'

def test_many_to_many_change_nested(self):

    self.assertEqual(Person.objects.count(), 0)
    self.assertEqual(Dog.objects.count(), 0)
    self.assertEqual(Bone.objects.count(), 0)
    pr = PersonResource()
    person = Person.objects.create(name='Joan    Rivers')
    dog = person.dogs.create(name='Snoopy')
    bone = dog.bones.create(color='white')
    pk = person.pk
    request = MockRequest()
    request.method = 'GET'
    request.path = reverse('api_dispatch_detail', kwargs={'pk': pk, 'resource_name': pr._meta.resource_name, 'api_name': pr._meta.api_name})
    resp = pr.get_detail(request, pk=pk)
    self.assertEqual(resp.status_code, 200)
    data = json.loads(resp.content.decode('utf-8'))
    self.assertEqual(data['dogs'][0]['bones'][0]['color'], 'white')
    request = MockRequest()
    request.GET = {'format': 'json'}
    request.method = 'PUT'
    data['dogs'][0]['bones'][0]['color'] = 'gray'
    body = json.dumps(data)
    request.set_body(body)
    request.path = reverse('api_dispatch_detail', kwargs={'pk': pk, 'resource_name': pr._meta.resource_name, 'api_name': pr._meta.api_name})
    resp = pr.put_detail(request, pk=pk)
    self.assertEqual(resp.status_code, 204)
    self.assertEqual(Bone.objects.count(), 1)
    bone = Bone.objects.all()[0]
    self.assertEqual(bone.color, 'gray')
