def test_api_can_update_bucketlist(self): #Test the api can update a given bucketlist change_bucketlist = {'name': 'Something new'} res = self.client.put(reverse('details', kwargs={'pk': bucketlist.id}), change_bucketlist, format="json") self.assertEqual(res.status_code, status.HTTP_200_OK)
def test_api_can_get_a_bucketlist(self): bucketlist = BucketList.objects.get() response = self.client.get(reverse('details', kwargs={'pk': bucketlist.id}), format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertContains(response, bucketlist)
def setUp(self): #define the test client and other test variables self.client = APIClient() self.bucketlist_data = {'name': 'Go to Ibiza'} self.response = self.client.post(reverse('create'), self.bucketlist_data, format="json")
def test_api_can_delete_bucketlist(self): #Api can delete a bucketlist bucketlist = BucketList.objects.get() response = self.client.delete(reverse('details', kwars={'pk': bucketlist.id}), format="json", follow=True) self.assertEquals(response.status_code, status.HTTP_204_NO_CONTENT)
def setUp(self): #Define the test client and other test variables user = User.objects.create(user=user) #Initialize client and force it to use authentication self.client = APIClient() self.client.force_authenticate(user=user) #User model it's not serializable, so we use the ID/PK self.bucketlist_data = {'name': 'Go to ibiza', 'owner': user.id} self.response = self.client.post(reverse('create'), self.bucketlist_data, format="json")
def setUp(self): super(ProductTests, self).setUp() app = "shop" model = "product" self.url = reverse("admin:%s_%s_add" % (app, model)) self.product = Product.objects.create()
def test_home(self): url = reverse('index') response = self.client.get(url) self.assertEquals(response.status_code, 200)