def test_get_invalid_single_user(self):
     """Test the api get invalid single course."""
     # Setup.
     url = "/courses/" + str(self.invalid_pk)
     request = self.factory.get(url)
     # Run.
     course_detail = CourseViewSet.as_view({'get': 'retrieve'})
     response = course_detail(request, pk=self.invalid_pk)
     # Check.
     self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
 def test_delete_valid_single_course(self):
     """Test the api valid delete new course."""
     # Setup.
     url = "/courses/" + str(self.invalid_pk)
     request = self.factory.delete(url)
     # Run.
     course_detail = CourseViewSet.as_view({'delete': 'destroy'})
     response = course_detail(request, pk=self.invalid_pk)
     # Check.
     self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
 def test_create_invalid_single_user(self):
     """Test the api invalid insert new course."""
     # Setup.
     url = "/courses/"
     request = self.factory.post(url, self.invalid_payload, format='json')
     # Run.
     course_list = CourseViewSet.as_view({'post': 'create'})
     response = course_list(request)
     # Check.
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_get_valid_single_course(self):
     """Test the api get valid single course."""
     # Setup.
     url = "/courses/" + str(self.newCourse1.pk)
     request = self.factory.get(url)
     serializer = CourseSerializer(self.newCourse1)
     # Run.
     course_detail = CourseViewSet.as_view({'get': 'retrieve'})
     response = course_detail(request, pk=self.newCourse1.pk)
     # Check.
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data, serializer.data)
 def test_get_all_courses(self):
     """Test the api get courses."""
     # Setup.
     url = "/courses/"
     request = self.factory.get(url)
     courses = Course.objects.all()
     serializer = CourseSerializer(courses, many=True)
     # Run.
     course_list = CourseViewSet.as_view({'get': 'list'})
     response = course_list(request)
     # Check.
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['results'], serializer.data)