A
A
Antigo_ptz2016-11-03 14:21:25
Django
Antigo_ptz, 2016-11-03 14:21:25

Django Rest Framework not creating model tables in test DB?

Wrote a test for adding and getting a model.

class PatientTests(APITestCase):

    def test_create_patient(self):
        url = reverse('patient-list')
        data = {'firstname': 'ivan', 'lastname': 'ivanov'}
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Patient.objects.count(), 1)
        self.assertEqual(Patient.objects.get().firstname, 'ivan')

    def test_get_patient(self):
        url = reverse('patient-detail', args=[1])
        response = self.client.get(url)
        self.assertEqual(response.data, {'firstname': 'ivan'})

I launch, as a result:
In the console, the creation of a test database passes, then the error django.db.utils.ProgrammingError: relation "patient" does not exist falls. How to overcome this problem? I so understand in a test DB which in storage the given table is not created?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question