def test_user_like_product(self): client = Client() client._login(self.user, 'django.contrib.auth.backends.ModelBackend') self.assertEquals(self.product_1.likes.count(), 0) response = client.post(self.url_like, {'change_like': self.product_1.slug}) self.assertEquals(self.product_1.likes.count(), 1) self.assertEquals(response.status_code, 302)
class TestCoupleActions(DataSetuoMixin, TestCase): fixtures = ['brands', 'prods'] def setUp(self) -> None: self.client = Client() self.usr = get_user_model().objects.get(username='******') self.wedding = GiftList.objects.get(user=self.usr, active=True) self.client._login(self.usr) # self.client.login(username='******', # password='******') def test_add_gift(self): self.assertEqual( GiftListItem.objects.filter(gift_list=self.wedding).count(), 0) resp = self.client.generic('POST', reverse('api-gift'), '{"product_id": 12}') self.assertEqual(resp.status_code, 200) self.assertEqual( GiftListItem.objects.filter(gift_list=self.wedding).count(), 1) def test_add_gift_unauthorised(self): self.client.logout() resp = self.client.generic('POST', reverse('api-gift'), '{"product_id": 12}') self.assertEqual(resp.status_code, 401) self.assertEqual( GiftListItem.objects.filter(gift_list=self.wedding).count(), 0) def add_gift(self): item = GiftListItem(gift_list=self.wedding, qty=1, added_by=self.usr, product_id=11) item.save() def test_remove_gift(self): self.add_gift() item = GiftListItem.objects.filter(gift_list=self.wedding).first() resp = self.client.delete( reverse('api-gift-item', kwargs=dict(item_id=item.pk))) self.assertEqual(resp.status_code, 200) self.assertEqual( GiftListItem.objects.filter(gift_list=self.wedding, ).count(), 0) def test_remove_gift_unauthorised(self): self.client.logout() self.add_gift() item = GiftListItem.objects.filter(gift_list=self.wedding).first() resp = self.client.delete( reverse('api-gift-item', kwargs=dict(item_id=item.pk))) self.assertEqual(resp.status_code, 401) self.assertEqual( GiftListItem.objects.filter(gift_list=self.wedding, ).count(), 1)
def test_user_comment(self): client = Client() client._login(self.user, 'django.contrib.auth.backends.ModelBackend') self.assertEquals(self.product_1.comments.count(), 0) response = client.post( self.url_comment, { 'username_comment': self.user.username, 'comment_message': 'test_message', 'add_comment': self.product_1.slug }) self.assertEquals(response.status_code, 302) self.assertEquals(self.product_1.comments.count(), 1)
def test_user_detail_page(self): client = Client() client._login(self.user, 'django.contrib.auth.backends.ModelBackend') response = client.get(self.url) self.assertEquals(response.status_code, 200)