def test_invalid_delete_partner(self): request = self.factory.delete( reverse('partner-detail', args=(self.partner.pk, ))) request.user = factories.CoreUser(is_superuser=True, is_staff=True) response = PartnerViewSet.as_view({'delete': 'destroy'})(request, pk=12) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_create_valid_partner(self): data = { 'name': 'partner name', } request = self.factory.post(reverse('partner-list'), data, format='json') request.user = factories.CoreUser(is_superuser=True, is_staff=True) response = PartnerViewSet.as_view({'post': 'create'})(request) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_valid_update_partner(self): self.partner = Partner.objects.create(name='partner name') data = { 'name': 'partner name', } request = self.factory.put( reverse('partner-detail', args=(self.partner.pk, )), data) request.user = factories.CoreUser(is_superuser=True, is_staff=True) response = PartnerViewSet.as_view({'put': 'update'})(request, pk=self.partner.pk) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_invalid_single_partner(self): self.request.user = factories.CoreUser(is_superuser=True, is_staff=True) view = PartnerViewSet.as_view({'get': 'retrieve'}) response = view(self.request, pk=12) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_list_all_partner(self): self.request.user = factories.CoreUser(is_superuser=True, is_staff=True) view = PartnerViewSet.as_view({'get': 'list'}) response = view(self.request) self.assertEqual(response.status_code, 200)