mercredi 24 juin 2020

django rest framework test code self.client.delete problem

'''
from rest_framework import status, response
from rest_framework.test import APITestCase
from lots.models import Lot


class LotsTestCase(APITestCase):
    def setUp(self) -> None:
        self.lot = Lot.objects.create(name="1",
                                      address="Dont Know",
                                      phone_num="010-4451-2211",
                                      latitude=127.12,
                                      longitude=352.123,
                                      basic_rate=20000,
                                      additional_rate=2000,
                                      partnership=False,
                                      section_count=3,)

    def test_delete(self):
        response = self.client.delete(f'api/lots/{self.lot["name"]}')
        # response = self.client.delete(f'/api/users/{self.users[0].pk}')
        # url = reverse(f'/api/lots/{self.lot}', kwargs={'pk': self.lot.pk})
        # self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(self.lot.objects.filter(pk=self.lot.pk.count()))

'''

i am having problems with the test code above. why isn't this working, I know it has to do with calling dictionary values but i just can't seem to figure it out. Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire