from . models import Employee from rest_framework.test import APIClient from rest_framework.test import APITestCase from rest_framework import status class EmployeeTestCase(APITestCase): def setUp(self): self.client = APIClient() self.data = { "name": "Erős István", "city": "Szeged", "salary": 395 } self.url = "/employees" def test_create_employee(self): data = self.data response = self.client.post(self.url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertTrue(Employee.objects.count() > 0) def test_create_employee_without_name(self): data = self.data data["name"] = "" response = self.client.post(self.url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)