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

def test_one_to_many(self):

    self.assertEqual(Person.objects.count(), 0)
    self.assertEqual(Company.objects.count(), 0)
    self.assertEqual(Product.objects.count(), 0)
    pr = PersonResource()
    data = {'name': 'Joan    Rivers', 'company': {'name': 'Yum    Yum    Pie    Factory!', 'products': [{'name': 'Tasty    Pie'}]}}
    request = MockRequest()
    request.GET = {'format': 'json'}
    request.method = 'POST'
    request.set_body(json.dumps(data))
    resp = pr.post_list(request)
    self.assertEqual(resp.status_code, 201)
    self.assertEqual(Person.objects.count(), 1)
    self.assertEqual(Company.objects.count(), 1)
    self.assertEqual(Product.objects.count(), 1)
    pk = Person.objects.all()[0].pk
    request = MockRequest()
    request.method = 'GET'
    resp = pr.get_detail(request, pk=pk)
    self.assertEqual(resp.status_code, 200)
    person = json.loads(resp.content.decode('utf-8'))
    self.assertEqual(person['name'], 'Joan    Rivers')
    company = person['company']
    self.assertEqual(company['name'], 'Yum    Yum    Pie    Factory!')
    self.assertEqual(len(company['products']), 1)
    product = company['products'][0]
    self.assertEqual(product['name'], 'Tasty    Pie')
    request = MockRequest()
    request.GET = {'format': 'json'}
    request.method = 'PUT'
    request.set_body(json.dumps(person))
    resp = pr.put_detail(request, pk=pk)
    self.assertEqual(resp.status_code, 204)
