@@ -0,0 +1,2073 @@
+from django.contrib.auth.models import User%0Afrom django.urls import reverse%0Afrom rest_framework import status%0Afrom rest_framework.test import APITestCase%0A%0Afrom students.models import Student%0A%0A%0Aclass StudentAPITestCase(APITestCase):%0A    %22%22%22Test for student api%22%22%22%0A%0A    def setUp(self):%0A        User.objects.create_user(username='admin', password='test12345', email='admin@admin.com')%0A%0A        self.student = Student.objects.create(first_name='Michael', last_name='Jordan')%0A        self.data = %7B%0A            'first_name': 'John',%0A            'last_name': 'Snow'%0A        %7D%0A%0A    def test_students_list(self):%0A        %22%22%22Check if anonymous user can get a students list%22%22%22%0A%0A        url = reverse('student-list')%0A        response = self.client.get(url)%0A%0A        self.assertEqual(response.status_code, status.HTTP_200_OK)%0A        self.assertEqual(len(response.json()%5B'results'%5D), 1)%0A%0A    def test_get_student(self):%0A        %22%22%22Check if anonymous user can get a student detail%22%22%22%0A%0A        url = reverse('student-detail', args=%5Bself.student.pk%5D)%0A        self.client.login(username='admin', password='test12345')%0A        response = self.client.get(url)%0A%0A        self.assertEqual(response.status_code, status.HTTP_200_OK)%0A        self.assertEqual(response.json()%5B'first_name'%5D, 'Michael')%0A        self.assertEqual(response.json()%5B'last_name'%5D, 'Jordan')%0A%0A    def test_post_student_if_authenticated(self):%0A        %22%22%22Check if logged in user can add students%22%22%22%0A%0A        url = reverse('student-list')%0A        self.client.login(username='admin', password='test12345')%0A        response = self.client.post(url, self.data)%0A%0A        self.assertEqual(response.status_code, status.HTTP_201_CREATED)%0A        self.assertEqual(Student.objects.count(), 2)%0A%0A    def test_post_student_if_anonymous(self):%0A        %22%22%22Check if POST student returns 403 status if user is anonymous%22%22%22%0A%0A        url = reverse('student-list')%0A        response = self.client.post(url, self.data)%0A%0A        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)%0A        self.assertEqual(Student.objects.count(), 1)%0A

test for student api