From 2a08fd0fabfb2441437e69ec7eac2b545a5e7346 Mon Sep 17 00:00:00 2001 From: Zamil Majdy <z.majdy1996@gmail.com> Date: Mon, 24 Apr 2017 16:00:55 +0700 Subject: [PATCH] [#140652771] [#21] [Refactor] move unused testcases add miss coverage test --- core/tests/test_studentViewSet.py | 18 ----------- core/tests/test_userViewSet.py | 52 +++++++++++++++++++++++++++---- core/tests/test_vacancies.py | 2 +- 3 files changed, 47 insertions(+), 25 deletions(-) delete mode 100644 core/tests/test_studentViewSet.py diff --git a/core/tests/test_studentViewSet.py b/core/tests/test_studentViewSet.py deleted file mode 100644 index efd3f413..00000000 --- a/core/tests/test_studentViewSet.py +++ /dev/null @@ -1,18 +0,0 @@ -# from unittest import TestCase -# -# from django.urls import reverse -# -# -# class TestStudentViewSet(TestCase): -# # def setUp(self): -# # #c = Client() -# # Student.objects.create(user = User.objects.create(username = "farhan"), npm = "1406572321") -# -# #def test_bookmark_vacancies(self): -# # url = reverse('bookmarked-vacancies') -# # data = {'company_id': 1} -# # response = self.client.post(url, data, format='json') -# # self.fail() -# # -# # def test_remove_vacancies(self): -# # self.fail() diff --git a/core/tests/test_userViewSet.py b/core/tests/test_userViewSet.py index 5a782206..ad2179c8 100644 --- a/core/tests/test_userViewSet.py +++ b/core/tests/test_userViewSet.py @@ -1,6 +1,46 @@ -# from unittest import TestCase -# -# -# class TestUserViewSet(TestCase): -# def test_me(self): -# self.fail() +from django.contrib.auth.models import User +from rest_framework import status +from rest_framework.test import APITestCase + + +class TestUserViewSet(APITestCase): + def test_me_success(self): + superuser = User.objects.create_superuser('dummy.user', 'dummy.user@user.com', 'lalala123') + self.client.force_authenticate(user=superuser) + + url = '/api/users/me/' + response = self.client.get(url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_users_fail(self): + url = '/api/users/' + response = self.client.get(url, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + response = self.client.put(url, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + response = self.client.patch(url, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_user_students_success(self): + superuser = User.objects.create_superuser('dummy.user', 'dummy.user@user.com', 'lalala123') + self.client.force_authenticate(user=superuser) + + url = '/api/students/' + response = self.client.get(url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_user_students_fail(self): + url = '/api/students/' + response = self.client.get(url, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + response = self.client.post(url, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + response = self.client.put(url, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + response = self.client.patch(url, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) diff --git a/core/tests/test_vacancies.py b/core/tests/test_vacancies.py index a4195f02..b8c7267f 100644 --- a/core/tests/test_vacancies.py +++ b/core/tests/test_vacancies.py @@ -3,7 +3,7 @@ from datetime import datetime import requests_mock from django.contrib.auth.models import User from rest_framework import status -from rest_framework.test import APITestCase, force_authenticate, APIRequestFactory +from rest_framework.test import APITestCase from core.models.accounts import Company from core.models.vacancies import Vacancy -- GitLab