Answer the question
In order to leave comments, you need to log in
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'})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question