def test_tag_things(self): client = APIClient() user = UserFactory() tag = TagFactory(user=user) thing = ThingFactory(user=user) thing.tags.add(tag) thing.save() thing = ThingFactory(user=user) thing.tags.add(tag) thing.save() ThingFactory(user=user) 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) ) ) tag_thing_url = reverse("api:thing-get-things-for-tags") query = "{0}?tag_id={1}".format(tag_thing_url, tag.pk) response = client.get(query) self.assertEqual(200, response.status_code) self.assertEqual('[{"id":1,"description":"Some Thing 1","place":null,"tags":[1]},{"id":2,"description":"Some Thing 2","place":null,"tags":[1]}]', response.content)
def test_retreive_with_place(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) thing.place = PlaceFactory(user=user) thing.save() thing_url = reverse("api:thing-detail", kwargs={"pk": thing.pk}) response = client.get(thing_url) self.assertEqual(200, response.status_code) self.assertEqual('{"id":1,"description":"Some Thing 1","place":1,"tags":[]}', response.content)