[Answer]-Trouble adding/testing addition of an object to a ManyToMany relation in Django

1👍

✅

You have to send the user’s id.

This might work :

add_member_post = self.client.post(reverse('add_member',
                                 kwargs={'pk':station.pk}),
                         {'user':user2.id},
                         follow=True)

And check if the request actually worked :

self.assertEqual(add_member_post.status_code, 200)

0👍

station remains the instance you created inside the test, and is not affected by anything that happens in your view. You’d need to reload it from the database:

self.client.post(...)
station = Station.objects.get(pk=station.pk)
self.assertIn(...)

Leave a comment