def test_insert(self): HOD.objects.all().delete() self.setup() old_count = HOD.objects.all().count() hod = HOD(departmentId=self.department, hod=self.professor) hod.save() new_count = HOD.objects.all().count() self.assertNotEqual(old_count, new_count)
def test_post_exists(self): HOD.objects.all().delete() self.setup() hod = HOD(departmentId=self.department, hod=self.professor) hod.save() data = {"departmentId": self.departmentId, "hod": self.professorId} response = self.client.post('/hod/', data) self.assertEqual( json.loads(response.content)['Status'], status.HTTP_409_CONFLICT)
def test_put_coflict(self): HOD.objects.all().delete() self.setup() departmentName = "EXTC" department = Department(departmentName=departmentName) department.save() hod = HOD(departmentId=department, hod=self.professor) hod.save() departmentId = Department.objects.get( departmentName='EXTC').departmentId data = {"departmentId": departmentId} response = self.client.put('/hod/%s/' % self.hodId, data, fomat='json') self.assertEqual( json.loads(response.content)['Status'], status.HTTP_409_CONFLICT)
class TestGet(APITestCase): def setup(self): departmentName = 'CSE' professerName = 'RKC' department = Department(departmentName=departmentName) department.save() department = Department.objects.get(departmentName=departmentName) self.department = department self.departmentId = department.departmentId professor = Professor(fname=professerName, lname=professerName, email='*****@*****.**', mobile='123456789', city='nanded', state='maha', department=self.department) professor.save() professor = Professor.objects.get(fname=professerName) self.professor = professor self.hod = HOD(departmentId=self.department, hod=self.professor) self.hod.save() self.hodId = HOD.objects.get(departmentId=self.departmentId).hodId def test_get(self): HOD.objects.all().delete() self.setup() response = self.client.get('/hod/') self.assertEqual( json.loads(response.content)['Status'], status.HTTP_200_OK) def test_get_by_id(self): HOD.objects.all().delete() self.setup() response = self.client.get('/hod/%s/' % self.hodId) self.assertEqual( json.loads(response.content)['Status'], status.HTTP_200_OK) def test_get_by_id_not_found(self): HOD.objects.all().delete() self.setup() id = int(self.hodId) + 1 response = self.client.get('/hod/%s/' % id) self.assertEqual( json.loads(response.content)['Status'], status.HTTP_404_NOT_FOUND)
def setup(self): departmentName = 'CSE' professerName = 'RKC' department = Department(departmentName=departmentName) department.save() department = Department.objects.get(departmentName=departmentName) self.department = department self.departmentId = department.departmentId professor = Professor(fname=professerName, lname=professerName, email='*****@*****.**', mobile='123456789', city='nanded', state='maha', department=self.department) professor.save() professor = Professor.objects.get(fname=professerName) self.professor = professor self.hod = HOD(departmentId=self.department, hod=self.professor) self.hod.save() self.hodId = HOD.objects.get(departmentId=self.departmentId).hodId
class TestPUT(APITestCase): def setup(self): departmentName = 'CSE' professerName = 'RKC' department = Department(departmentName=departmentName) department.save() department = Department.objects.get(departmentName=departmentName) self.department = department self.departmentId = department.departmentId professor = Professor(fname=professerName, lname=professerName, email='*****@*****.**', mobile='123456789', city='nanded', state='maha', department=self.department) professor.save() professor = Professor.objects.get(fname=professerName) self.professor = professor self.hod = HOD(departmentId=self.department, hod=self.professor) self.hod.save() self.hodId = HOD.objects.get(departmentId=self.departmentId).hodId def test_put(self): HOD.objects.all().delete() self.setup() department = Department(departmentName='EXTC') department.save() departmentId = Department.objects.get( departmentName='EXTC').departmentId data = {"departmentId": departmentId} response = self.client.put('/hod/%s/' % self.hodId, data) self.assertEqual( json.loads(response.content)['Status'], status.HTTP_201_CREATED) def test_put_coflict(self): HOD.objects.all().delete() self.setup() departmentName = "EXTC" department = Department(departmentName=departmentName) department.save() hod = HOD(departmentId=department, hod=self.professor) hod.save() departmentId = Department.objects.get( departmentName='EXTC').departmentId data = {"departmentId": departmentId} response = self.client.put('/hod/%s/' % self.hodId, data, fomat='json') self.assertEqual( json.loads(response.content)['Status'], status.HTTP_409_CONFLICT) def test_put_not_found(self): HOD.objects.all().delete() self.setup() id = int(self.hodId) + 1 departmentName = "EXTC" department = Department(departmentName=departmentName) department.save() departmentId = Department.objects.get( departmentName='EXTC').departmentId data = {"departmentId": departmentId} response = self.client.put('/hod/%s/' % id, data) self.assertEqual( json.loads(response.content)['Status'], status.HTTP_404_NOT_FOUND)