def test_update_thing(self):
     client = APIClient()
     user = UserFactory()
     client.force_authenticate(
         user=user,
         token=AccessToken.objects.create(
             user=user,
             application=self.application,
             scope='read write',
             expires=datetime.datetime.now() + datetime.timedelta(days=1)
         )
     )
     thing = ThingFactory(user=user)
     self.assertNotEqual("new thing", thing.description)
     thing_url = reverse("api:thing-detail", kwargs={'pk': thing.pk})
     response = client.put(thing_url, {"description": "new thing"}, format='json')
     self.assertEqual(200, response.status_code)
     self.assertEqual('{"id":1,"description":"new thing","place":null,"tags":[]}', response.content)
     thing.refresh_from_db()
     self.assertEqual("new thing", thing.description)
 def test_update_thing_with_place_different_user(self):
     client = APIClient()
     user = UserFactory()
     user2 = UserFactory()
     client.force_authenticate(
         user=user,
         token=AccessToken.objects.create(
             user=user,
             application=self.application,
             scope='read write',
             expires=datetime.datetime.now() + datetime.timedelta(days=1)
         )
     )
     thing = ThingFactory(user=user)
     PlaceFactory(user=user2)
     self.assertIsNone(thing.place)
     thing_url = reverse("api:thing-detail", kwargs={'pk': thing.pk})
     response = client.put(thing_url, {"description": "new thing", "tags": [], "place": 1}, format='json')
     self.assertEqual(400, response.status_code)
     self.assertEqual('{"place":["Place does not belong to user"]}', response.content)
     thing.refresh_from_db()
     self.assertIsNone(thing.place)