'Make sure when something besides \'pk\' is used for detail_uri_name and
it isn\'t unique that we still look up the correct object and don\'t
create a duplicate.
Make sure this still works when used as a related resource.'

@skipIf((MyUUIDModel is None), u'UUIDField    not    available')
def test_patch_detail_with_m2m_non_unique_uuid_detail_uri_name(self):

    self.assertFalse(MyUUIDModel._meta.get_field(u'anotheruuid').unique)
    myuuidmodel = MyUUIDModel.objects.create()
    myrelateduuidmodel = MyRelatedUUIDModel.objects.create()
    myrelateduuidmodel.myuuidmodels.add(myuuidmodel)
    self.assertEqual(MyUUIDModel.objects.count(), 1)
    self.assertEqual(MyRelatedUUIDModel.objects.count(), 1)
    data = {u'myuuidmodels': [{u'content': u'foo', u'resource_uri': MyUUIDModelResourceNonUniqueDetailUriName().get_resource_uri(myuuidmodel)}, {u'content': u'bar', u'order': 1}]}
    request = MockRequest()
    request.GET = {u'format': u'json'}
    request.method = u'PUT'
    request.set_body(json.dumps(data))
    self.assertNotEqual(myuuidmodel.content, data[u'myuuidmodels'][0][u'content'])
    resource = MyRelatedUUIDModelResource()
    resp = resource.patch_detail(request, pk=myrelateduuidmodel.pk)
    self.assertEqual(resp.status_code, 202)
    self.assertEqual(MyUUIDModel.objects.count(), 2)
    self.assertEqual(MyRelatedUUIDModel.objects.count(), 1)
    myuuidmodel = MyUUIDModel.objects.get(pk=myuuidmodel.pk)
    self.assertEqual(myuuidmodel.content, data[u'myuuidmodels'][0][u'content'])
    resp_data = json.loads(resp.content.decode(u'utf-8'))
    self.assertEqual(resp_data[u'myuuidmodels'][0][u'id'], str(myuuidmodel.pk))
    self.assertEqual(resp_data[u'myuuidmodels'][0][u'anotheruuid'], str(myuuidmodel.anotheruuid))
    self.assertEqual(resp_data[u'myuuidmodels'][0][u'content'], data[u'myuuidmodels'][0][u'content'])
    self.assertEqual(resp_data[u'myuuidmodels'][1][u'content'], data[u'myuuidmodels'][1][u'content'])
