From c91d4eae214ea63ced9f07ca700281e84538893b Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Fri, 12 Apr 2024 19:30:11 +0200 Subject: [PATCH 1/8] Feat: Tests for Educator and CenterExit CRUD --- nexong/api/Authentication/tests.py | 99 +++++++++++++++++++++ nexong/api/CenterExit/__init__.py | 0 nexong/api/CenterExit/tests.py | 134 +++++++++++++++++++++++++++++ nexong/api/Evaluation/test.py | 0 nexong/api/Lesson/tests.py | 0 nexong/api/Student/tests.py | 0 6 files changed, 233 insertions(+) create mode 100644 nexong/api/Authentication/tests.py create mode 100644 nexong/api/CenterExit/__init__.py create mode 100644 nexong/api/CenterExit/tests.py create mode 100644 nexong/api/Evaluation/test.py create mode 100644 nexong/api/Lesson/tests.py create mode 100644 nexong/api/Student/tests.py diff --git a/nexong/api/Authentication/tests.py b/nexong/api/Authentication/tests.py new file mode 100644 index 00000000..7f0a46f7 --- /dev/null +++ b/nexong/api/Authentication/tests.py @@ -0,0 +1,99 @@ +from rest_framework.exceptions import ValidationError +from nexong.api.Authentication.views import * +from nexong.models import * +from rest_framework.authtoken.models import Token +from rest_framework.test import APIRequestFactory +from rest_framework.test import APITestCase +from rest_framework import status + + + +class EducatorApiViewSetTestCase(APITestCase): + def setUp(self): + self.factory = APIRequestFactory() + self.educator_data = { + "description": "Test description", + "birthdate": "1969-06-09", + + } + self.educator_error_desc = { + "description": "", + "birthdate": "1969-06-09", + } + self.educator_error_date = { + "description": "Test description", + "birthdate": "2069-06-09", + } + self.user = User.objects.create( + username="testuser", email="example@gmail.com", role=ADMIN + ) + self.token = Token.objects.create(user=self.user) + + def test_create_educator(self): + serializerE1 = EducatorSerializer(data = self.educator_error_desc) + serializerE2 = EducatorSerializer(data = self.educator_error_date) + + response_error = self.client.post( + "/api/educator/", + self.educator_error_date, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response_error.status_code, status.HTTP_400_BAD_REQUEST) + + with self.assertRaises(ValidationError) as context1: + serializerE1.is_valid(raise_exception=True) + self.assertEqual(context1.exception.detail["description"][0], "This field may not be blank.") + + with self.assertRaises(ValidationError) as context2: + serializerE2.is_valid(raise_exception=True) + self.assertEqual(context2.exception.detail["non_field_errors"][0], "Birthdate can't be greater than today") + + response = self.client.post( + "/api/educator/", + self.educator_data, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(Educator.objects.count(), 1) + self.assertEqual(Educator.objects.get().description, "Test description") + self.assertEqual(Educator.objects.get().birthdate, datetime.date(1969, 6, 9)) + + def test_retrieve_educator(self): + educator = Educator.objects.create(**self.educator_data) + response = self.client.get( + f"/api/educator/{educator.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["description"], "Test description") + self.assertEqual(response.data["birthdate"], "1969-06-09") + + + def test_update_educator(self): + educator = Educator.objects.create(**self.educator_data) + self.educator_data["description"] = "Updated description" + self.educator_data["birthdate"] = "1970-07-10" + response = self.client.put( + f"/api/educator/{educator.id}/", + self.educator_data, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual( + Educator.objects.get().description, "Updated description" + ) + self.assertEqual( + Educator.objects.get().birthdate, datetime.date(1970, 7, 10) + ) + + + def test_delete_educator(self): + educator = Educator.objects.create(**self.educator_data) + response = self.client.delete( + f"/api/educator/{educator.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + self.assertEqual(Educator.objects.count(), 0) \ No newline at end of file diff --git a/nexong/api/CenterExit/__init__.py b/nexong/api/CenterExit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/nexong/api/CenterExit/tests.py b/nexong/api/CenterExit/tests.py new file mode 100644 index 00000000..bb0d5f16 --- /dev/null +++ b/nexong/api/CenterExit/tests.py @@ -0,0 +1,134 @@ +from rest_framework.exceptions import ValidationError +from nexong.api.Authentication.views import * +from nexong.models import * +from rest_framework.authtoken.models import Token +from rest_framework.test import APIRequestFactory +from rest_framework.test import APITestCase +from rest_framework import status +from django.core.files.uploadedfile import SimpleUploadedFile + +class EducatorCenterExitApiViewSetTestCase(APITestCase): + def setUp(self): + self.family = Family.objects.create(name="Los Pedraz") + self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.factory = APIRequestFactory() + self.user = User.objects.create( + username="testuser", + email="example@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + #self.user2 = User.objects.create( + # username="testuser2", email="example2@gmail.com", role=ADMIN + #) + self.token = Token.objects.create(user=self.user) + #self.token2 = Token.objects.create(user=self.user2) + self.educator2 = Educator.objects.create(birthdate="2000-04-21") + self.educator3 = Educator.objects.create(birthdate="2000-04-22") + self.education_center = EducationCenter.objects.create( + name="San Francisco Solano" + ) + self.voluntario = Volunteer.objects.create( + academic_formation="Prueba Voluntario", + motivation="Test voluntario", + status="ACEPTADO", + address="Test voluntario address", + postal_code=12359, + birthdate="1956-07-05", + start_date="1955-07-05", + end_date="1956-07-05", + ) + self.voluntario2 = Volunteer.objects.create( + academic_formation="Test vol2", + motivation="Test vol", + status="ACEPTADO", + address="Test advol", + postal_code=12356, + birthdate="1956-07-05", + start_date="1956-07-05", + end_date="1956-07-05", + ) + self.student = Student.objects.create( + name="Amadeo", + surname="Portillo", + education_center=self.education_center, + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="TRES AÑOS", + education_center_tutor="Don Carlos Perez", + nationality="Alemania", + birthdate="2015-04-21", + family=self.family, + ) + self.student2 = Student.objects.create( + name="Pablo", + surname="Portillo", + education_center=self.education_center, + is_morning_student=False, + activities_during_exit="", + status="ACEPTADO", + current_education_year="TRES AÑOS", + education_center_tutor="Don Carlos Perez", + nationality="Alemania", + birthdate="2015-06-21", + family=self.family, + ) + self.lesson = Lesson.objects.create( + name="PRIMER Materia", + description="Módulo C, segunda planta", + capacity=50, + is_morning_lesson=True, + educator=self.educator, + start_date="2024-01-28", + end_date="2024-05-28", + ) + self.lesson_event = LessonEvent.objects.create( + name="Excursión a La Giralda", + description="Vamos al centro a ver La Giralda", + place="Centro Sevilla", + price=25, + max_volunteers=10, + start_date="2024-04-18 12:00-00:00", + end_date="2024-04-18 18:00-00:00", + lesson=self.lesson, + ) + self.lesson_event.educators.add(self.educator2, self.educator3) + self.lesson_event.attendees.add(self.student, self.student2) + self.lesson_event.volunteers.add(self.voluntario, self.voluntario2) + + self.center_exit = { + "student": self.student, + "is_authorized": True, + "lesson_event": self.lesson_event, + } + file_content = b"Test file content" + self.center_exit["authorization"] = SimpleUploadedFile( + "centerexit_authorization.pdf", file_content + ) + + def test_create_center_exit_by_educator(self): + response = self.client.post( + "/api/center-exit/", + self.center_exit, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_obtain_center_authorization_by_educator(self): + center_exit = CenterExitAuthorization.objects.create(**self.center_exit) + response = self.client.get( + f"/api/center-exit/{center_exit.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(center_exit.is_authorized, True) + + def test_delete_center_authorization_by_educator(self): + center_exit = CenterExitAuthorization.objects.create(**self.center_exit) + response = self.client.delete( + f"/api/center-exit/{center_exit.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file diff --git a/nexong/api/Evaluation/test.py b/nexong/api/Evaluation/test.py new file mode 100644 index 00000000..e69de29b diff --git a/nexong/api/Lesson/tests.py b/nexong/api/Lesson/tests.py new file mode 100644 index 00000000..e69de29b diff --git a/nexong/api/Student/tests.py b/nexong/api/Student/tests.py new file mode 100644 index 00000000..e69de29b From 27c8115515bdb7e06fb208ea4bf0405c36ea84b0 Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Wed, 17 Apr 2024 00:54:58 +0200 Subject: [PATCH 2/8] Feat: test for all educator interactions --- nexong/api/CenterExit/tests.py | 15 +- nexong/api/Evaluation/__init__.py | 0 nexong/api/Evaluation/test.py | 325 ++++++++++++++++++++++++++++++ nexong/api/Lesson/tests.py | 178 ++++++++++++++++ nexong/api/Student/__init__.py | 0 nexong/api/Student/tests.py | 152 ++++++++++++++ 6 files changed, 665 insertions(+), 5 deletions(-) create mode 100644 nexong/api/Evaluation/__init__.py create mode 100644 nexong/api/Student/__init__.py diff --git a/nexong/api/CenterExit/tests.py b/nexong/api/CenterExit/tests.py index bb0d5f16..231cb3b1 100644 --- a/nexong/api/CenterExit/tests.py +++ b/nexong/api/CenterExit/tests.py @@ -1,4 +1,3 @@ -from rest_framework.exceptions import ValidationError from nexong.api.Authentication.views import * from nexong.models import * from rest_framework.authtoken.models import Token @@ -18,11 +17,7 @@ def setUp(self): role=EDUCATOR, educator=self.educator, ) - #self.user2 = User.objects.create( - # username="testuser2", email="example2@gmail.com", role=ADMIN - #) self.token = Token.objects.create(user=self.user) - #self.token2 = Token.objects.create(user=self.user2) self.educator2 = Educator.objects.create(birthdate="2000-04-21") self.educator3 = Educator.objects.create(birthdate="2000-04-22") self.education_center = EducationCenter.objects.create( @@ -125,6 +120,16 @@ def test_obtain_center_authorization_by_educator(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(center_exit.is_authorized, True) + def test_update_center_authorization_by_educator(self): + center_exit = CenterExitAuthorization.objects.create(**self.center_exit) + self.center_exit["is_authorized"] = False + response = self.client.put( + f"/api/center-exit/{center_exit.id}/", + self.center_exit, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + def test_delete_center_authorization_by_educator(self): center_exit = CenterExitAuthorization.objects.create(**self.center_exit) response = self.client.delete( diff --git a/nexong/api/Evaluation/__init__.py b/nexong/api/Evaluation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/nexong/api/Evaluation/test.py b/nexong/api/Evaluation/test.py index e69de29b..63e8feea 100644 --- a/nexong/api/Evaluation/test.py +++ b/nexong/api/Evaluation/test.py @@ -0,0 +1,325 @@ +from nexong.api.Authentication.views import * +from nexong.models import * +from rest_framework.authtoken.models import Token +from rest_framework.test import APIRequestFactory +from rest_framework.test import APITestCase +from rest_framework import status + +class EducatorEvaluationTypeTestCase(APITestCase): + def setUp(self): + self.family = Family.objects.create(name="Los Pedraz") + self.educator = Educator.objects.create(description="Profesor de lengua", birthdate="1969-04-21") + self.educator2 = Educator.objects.create(description="Profesor de mates", birthdate="1998-04-21") + + self.factory = APIRequestFactory() + self.user = User.objects.create( + username="testuser", + email="example@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + self.token = Token.objects.create(user=self.user) + self.student = Student.objects.create( + name="Amadeo", + surname="Portillo", + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="TRES AÑOS", + education_center_tutor="Don Carlos Perez", + nationality="Aleman", + birthdate="2015-04-21", + family=self.family, + ) + self.lesson = Lesson.objects.create( + name="PRIMER Materia", + description="Módulo C, segunda planta", + capacity=50, + is_morning_lesson=True, + educator=self.educator, + start_date="2024-01-28", + end_date="2024-05-28", + ) + self.lesson2 = Lesson.objects.create( + name="Segunda Materia", + description="Módulo B, segunda planta", + capacity=50, + is_morning_lesson=True, + educator=self.educator2, + start_date="2024-01-28", + end_date="2024-05-28", + ) + self.evaluation_type_data = { + "name" : "Asistencia", + "description" : "asitencia diaria", + "evaluation_type" : "DIARIO", + "grade_system" : "CERO A UNO", + "lesson" : self.lesson, + } + self.evaluation_type_data_forbiden = { + "name" : "Asistencia", + "description" : "asitencia diaria", + "evaluation_type" : "DIARIO", + "grade_system" : "CERO A UNO", + "lesson" : self.lesson2, + } + self.evaluation_type_data_bad_request = { + "name" : "", + "description" : "asitencia diaria", + "evaluation_type" : "DIARIO", + "grade_system" : "CERO A UNO", + "lesson" : self.lesson, + } + + + def test_create_evaluation_type_by_educator(self): + self.evaluation_type_data["lesson"] = self.lesson.id + self.evaluation_type_data_bad_request["lesson"] = self.lesson.id + response = self.client.post( + "/api/evaluation-type/", + self.evaluation_type_data, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + + response2 = self.client.post( + "/api/evaluation-type/", + self.evaluation_type_data_bad_request, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response2.status_code, status.HTTP_400_BAD_REQUEST) + + def test_obtain_evaluation_type_by_educator(self): + + eval_type = EvaluationType.objects.create(**self.evaluation_type_data) + eval_type_forbid = EvaluationType.objects.create(**self.evaluation_type_data_forbiden) + response = self.client.get( + f"/api/evaluation-type/{eval_type.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["name"], "Asistencia") + self.assertEqual(response.data["description"], "asitencia diaria") + + response2 = self.client.get( + f"/api/evaluation-type/{eval_type_forbid.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) + + def test_update_evaluation_type_by_educator(self): + eval_type = EvaluationType.objects.create(**self.evaluation_type_data) + self.evaluation_type_data["name"] = "Participacion en clase" + self.evaluation_type_data["lesson"] = self.lesson.id + self.evaluation_type_data_bad_request["lesson"] = self.lesson.id + + response = self.client.put( + f"/api/evaluation-type/{eval_type.id}/", + self.evaluation_type_data, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["name"], "Participacion en clase") + + eval_type_forbid = EvaluationType.objects.create(**self.evaluation_type_data_forbiden) + self.evaluation_type_data_forbiden["lesson"] = self.lesson2.id + response2 = self.client.put( + f"/api/evaluation-type/{eval_type_forbid.id}/", + self.evaluation_type_data, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) + + response3 = self.client.put( + f"/api/evaluation-type/{eval_type.id}/", + self.evaluation_type_data_bad_request, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response3.status_code, status.HTTP_400_BAD_REQUEST) + + + def test_delete_evaluation_type_by_educator(self): + eval_type = EvaluationType.objects.create(**self.evaluation_type_data) + eval_type_forbid = EvaluationType.objects.create(**self.evaluation_type_data_forbiden) + response = self.client.delete( + f"/api/evaluation-type/{eval_type.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + response2 = self.client.delete( + f"/api/evaluation-type/{eval_type_forbid.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + self.assertEqual(EvaluationType.objects.count(), 1) + self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) + +class EducatorStudentEvaluationTestCase(APITestCase): + def setUp(self): + self.family = Family.objects.create(name="Los Pedraz") + self.educator = Educator.objects.create(description="Profesor de lengua", birthdate="1969-04-21") + self.educator2 = Educator.objects.create(description="Profesor de mates", birthdate="1998-04-21") + + self.factory = APIRequestFactory() + self.user = User.objects.create( + username="testuser", + email="example@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + self.token = Token.objects.create(user=self.user) + self.student = Student.objects.create( + name="Amadeo", + surname="Portillo", + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="TRES AÑOS", + education_center_tutor="Don Carlos Perez", + nationality="Aleman", + birthdate="2015-04-21", + family=self.family, + ) + self.lesson = Lesson.objects.create( + name="PRIMER Materia", + description="Módulo C, segunda planta", + capacity=50, + is_morning_lesson=True, + educator=self.educator, + start_date="2024-01-28", + end_date="2024-05-28", + ) + self.lesson2 = Lesson.objects.create( + name="Segunda Materia", + description="Módulo B, segunda planta", + capacity=50, + is_morning_lesson=True, + educator=self.educator2, + start_date="2024-01-28", + end_date="2024-05-28", + ) + self.lesson.students.add(self.student) + self.lesson2.students.add(self.student) + self.evaluation_type = EvaluationType.objects.create( + name= "Asistencia", + description = "asitencia diaria", + evaluation_type = DAILY, + grade_system = ZERO_TO_TEN, + lesson = self.lesson, + ) + self.evaluation_type2 = EvaluationType.objects.create( + name= "Asistencia", + description = "asitencia diaria", + evaluation_type = DAILY, + grade_system = ZERO_TO_TEN, + lesson = self.lesson2, + ) + self.student_eval_data = { + "grade" : 5, + "date" : "2024-01-28", + "comment" : "Puede mejorar", + "student" : self.student, + "evaluation_type" : self.evaluation_type, + } + self.student_eval_data_forbiden = { + "grade" : 5, + "date" : "2024-01-28", + "comment" : "Puede mejorar", + "student" : self.student, + "evaluation_type" : self.evaluation_type2, + } + self.student_eval_data_bad_request = { + "grade" : -1, + "date" : "2024-01-28", + "comment" : "Puede mejorar", + "student" : self.student, + "evaluation_type" : self.evaluation_type, + } + + + def test_create_student_evaluation_by_educator(self): + self.student_eval_data["student"] = self.student.id + self.student_eval_data["evaluation_type"] = self.evaluation_type.id + self.student_eval_data_bad_request["student"] = self.student.id + self.student_eval_data_bad_request["evaluation_type"] = self.evaluation_type2.id + response = self.client.post( + "/api/student-evaluation/", + self.student_eval_data, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + + response2 = self.client.post( + "/api/student-evaluation/", + self.student_eval_data_bad_request, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response2.status_code, status.HTTP_400_BAD_REQUEST) + + def test_obtain_student_evaluation_by_educator(self): + + student_eval = StudentEvaluation.objects.create(**self.student_eval_data) + student_eval_forbid = StudentEvaluation.objects.create(**self.student_eval_data_forbiden) + response = self.client.get( + f"/api/student-evaluation/{student_eval.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["grade"], 5) + self.assertEqual(response.data["comment"], "Puede mejorar") + + response2 = self.client.get( + f"/api/student-evaluation/{student_eval_forbid.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) + + def test_update_student_evaluation_by_educator(self): + student_eval = StudentEvaluation.objects.create(**self.student_eval_data) + self.student_eval_data["student"] = self.student.id + self.student_eval_data["evaluation_type"] = self.evaluation_type.id + self.student_eval_data["comment"] = "Mejoro tras la revision" + + response = self.client.put( + f"/api/student-evaluation/{student_eval.id}/", + self.student_eval_data, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(StudentEvaluation.objects.get().comment, "Mejoro tras la revision") + + student_eval_forbid = StudentEvaluation.objects.create(**self.student_eval_data_forbiden) + self.student_eval_data_forbiden["student"] = self.student.id + self.student_eval_data_forbiden["evaluation_type"] = self.evaluation_type2.id + response2 = self.client.put( + f"/api/student-evaluation/{student_eval_forbid.id}/", + self.student_eval_data, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) + + response3 = self.client.put( + f"/api/student-evaluation/{student_eval.id}/", + self.student_eval_data_bad_request, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response3.status_code, status.HTTP_400_BAD_REQUEST) + + + def test_delete_student_evaluation_by_educator(self): + student_eval = StudentEvaluation.objects.create(**self.student_eval_data) + student_eval_forbid = StudentEvaluation.objects.create(**self.student_eval_data_forbiden) + response = self.client.delete( + f"/api/student-evaluation/{student_eval.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + response2 = self.client.delete( + f"/api/student-evaluation/{student_eval_forbid.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + self.assertEqual(StudentEvaluation.objects.count(), 1) + self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file diff --git a/nexong/api/Lesson/tests.py b/nexong/api/Lesson/tests.py index e69de29b..76ce676a 100644 --- a/nexong/api/Lesson/tests.py +++ b/nexong/api/Lesson/tests.py @@ -0,0 +1,178 @@ +from nexong.api.Authentication.views import * +from nexong.models import * +from rest_framework.authtoken.models import Token +from rest_framework.test import APIRequestFactory +from rest_framework.test import APITestCase +from rest_framework import status + +class EducatorLessonApiViewSetTestCase(APITestCase): + def setUp(self): + self.family = Family.objects.create(name="Los Pedraz") + self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.factory = APIRequestFactory() + self.user = User.objects.create( + username="testuser", + email="example@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + self.token = Token.objects.create(user=self.user) + self.education_center = EducationCenter.objects.create( + name="San Francisco Solano" + ) + self.student = Student.objects.create( + name="Amadeo", + surname="Portillo", + education_center=self.education_center, + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="TRES AÑOS", + education_center_tutor="Don Carlos Perez", + nationality="Alemania", + birthdate="2015-04-21", + family=self.family, + ) + self.lesson = { + "name" :"Primera Materia", + "description" : "Módulo C, segunda planta", + "capacity":50, + "is_morning_lesson":True, + "educator":self.educator, + "start_date": "2024-01-28", + "end_date": "2024-05-28", + } + + + def test_create_lesson_by_educator(self): + self.lesson["educator"] = self.educator.id + response = self.client.post( + "/api/lesson/", + self.lesson, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_obtain_lesson_by_educator(self): + lesson = Lesson.objects.create(**self.lesson) + response = self.client.get( + f"/api/lesson/{lesson.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["name"], "Primera Materia") + + def test_update_lesson_by_educator(self): + lesson = Lesson.objects.create(**self.lesson) + self.lesson["educator"] = self.educator.id + self.lesson["is_morning_lesson"] = False + response = self.client.put( + f"/api/lesson/{lesson.id}/", + self.lesson, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_delete_lesson_by_educator(self): + lesson = Lesson.objects.create(**self.lesson) + response = self.client.delete( + f"/api/lesson/{lesson.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + +class EducatorLessonAttendanceApiViewSetTestCase(APITestCase): + def setUp(self): + self.family = Family.objects.create(name="Los Pedraz") + self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.factory = APIRequestFactory() + self.user = User.objects.create( + username="testuser", + email="example@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + self.token = Token.objects.create(user=self.user) + self.education_center = EducationCenter.objects.create( + name="San Francisco Solano" + ) + self.student = Student.objects.create( + name="Amadeo", + surname="Portillo", + education_center=self.education_center, + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="TRES AÑOS", + education_center_tutor="Don Carlos Perez", + nationality="Alemania", + birthdate="2015-04-21", + family=self.family, + ) + self.volunteer = Volunteer.objects.create( + academic_formation="Prueba Voluntario", + motivation="Test voluntario", + status="ACEPTADO", + address="Test voluntario address", + postal_code=12359, + birthdate="1956-07-05", + start_date="1955-07-05", + end_date="1956-07-05", + ) + self.lesson = Lesson.objects.create( + name="PRIMER Materia", + description="Módulo C, segunda planta", + capacity=50, + is_morning_lesson=True, + educator=self.educator, + start_date="2024-01-28", + end_date="2024-05-28", + ) + self.lessonAtendance = { + "date": "2024-01-28", + "lesson": self.lesson, + "volunteer": self.volunteer, + } + + + def test_create_lessonAttendance_by_educator(self): + self.lessonAtendance["lesson"] = self.lesson.id + self.lessonAtendance["volunteer"] = self.volunteer.id + response = self.client.post( + "/api/lesson-attendance/", + self.lessonAtendance, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_obtain_lessonAttendance_by_educator(self): + lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance) + response = self.client.get( + f"/api/lesson-attendance/{lessonAttendance.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["date"], "2024-01-28") + + def test_update_lessonAttendance_by_educator(self): + lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance) + self.lessonAtendance["lesson"] = self.lesson.id + self.lessonAtendance["volunteer"] = self.volunteer.id + self.lessonAtendance["date"] = "2024-01-20" + + response = self.client.put( + f"/api/lesson-attendance/{lessonAttendance.id}/", + self.lessonAtendance, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_delete_lessonAttendance_by_educator(self): + lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance) + response = self.client.delete( + f"/api/lesson-attendance/{lessonAttendance.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file diff --git a/nexong/api/Student/__init__.py b/nexong/api/Student/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/nexong/api/Student/tests.py b/nexong/api/Student/tests.py index e69de29b..8883fc44 100644 --- a/nexong/api/Student/tests.py +++ b/nexong/api/Student/tests.py @@ -0,0 +1,152 @@ +from nexong.api.Authentication.views import * +from nexong.models import * +from rest_framework.authtoken.models import Token +from rest_framework.test import APIRequestFactory +from rest_framework.test import APITestCase +from rest_framework import status +from django.core.files.uploadedfile import SimpleUploadedFile + + +class EducatorStudentApiViewSetTestCase(APITestCase): + def setUp(self): + self.family = Family.objects.create(name="Los Pedraz") + self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.factory = APIRequestFactory() + self.user = User.objects.create( + username="testuser", + email="example@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + self.token = Token.objects.create(user=self.user) + self.education_center = EducationCenter.objects.create( + name="San Francisco Solano" + ) + self.student = { + "name": "Amadeo", + "surname" :"Portillo", + "education_center":self.education_center, + "is_morning_student":True, + "activities_during_exit":"", + "status":"ACEPTADO", + "current_education_year":"TRES AÑOS", + "education_center_tutor":"Don Carlos Perez", + "nationality":"Alemania", + "birthdate":"2015-04-21", + "family":self.family, + } + + def test_create_student_by_educator(self): + self.student["family"] = self.family.id + self.student["education_center"] = self.education_center.id + response = self.client.post( + "/api/student/", + self.student, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_obtain_student_by_educator(self): + student = Student.objects.create(**self.student) + response = self.client.get( + f"/api/student/{student.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["name"], "Amadeo") + + def test_update_student_by_educator(self): + student = Student.objects.create(**self.student) + self.student["family"] = self.family.id + self.student["education_center"] = self.education_center.id + self.student["name"] = "Jose" + response = self.client.put( + f"/api/student/{student.id}/", + self.student, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_delete_student_by_educator(self): + student = Student.objects.create(**self.student) + response = self.client.delete( + f"/api/student/{student.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + +class EducatorQuarterMArksApiViewSetTestCase(APITestCase): + def setUp(self): + self.family = Family.objects.create(name="Los Pedraz") + self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.factory = APIRequestFactory() + self.user = User.objects.create( + username="testuser", + email="example@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + self.token = Token.objects.create(user=self.user) + self.education_center = EducationCenter.objects.create( + name="San Francisco Solano" + ) + self.student = Student.objects.create( + name="Amadeo", + surname="Portillo", + education_center=self.education_center, + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="TRES AÑOS", + education_center_tutor="Don Carlos Perez", + nationality="Alemania", + birthdate="2015-04-21", + family=self.family, + ) + self.quartermarks = { + "date" : "2024-03-21", + "student" : self.student + } + file_content = b"Test file content" + self.quartermarks["marks"] = SimpleUploadedFile( + "student_marks.pdf", file_content + ) + + def test_create_quarterMarks_by_educator(self): + self.quartermarks["student"] = self.student.id + response = self.client.post( + "/api/quarter-marks/", + self.quartermarks, + format="multipart", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_obtain_quarterMarks_by_educator(self): + quartermarks = QuarterMarks.objects.create(**self.quartermarks) + response = self.client.get( + f"/api/quarter-marks/{quartermarks.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["date"], "2024-03-21") + + def test_update_quarterMarks_by_educator(self): + quartermarks = QuarterMarks.objects.create(**self.quartermarks) + self.quartermarks["student"] = self.student.id + self.quartermarks["date"] = "2024-03-16" + response = self.client.put( + f"/api/quarter-marks/{quartermarks.id}/", + self.quartermarks, + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_delete_quarterMarks_by_educator(self): + quartermarks = QuarterMarks.objects.create(**self.quartermarks) + response = self.client.delete( + f"/api/quarter-marks/{quartermarks.id}/", + HTTP_AUTHORIZATION=f"Token {self.token.key}", + ) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file From 61b4b1a9c38985068cfa39ecf48df25205b8e3f5 Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Tue, 16 Apr 2024 23:06:45 +0000 Subject: [PATCH 3/8] refactor: Format code with Black --- nexong/api/Authentication/tests.py | 24 +++-- nexong/api/CenterExit/tests.py | 9 +- nexong/api/Evaluation/test.py | 136 ++++++++++++++++------------- nexong/api/Lesson/tests.py | 30 ++++--- nexong/api/Student/tests.py | 44 +++++----- 5 files changed, 135 insertions(+), 108 deletions(-) diff --git a/nexong/api/Authentication/tests.py b/nexong/api/Authentication/tests.py index 4d37a436..9ba879bb 100644 --- a/nexong/api/Authentication/tests.py +++ b/nexong/api/Authentication/tests.py @@ -14,7 +14,6 @@ def setUp(self): self.educator_data = { "description": "Test description", "birthdate": "1969-06-09", - } self.educator_error_desc = { "description": "", @@ -30,8 +29,8 @@ def setUp(self): self.token = Token.objects.create(user=self.user) def test_create_educator(self): - serializerE1 = EducatorSerializer(data = self.educator_error_desc) - serializerE2 = EducatorSerializer(data = self.educator_error_date) + serializerE1 = EducatorSerializer(data=self.educator_error_desc) + serializerE2 = EducatorSerializer(data=self.educator_error_date) response_error = self.client.post( "/api/educator/", @@ -43,11 +42,16 @@ def test_create_educator(self): with self.assertRaises(ValidationError) as context1: serializerE1.is_valid(raise_exception=True) - self.assertEqual(context1.exception.detail["description"][0], "This field may not be blank.") + self.assertEqual( + context1.exception.detail["description"][0], "This field may not be blank." + ) with self.assertRaises(ValidationError) as context2: serializerE2.is_valid(raise_exception=True) - self.assertEqual(context2.exception.detail["non_field_errors"][0], "Birthdate can't be greater than today") + self.assertEqual( + context2.exception.detail["non_field_errors"][0], + "Birthdate can't be greater than today", + ) response = self.client.post( "/api/educator/", @@ -70,7 +74,6 @@ def test_retrieve_educator(self): self.assertEqual(response.data["description"], "Test description") self.assertEqual(response.data["birthdate"], "1969-06-09") - def test_update_educator(self): educator = Educator.objects.create(**self.educator_data) self.educator_data["description"] = "Updated description" @@ -81,13 +84,8 @@ def test_update_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual( - Educator.objects.get().description, "Updated description" - ) - self.assertEqual( - Educator.objects.get().birthdate, datetime.date(1970, 7, 10) - ) - + self.assertEqual(Educator.objects.get().description, "Updated description") + self.assertEqual(Educator.objects.get().birthdate, datetime.date(1970, 7, 10)) def test_delete_educator(self): educator = Educator.objects.create(**self.educator_data) diff --git a/nexong/api/CenterExit/tests.py b/nexong/api/CenterExit/tests.py index 231cb3b1..0a9bf569 100644 --- a/nexong/api/CenterExit/tests.py +++ b/nexong/api/CenterExit/tests.py @@ -6,10 +6,13 @@ from rest_framework import status from django.core.files.uploadedfile import SimpleUploadedFile + class EducatorCenterExitApiViewSetTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.educator = Educator.objects.create( + birthdate="1969-06-09", description="EL profesor de lengua" + ) self.factory = APIRequestFactory() self.user = User.objects.create( username="testuser", @@ -129,11 +132,11 @@ def test_update_center_authorization_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - + def test_delete_center_authorization_by_educator(self): center_exit = CenterExitAuthorization.objects.create(**self.center_exit) response = self.client.delete( f"/api/center-exit/{center_exit.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) diff --git a/nexong/api/Evaluation/test.py b/nexong/api/Evaluation/test.py index 63e8feea..1991ef84 100644 --- a/nexong/api/Evaluation/test.py +++ b/nexong/api/Evaluation/test.py @@ -5,11 +5,16 @@ from rest_framework.test import APITestCase from rest_framework import status + class EducatorEvaluationTypeTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create(description="Profesor de lengua", birthdate="1969-04-21") - self.educator2 = Educator.objects.create(description="Profesor de mates", birthdate="1998-04-21") + self.educator = Educator.objects.create( + description="Profesor de lengua", birthdate="1969-04-21" + ) + self.educator2 = Educator.objects.create( + description="Profesor de mates", birthdate="1998-04-21" + ) self.factory = APIRequestFactory() self.user = User.objects.create( @@ -50,27 +55,26 @@ def setUp(self): end_date="2024-05-28", ) self.evaluation_type_data = { - "name" : "Asistencia", - "description" : "asitencia diaria", - "evaluation_type" : "DIARIO", - "grade_system" : "CERO A UNO", - "lesson" : self.lesson, + "name": "Asistencia", + "description": "asitencia diaria", + "evaluation_type": "DIARIO", + "grade_system": "CERO A UNO", + "lesson": self.lesson, } self.evaluation_type_data_forbiden = { - "name" : "Asistencia", - "description" : "asitencia diaria", - "evaluation_type" : "DIARIO", - "grade_system" : "CERO A UNO", - "lesson" : self.lesson2, + "name": "Asistencia", + "description": "asitencia diaria", + "evaluation_type": "DIARIO", + "grade_system": "CERO A UNO", + "lesson": self.lesson2, } self.evaluation_type_data_bad_request = { - "name" : "", - "description" : "asitencia diaria", - "evaluation_type" : "DIARIO", - "grade_system" : "CERO A UNO", - "lesson" : self.lesson, + "name": "", + "description": "asitencia diaria", + "evaluation_type": "DIARIO", + "grade_system": "CERO A UNO", + "lesson": self.lesson, } - def test_create_evaluation_type_by_educator(self): self.evaluation_type_data["lesson"] = self.lesson.id @@ -92,15 +96,16 @@ def test_create_evaluation_type_by_educator(self): self.assertEqual(response2.status_code, status.HTTP_400_BAD_REQUEST) def test_obtain_evaluation_type_by_educator(self): - eval_type = EvaluationType.objects.create(**self.evaluation_type_data) - eval_type_forbid = EvaluationType.objects.create(**self.evaluation_type_data_forbiden) + eval_type_forbid = EvaluationType.objects.create( + **self.evaluation_type_data_forbiden + ) response = self.client.get( f"/api/evaluation-type/{eval_type.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data["name"], "Asistencia") + self.assertEqual(response.data["name"], "Asistencia") self.assertEqual(response.data["description"], "asitencia diaria") response2 = self.client.get( @@ -123,7 +128,9 @@ def test_update_evaluation_type_by_educator(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["name"], "Participacion en clase") - eval_type_forbid = EvaluationType.objects.create(**self.evaluation_type_data_forbiden) + eval_type_forbid = EvaluationType.objects.create( + **self.evaluation_type_data_forbiden + ) self.evaluation_type_data_forbiden["lesson"] = self.lesson2.id response2 = self.client.put( f"/api/evaluation-type/{eval_type_forbid.id}/", @@ -139,10 +146,11 @@ def test_update_evaluation_type_by_educator(self): ) self.assertEqual(response3.status_code, status.HTTP_400_BAD_REQUEST) - def test_delete_evaluation_type_by_educator(self): eval_type = EvaluationType.objects.create(**self.evaluation_type_data) - eval_type_forbid = EvaluationType.objects.create(**self.evaluation_type_data_forbiden) + eval_type_forbid = EvaluationType.objects.create( + **self.evaluation_type_data_forbiden + ) response = self.client.delete( f"/api/evaluation-type/{eval_type.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", @@ -155,11 +163,16 @@ def test_delete_evaluation_type_by_educator(self): self.assertEqual(EvaluationType.objects.count(), 1) self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) + class EducatorStudentEvaluationTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create(description="Profesor de lengua", birthdate="1969-04-21") - self.educator2 = Educator.objects.create(description="Profesor de mates", birthdate="1998-04-21") + self.educator = Educator.objects.create( + description="Profesor de lengua", birthdate="1969-04-21" + ) + self.educator2 = Educator.objects.create( + description="Profesor de mates", birthdate="1998-04-21" + ) self.factory = APIRequestFactory() self.user = User.objects.create( @@ -202,41 +215,40 @@ def setUp(self): self.lesson.students.add(self.student) self.lesson2.students.add(self.student) self.evaluation_type = EvaluationType.objects.create( - name= "Asistencia", - description = "asitencia diaria", - evaluation_type = DAILY, - grade_system = ZERO_TO_TEN, - lesson = self.lesson, + name="Asistencia", + description="asitencia diaria", + evaluation_type=DAILY, + grade_system=ZERO_TO_TEN, + lesson=self.lesson, ) self.evaluation_type2 = EvaluationType.objects.create( - name= "Asistencia", - description = "asitencia diaria", - evaluation_type = DAILY, - grade_system = ZERO_TO_TEN, - lesson = self.lesson2, + name="Asistencia", + description="asitencia diaria", + evaluation_type=DAILY, + grade_system=ZERO_TO_TEN, + lesson=self.lesson2, ) self.student_eval_data = { - "grade" : 5, - "date" : "2024-01-28", - "comment" : "Puede mejorar", - "student" : self.student, - "evaluation_type" : self.evaluation_type, + "grade": 5, + "date": "2024-01-28", + "comment": "Puede mejorar", + "student": self.student, + "evaluation_type": self.evaluation_type, } self.student_eval_data_forbiden = { - "grade" : 5, - "date" : "2024-01-28", - "comment" : "Puede mejorar", - "student" : self.student, - "evaluation_type" : self.evaluation_type2, + "grade": 5, + "date": "2024-01-28", + "comment": "Puede mejorar", + "student": self.student, + "evaluation_type": self.evaluation_type2, } self.student_eval_data_bad_request = { - "grade" : -1, - "date" : "2024-01-28", - "comment" : "Puede mejorar", - "student" : self.student, - "evaluation_type" : self.evaluation_type, + "grade": -1, + "date": "2024-01-28", + "comment": "Puede mejorar", + "student": self.student, + "evaluation_type": self.evaluation_type, } - def test_create_student_evaluation_by_educator(self): self.student_eval_data["student"] = self.student.id @@ -260,9 +272,10 @@ def test_create_student_evaluation_by_educator(self): self.assertEqual(response2.status_code, status.HTTP_400_BAD_REQUEST) def test_obtain_student_evaluation_by_educator(self): - student_eval = StudentEvaluation.objects.create(**self.student_eval_data) - student_eval_forbid = StudentEvaluation.objects.create(**self.student_eval_data_forbiden) + student_eval_forbid = StudentEvaluation.objects.create( + **self.student_eval_data_forbiden + ) response = self.client.get( f"/api/student-evaluation/{student_eval.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", @@ -289,9 +302,13 @@ def test_update_student_evaluation_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(StudentEvaluation.objects.get().comment, "Mejoro tras la revision") + self.assertEqual( + StudentEvaluation.objects.get().comment, "Mejoro tras la revision" + ) - student_eval_forbid = StudentEvaluation.objects.create(**self.student_eval_data_forbiden) + student_eval_forbid = StudentEvaluation.objects.create( + **self.student_eval_data_forbiden + ) self.student_eval_data_forbiden["student"] = self.student.id self.student_eval_data_forbiden["evaluation_type"] = self.evaluation_type2.id response2 = self.client.put( @@ -308,10 +325,11 @@ def test_update_student_evaluation_by_educator(self): ) self.assertEqual(response3.status_code, status.HTTP_400_BAD_REQUEST) - def test_delete_student_evaluation_by_educator(self): student_eval = StudentEvaluation.objects.create(**self.student_eval_data) - student_eval_forbid = StudentEvaluation.objects.create(**self.student_eval_data_forbiden) + student_eval_forbid = StudentEvaluation.objects.create( + **self.student_eval_data_forbiden + ) response = self.client.delete( f"/api/student-evaluation/{student_eval.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", @@ -322,4 +340,4 @@ def test_delete_student_evaluation_by_educator(self): ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(StudentEvaluation.objects.count(), 1) - self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file + self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) diff --git a/nexong/api/Lesson/tests.py b/nexong/api/Lesson/tests.py index 22859891..5c3b910b 100644 --- a/nexong/api/Lesson/tests.py +++ b/nexong/api/Lesson/tests.py @@ -207,6 +207,8 @@ def test_delete_lesson_attendance_by_admin(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, 204) + + from nexong.api.Authentication.views import * from nexong.models import * from rest_framework.authtoken.models import Token @@ -214,10 +216,13 @@ def test_delete_lesson_attendance_by_admin(self): from rest_framework.test import APITestCase from rest_framework import status + class EducatorLessonApiViewSetTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.educator = Educator.objects.create( + birthdate="1969-06-09", description="EL profesor de lengua" + ) self.factory = APIRequestFactory() self.user = User.objects.create( username="testuser", @@ -243,16 +248,15 @@ def setUp(self): family=self.family, ) self.lesson = { - "name" :"Primera Materia", - "description" : "Módulo C, segunda planta", - "capacity":50, - "is_morning_lesson":True, - "educator":self.educator, + "name": "Primera Materia", + "description": "Módulo C, segunda planta", + "capacity": 50, + "is_morning_lesson": True, + "educator": self.educator, "start_date": "2024-01-28", "end_date": "2024-05-28", } - def test_create_lesson_by_educator(self): self.lesson["educator"] = self.educator.id response = self.client.post( @@ -282,7 +286,7 @@ def test_update_lesson_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - + def test_delete_lesson_by_educator(self): lesson = Lesson.objects.create(**self.lesson) response = self.client.delete( @@ -291,10 +295,13 @@ def test_delete_lesson_by_educator(self): ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + class EducatorLessonAttendanceApiViewSetTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.educator = Educator.objects.create( + birthdate="1969-06-09", description="EL profesor de lengua" + ) self.factory = APIRequestFactory() self.user = User.objects.create( username="testuser", @@ -344,7 +351,6 @@ def setUp(self): "volunteer": self.volunteer, } - def test_create_lessonAttendance_by_educator(self): self.lessonAtendance["lesson"] = self.lesson.id self.lessonAtendance["volunteer"] = self.volunteer.id @@ -377,11 +383,11 @@ def test_update_lessonAttendance_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - + def test_delete_lessonAttendance_by_educator(self): lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance) response = self.client.delete( f"/api/lesson-attendance/{lessonAttendance.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) diff --git a/nexong/api/Student/tests.py b/nexong/api/Student/tests.py index 8883fc44..23a0a244 100644 --- a/nexong/api/Student/tests.py +++ b/nexong/api/Student/tests.py @@ -10,7 +10,9 @@ class EducatorStudentApiViewSetTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.educator = Educator.objects.create( + birthdate="1969-06-09", description="EL profesor de lengua" + ) self.factory = APIRequestFactory() self.user = User.objects.create( username="testuser", @@ -24,18 +26,18 @@ def setUp(self): ) self.student = { "name": "Amadeo", - "surname" :"Portillo", - "education_center":self.education_center, - "is_morning_student":True, - "activities_during_exit":"", - "status":"ACEPTADO", - "current_education_year":"TRES AÑOS", - "education_center_tutor":"Don Carlos Perez", - "nationality":"Alemania", - "birthdate":"2015-04-21", - "family":self.family, + "surname": "Portillo", + "education_center": self.education_center, + "is_morning_student": True, + "activities_during_exit": "", + "status": "ACEPTADO", + "current_education_year": "TRES AÑOS", + "education_center_tutor": "Don Carlos Perez", + "nationality": "Alemania", + "birthdate": "2015-04-21", + "family": self.family, } - + def test_create_student_by_educator(self): self.student["family"] = self.family.id self.student["education_center"] = self.education_center.id @@ -67,7 +69,7 @@ def test_update_student_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - + def test_delete_student_by_educator(self): student = Student.objects.create(**self.student) response = self.client.delete( @@ -76,10 +78,13 @@ def test_delete_student_by_educator(self): ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + class EducatorQuarterMArksApiViewSetTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create(birthdate="1969-06-09", description="EL profesor de lengua") + self.educator = Educator.objects.create( + birthdate="1969-06-09", description="EL profesor de lengua" + ) self.factory = APIRequestFactory() self.user = User.objects.create( username="testuser", @@ -104,15 +109,12 @@ def setUp(self): birthdate="2015-04-21", family=self.family, ) - self.quartermarks = { - "date" : "2024-03-21", - "student" : self.student - } + self.quartermarks = {"date": "2024-03-21", "student": self.student} file_content = b"Test file content" self.quartermarks["marks"] = SimpleUploadedFile( "student_marks.pdf", file_content ) - + def test_create_quarterMarks_by_educator(self): self.quartermarks["student"] = self.student.id response = self.client.post( @@ -142,11 +144,11 @@ def test_update_quarterMarks_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - + def test_delete_quarterMarks_by_educator(self): quartermarks = QuarterMarks.objects.create(**self.quartermarks) response = self.client.delete( f"/api/quarter-marks/{quartermarks.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) \ No newline at end of file + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) From ecdbd9e1f598478ae4fef4082d1458c6f4bcf9b1 Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Wed, 17 Apr 2024 23:11:41 +0200 Subject: [PATCH 4/8] Fix: repeated imports --- nexong/api/Lesson/tests.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/nexong/api/Lesson/tests.py b/nexong/api/Lesson/tests.py index 5c3b910b..6f70a030 100644 --- a/nexong/api/Lesson/tests.py +++ b/nexong/api/Lesson/tests.py @@ -4,7 +4,7 @@ from rest_framework.test import APIRequestFactory from rest_framework import status from rest_framework.authtoken.models import Token - +from rest_framework.test import APITestCase class AdminLessonApiViewSetTestCase(TestCase): def setUp(self): @@ -209,14 +209,6 @@ def test_delete_lesson_attendance_by_admin(self): self.assertEqual(response.status_code, 204) -from nexong.api.Authentication.views import * -from nexong.models import * -from rest_framework.authtoken.models import Token -from rest_framework.test import APIRequestFactory -from rest_framework.test import APITestCase -from rest_framework import status - - class EducatorLessonApiViewSetTestCase(APITestCase): def setUp(self): self.family = Family.objects.create(name="Los Pedraz") From 19082af83403767e3a79cec7ac52509d9964f11c Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Wed, 17 Apr 2024 21:12:09 +0000 Subject: [PATCH 5/8] refactor: Format code with Black --- nexong/api/Lesson/tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nexong/api/Lesson/tests.py b/nexong/api/Lesson/tests.py index 6f70a030..be78414c 100644 --- a/nexong/api/Lesson/tests.py +++ b/nexong/api/Lesson/tests.py @@ -6,6 +6,7 @@ from rest_framework.authtoken.models import Token from rest_framework.test import APITestCase + class AdminLessonApiViewSetTestCase(TestCase): def setUp(self): self.factory = APIRequestFactory() From ec0e86ae4611141ac186aa06d425c34ec4a48a62 Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Fri, 19 Apr 2024 01:06:51 +0200 Subject: [PATCH 6/8] Fix: codacy errors --- nexong/api/Authentication/tests.py | 49 ++++---- nexong/api/CenterExit/tests.py | 101 +--------------- nexong/api/Evaluation/test.py | 166 ++----------------------- nexong/api/Lesson/tests.py | 135 ++++----------------- nexong/api/Student/tests.py | 93 +++------------ nexong/api/helpers/testsSetup.py | 186 +++++++++++++++++++++++++++++ 6 files changed, 261 insertions(+), 469 deletions(-) create mode 100644 nexong/api/helpers/testsSetup.py diff --git a/nexong/api/Authentication/tests.py b/nexong/api/Authentication/tests.py index 9ba879bb..581d7f84 100644 --- a/nexong/api/Authentication/tests.py +++ b/nexong/api/Authentication/tests.py @@ -6,27 +6,15 @@ from rest_framework.test import APITestCase from rest_framework import status from django.test import TestCase - +from nexong.api.helpers.testsSetup import testSetupEducator class EducatorApiViewSetTestCase(APITestCase): def setUp(self): - self.factory = APIRequestFactory() - self.educator_data = { - "description": "Test description", - "birthdate": "1969-06-09", - } - self.educator_error_desc = { - "description": "", - "birthdate": "1969-06-09", - } - self.educator_error_date = { - "description": "Test description", - "birthdate": "2069-06-09", - } - self.user = User.objects.create( - username="testuser", email="example@gmail.com", role=ADMIN + testSetupEducator(self) + self.userAdmin = User.objects.create( + username="testAdminUserForEducator", email="exampleAdmin@outlook.com", role=ADMIN ) - self.token = Token.objects.create(user=self.user) + self.token2 = Token.objects.create(user=self.userAdmin) def test_create_educator(self): serializerE1 = EducatorSerializer(data=self.educator_error_desc) @@ -36,7 +24,7 @@ def test_create_educator(self): "/api/educator/", self.educator_error_date, format="multipart", - HTTP_AUTHORIZATION=f"Token {self.token.key}", + HTTP_AUTHORIZATION=f"Token {self.token2.key}", ) self.assertEqual(response_error.status_code, status.HTTP_400_BAD_REQUEST) @@ -52,23 +40,24 @@ def test_create_educator(self): context2.exception.detail["non_field_errors"][0], "Birthdate can't be greater than today", ) - + + count = Educator.objects.count() response = self.client.post( "/api/educator/", self.educator_data, format="multipart", - HTTP_AUTHORIZATION=f"Token {self.token.key}", + HTTP_AUTHORIZATION=f"Token {self.token2.key}", ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) - self.assertEqual(Educator.objects.count(), 1) - self.assertEqual(Educator.objects.get().description, "Test description") - self.assertEqual(Educator.objects.get().birthdate, datetime.date(1969, 6, 9)) + self.assertEqual(Educator.objects.count(), count+1) + self.assertEqual(response.data["description"], "Test description") + self.assertEqual(response.data["birthdate"], "1969-06-09") def test_retrieve_educator(self): educator = Educator.objects.create(**self.educator_data) response = self.client.get( f"/api/educator/{educator.id}/", - HTTP_AUTHORIZATION=f"Token {self.token.key}", + HTTP_AUTHORIZATION=f"Token {self.token2.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["description"], "Test description") @@ -81,20 +70,22 @@ def test_update_educator(self): response = self.client.put( f"/api/educator/{educator.id}/", self.educator_data, - HTTP_AUTHORIZATION=f"Token {self.token.key}", + HTTP_AUTHORIZATION=f"Token {self.token2.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(Educator.objects.get().description, "Updated description") - self.assertEqual(Educator.objects.get().birthdate, datetime.date(1970, 7, 10)) + self.assertEqual(response.data["description"], "Updated description") + self.assertEqual(response.data["birthdate"], "1970-07-10") def test_delete_educator(self): educator = Educator.objects.create(**self.educator_data) + count = Educator.objects.count() + response = self.client.delete( f"/api/educator/{educator.id}/", - HTTP_AUTHORIZATION=f"Token {self.token.key}", + HTTP_AUTHORIZATION=f"Token {self.token2.key}", ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) - self.assertEqual(Educator.objects.count(), 0) + self.assertEqual(Educator.objects.count(), count-1) class AdminUserApiViewSetTestCase(TestCase): diff --git a/nexong/api/CenterExit/tests.py b/nexong/api/CenterExit/tests.py index 0a9bf569..3655bac0 100644 --- a/nexong/api/CenterExit/tests.py +++ b/nexong/api/CenterExit/tests.py @@ -1,109 +1,14 @@ from nexong.api.Authentication.views import * from nexong.models import * -from rest_framework.authtoken.models import Token -from rest_framework.test import APIRequestFactory from rest_framework.test import APITestCase from rest_framework import status -from django.core.files.uploadedfile import SimpleUploadedFile +from nexong.api.helpers.testsSetup import testSetupEducator class EducatorCenterExitApiViewSetTestCase(APITestCase): def setUp(self): - self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create( - birthdate="1969-06-09", description="EL profesor de lengua" - ) - self.factory = APIRequestFactory() - self.user = User.objects.create( - username="testuser", - email="example@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) - self.token = Token.objects.create(user=self.user) - self.educator2 = Educator.objects.create(birthdate="2000-04-21") - self.educator3 = Educator.objects.create(birthdate="2000-04-22") - self.education_center = EducationCenter.objects.create( - name="San Francisco Solano" - ) - self.voluntario = Volunteer.objects.create( - academic_formation="Prueba Voluntario", - motivation="Test voluntario", - status="ACEPTADO", - address="Test voluntario address", - postal_code=12359, - birthdate="1956-07-05", - start_date="1955-07-05", - end_date="1956-07-05", - ) - self.voluntario2 = Volunteer.objects.create( - academic_formation="Test vol2", - motivation="Test vol", - status="ACEPTADO", - address="Test advol", - postal_code=12356, - birthdate="1956-07-05", - start_date="1956-07-05", - end_date="1956-07-05", - ) - self.student = Student.objects.create( - name="Amadeo", - surname="Portillo", - education_center=self.education_center, - is_morning_student=True, - activities_during_exit="", - status="ACEPTADO", - current_education_year="TRES AÑOS", - education_center_tutor="Don Carlos Perez", - nationality="Alemania", - birthdate="2015-04-21", - family=self.family, - ) - self.student2 = Student.objects.create( - name="Pablo", - surname="Portillo", - education_center=self.education_center, - is_morning_student=False, - activities_during_exit="", - status="ACEPTADO", - current_education_year="TRES AÑOS", - education_center_tutor="Don Carlos Perez", - nationality="Alemania", - birthdate="2015-06-21", - family=self.family, - ) - self.lesson = Lesson.objects.create( - name="PRIMER Materia", - description="Módulo C, segunda planta", - capacity=50, - is_morning_lesson=True, - educator=self.educator, - start_date="2024-01-28", - end_date="2024-05-28", - ) - self.lesson_event = LessonEvent.objects.create( - name="Excursión a La Giralda", - description="Vamos al centro a ver La Giralda", - place="Centro Sevilla", - price=25, - max_volunteers=10, - start_date="2024-04-18 12:00-00:00", - end_date="2024-04-18 18:00-00:00", - lesson=self.lesson, - ) - self.lesson_event.educators.add(self.educator2, self.educator3) - self.lesson_event.attendees.add(self.student, self.student2) - self.lesson_event.volunteers.add(self.voluntario, self.voluntario2) - - self.center_exit = { - "student": self.student, - "is_authorized": True, - "lesson_event": self.lesson_event, - } - file_content = b"Test file content" - self.center_exit["authorization"] = SimpleUploadedFile( - "centerexit_authorization.pdf", file_content - ) + testSetupEducator(self) + def test_create_center_exit_by_educator(self): response = self.client.post( diff --git a/nexong/api/Evaluation/test.py b/nexong/api/Evaluation/test.py index 1991ef84..ae55d483 100644 --- a/nexong/api/Evaluation/test.py +++ b/nexong/api/Evaluation/test.py @@ -1,81 +1,16 @@ from nexong.api.Authentication.views import * from nexong.models import * -from rest_framework.authtoken.models import Token -from rest_framework.test import APIRequestFactory from rest_framework.test import APITestCase from rest_framework import status +from nexong.api.helpers.testsSetup import testSetupEducator + class EducatorEvaluationTypeTestCase(APITestCase): def setUp(self): - self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create( - description="Profesor de lengua", birthdate="1969-04-21" - ) - self.educator2 = Educator.objects.create( - description="Profesor de mates", birthdate="1998-04-21" - ) - - self.factory = APIRequestFactory() - self.user = User.objects.create( - username="testuser", - email="example@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) - self.token = Token.objects.create(user=self.user) - self.student = Student.objects.create( - name="Amadeo", - surname="Portillo", - is_morning_student=True, - activities_during_exit="", - status="ACEPTADO", - current_education_year="TRES AÑOS", - education_center_tutor="Don Carlos Perez", - nationality="Aleman", - birthdate="2015-04-21", - family=self.family, - ) - self.lesson = Lesson.objects.create( - name="PRIMER Materia", - description="Módulo C, segunda planta", - capacity=50, - is_morning_lesson=True, - educator=self.educator, - start_date="2024-01-28", - end_date="2024-05-28", - ) - self.lesson2 = Lesson.objects.create( - name="Segunda Materia", - description="Módulo B, segunda planta", - capacity=50, - is_morning_lesson=True, - educator=self.educator2, - start_date="2024-01-28", - end_date="2024-05-28", - ) - self.evaluation_type_data = { - "name": "Asistencia", - "description": "asitencia diaria", - "evaluation_type": "DIARIO", - "grade_system": "CERO A UNO", - "lesson": self.lesson, - } - self.evaluation_type_data_forbiden = { - "name": "Asistencia", - "description": "asitencia diaria", - "evaluation_type": "DIARIO", - "grade_system": "CERO A UNO", - "lesson": self.lesson2, - } - self.evaluation_type_data_bad_request = { - "name": "", - "description": "asitencia diaria", - "evaluation_type": "DIARIO", - "grade_system": "CERO A UNO", - "lesson": self.lesson, - } - + testSetupEducator(self) + + def test_create_evaluation_type_by_educator(self): self.evaluation_type_data["lesson"] = self.lesson.id self.evaluation_type_data_bad_request["lesson"] = self.lesson.id @@ -151,6 +86,7 @@ def test_delete_evaluation_type_by_educator(self): eval_type_forbid = EvaluationType.objects.create( **self.evaluation_type_data_forbiden ) + count = EvaluationType.objects.count() response = self.client.delete( f"/api/evaluation-type/{eval_type.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", @@ -160,95 +96,13 @@ def test_delete_evaluation_type_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) - self.assertEqual(EvaluationType.objects.count(), 1) + self.assertEqual(EvaluationType.objects.count(), count-1) self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) class EducatorStudentEvaluationTestCase(APITestCase): def setUp(self): - self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create( - description="Profesor de lengua", birthdate="1969-04-21" - ) - self.educator2 = Educator.objects.create( - description="Profesor de mates", birthdate="1998-04-21" - ) - - self.factory = APIRequestFactory() - self.user = User.objects.create( - username="testuser", - email="example@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) - self.token = Token.objects.create(user=self.user) - self.student = Student.objects.create( - name="Amadeo", - surname="Portillo", - is_morning_student=True, - activities_during_exit="", - status="ACEPTADO", - current_education_year="TRES AÑOS", - education_center_tutor="Don Carlos Perez", - nationality="Aleman", - birthdate="2015-04-21", - family=self.family, - ) - self.lesson = Lesson.objects.create( - name="PRIMER Materia", - description="Módulo C, segunda planta", - capacity=50, - is_morning_lesson=True, - educator=self.educator, - start_date="2024-01-28", - end_date="2024-05-28", - ) - self.lesson2 = Lesson.objects.create( - name="Segunda Materia", - description="Módulo B, segunda planta", - capacity=50, - is_morning_lesson=True, - educator=self.educator2, - start_date="2024-01-28", - end_date="2024-05-28", - ) - self.lesson.students.add(self.student) - self.lesson2.students.add(self.student) - self.evaluation_type = EvaluationType.objects.create( - name="Asistencia", - description="asitencia diaria", - evaluation_type=DAILY, - grade_system=ZERO_TO_TEN, - lesson=self.lesson, - ) - self.evaluation_type2 = EvaluationType.objects.create( - name="Asistencia", - description="asitencia diaria", - evaluation_type=DAILY, - grade_system=ZERO_TO_TEN, - lesson=self.lesson2, - ) - self.student_eval_data = { - "grade": 5, - "date": "2024-01-28", - "comment": "Puede mejorar", - "student": self.student, - "evaluation_type": self.evaluation_type, - } - self.student_eval_data_forbiden = { - "grade": 5, - "date": "2024-01-28", - "comment": "Puede mejorar", - "student": self.student, - "evaluation_type": self.evaluation_type2, - } - self.student_eval_data_bad_request = { - "grade": -1, - "date": "2024-01-28", - "comment": "Puede mejorar", - "student": self.student, - "evaluation_type": self.evaluation_type, - } + testSetupEducator(self) def test_create_student_evaluation_by_educator(self): self.student_eval_data["student"] = self.student.id @@ -281,7 +135,7 @@ def test_obtain_student_evaluation_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data["grade"], 5) + self.assertEqual(response.data["grade"], 0) self.assertEqual(response.data["comment"], "Puede mejorar") response2 = self.client.get( @@ -303,7 +157,7 @@ def test_update_student_evaluation_by_educator(self): ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( - StudentEvaluation.objects.get().comment, "Mejoro tras la revision" + response.data["comment"], "Mejoro tras la revision" ) student_eval_forbid = StudentEvaluation.objects.create( diff --git a/nexong/api/Lesson/tests.py b/nexong/api/Lesson/tests.py index 6f70a030..85ec10fc 100644 --- a/nexong/api/Lesson/tests.py +++ b/nexong/api/Lesson/tests.py @@ -5,6 +5,8 @@ from rest_framework import status from rest_framework.authtoken.models import Token from rest_framework.test import APITestCase +from nexong.api.helpers.testsSetup import testSetupEducator + class AdminLessonApiViewSetTestCase(TestCase): def setUp(self): @@ -211,76 +213,41 @@ def test_delete_lesson_attendance_by_admin(self): class EducatorLessonApiViewSetTestCase(APITestCase): def setUp(self): - self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create( - birthdate="1969-06-09", description="EL profesor de lengua" - ) - self.factory = APIRequestFactory() - self.user = User.objects.create( - username="testuser", - email="example@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) - self.token = Token.objects.create(user=self.user) - self.education_center = EducationCenter.objects.create( - name="San Francisco Solano" - ) - self.student = Student.objects.create( - name="Amadeo", - surname="Portillo", - education_center=self.education_center, - is_morning_student=True, - activities_during_exit="", - status="ACEPTADO", - current_education_year="TRES AÑOS", - education_center_tutor="Don Carlos Perez", - nationality="Alemania", - birthdate="2015-04-21", - family=self.family, - ) - self.lesson = { - "name": "Primera Materia", - "description": "Módulo C, segunda planta", - "capacity": 50, - "is_morning_lesson": True, - "educator": self.educator, - "start_date": "2024-01-28", - "end_date": "2024-05-28", - } + testSetupEducator(self) + def test_create_lesson_by_educator(self): - self.lesson["educator"] = self.educator.id + self.lesson_data["educator"] = self.educator.id response = self.client.post( "/api/lesson/", - self.lesson, + self.lesson_data, format="multipart", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_obtain_lesson_by_educator(self): - lesson = Lesson.objects.create(**self.lesson) + lesson = Lesson.objects.create(**self.lesson_data) response = self.client.get( f"/api/lesson/{lesson.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data["name"], "Primera Materia") + self.assertEqual(response.data["name"], "Filosofia") def test_update_lesson_by_educator(self): - lesson = Lesson.objects.create(**self.lesson) - self.lesson["educator"] = self.educator.id - self.lesson["is_morning_lesson"] = False + lesson = Lesson.objects.create(**self.lesson_data) + self.lesson_data["educator"] = self.educator.id + self.lesson_data["is_morning_lesson"] = False response = self.client.put( f"/api/lesson/{lesson.id}/", - self.lesson, + self.lesson_data, HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_delete_lesson_by_educator(self): - lesson = Lesson.objects.create(**self.lesson) + lesson = Lesson.objects.create(**self.lesson_data) response = self.client.delete( f"/api/lesson/{lesson.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", @@ -290,94 +257,44 @@ def test_delete_lesson_by_educator(self): class EducatorLessonAttendanceApiViewSetTestCase(APITestCase): def setUp(self): - self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create( - birthdate="1969-06-09", description="EL profesor de lengua" - ) - self.factory = APIRequestFactory() - self.user = User.objects.create( - username="testuser", - email="example@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) - self.token = Token.objects.create(user=self.user) - self.education_center = EducationCenter.objects.create( - name="San Francisco Solano" - ) - self.student = Student.objects.create( - name="Amadeo", - surname="Portillo", - education_center=self.education_center, - is_morning_student=True, - activities_during_exit="", - status="ACEPTADO", - current_education_year="TRES AÑOS", - education_center_tutor="Don Carlos Perez", - nationality="Alemania", - birthdate="2015-04-21", - family=self.family, - ) - self.volunteer = Volunteer.objects.create( - academic_formation="Prueba Voluntario", - motivation="Test voluntario", - status="ACEPTADO", - address="Test voluntario address", - postal_code=12359, - birthdate="1956-07-05", - start_date="1955-07-05", - end_date="1956-07-05", - ) - self.lesson = Lesson.objects.create( - name="PRIMER Materia", - description="Módulo C, segunda planta", - capacity=50, - is_morning_lesson=True, - educator=self.educator, - start_date="2024-01-28", - end_date="2024-05-28", - ) - self.lessonAtendance = { - "date": "2024-01-28", - "lesson": self.lesson, - "volunteer": self.volunteer, - } + testSetupEducator(self) + def test_create_lessonAttendance_by_educator(self): - self.lessonAtendance["lesson"] = self.lesson.id - self.lessonAtendance["volunteer"] = self.volunteer.id + self.lessonAtendance_data["lesson"] = self.lesson.id + self.lessonAtendance_data["volunteer"] = self.volunteer.id response = self.client.post( "/api/lesson-attendance/", - self.lessonAtendance, + self.lessonAtendance_data, format="multipart", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_obtain_lessonAttendance_by_educator(self): - lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance) + lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance_data) response = self.client.get( f"/api/lesson-attendance/{lessonAttendance.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data["date"], "2024-01-28") + self.assertEqual(response.data["date"], "2024-02-23") def test_update_lessonAttendance_by_educator(self): - lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance) - self.lessonAtendance["lesson"] = self.lesson.id - self.lessonAtendance["volunteer"] = self.volunteer.id - self.lessonAtendance["date"] = "2024-01-20" + lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance_data) + self.lessonAtendance_data["lesson"] = self.lesson.id + self.lessonAtendance_data["volunteer"] = self.volunteer.id + self.lessonAtendance_data["date"] = "2024-01-20" response = self.client.put( f"/api/lesson-attendance/{lessonAttendance.id}/", - self.lessonAtendance, + self.lessonAtendance_data, HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_delete_lessonAttendance_by_educator(self): - lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance) + lessonAttendance = LessonAttendance.objects.create(**self.lessonAtendance_data) response = self.client.delete( f"/api/lesson-attendance/{lessonAttendance.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", diff --git a/nexong/api/Student/tests.py b/nexong/api/Student/tests.py index 23a0a244..40f878e0 100644 --- a/nexong/api/Student/tests.py +++ b/nexong/api/Student/tests.py @@ -1,77 +1,48 @@ from nexong.api.Authentication.views import * +from nexong.api.helpers.testsSetup import testSetupEducator from nexong.models import * -from rest_framework.authtoken.models import Token -from rest_framework.test import APIRequestFactory from rest_framework.test import APITestCase from rest_framework import status -from django.core.files.uploadedfile import SimpleUploadedFile class EducatorStudentApiViewSetTestCase(APITestCase): def setUp(self): - self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create( - birthdate="1969-06-09", description="EL profesor de lengua" - ) - self.factory = APIRequestFactory() - self.user = User.objects.create( - username="testuser", - email="example@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) - self.token = Token.objects.create(user=self.user) - self.education_center = EducationCenter.objects.create( - name="San Francisco Solano" - ) - self.student = { - "name": "Amadeo", - "surname": "Portillo", - "education_center": self.education_center, - "is_morning_student": True, - "activities_during_exit": "", - "status": "ACEPTADO", - "current_education_year": "TRES AÑOS", - "education_center_tutor": "Don Carlos Perez", - "nationality": "Alemania", - "birthdate": "2015-04-21", - "family": self.family, - } - + testSetupEducator(self) + def test_create_student_by_educator(self): - self.student["family"] = self.family.id - self.student["education_center"] = self.education_center.id + self.student_data["family"] = self.family.id + self.student_data["education_center"] = self.education_center.id response = self.client.post( "/api/student/", - self.student, + self.student_data, format="multipart", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_obtain_student_by_educator(self): - student = Student.objects.create(**self.student) + student = Student.objects.create(**self.student_data) response = self.client.get( f"/api/student/{student.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data["name"], "Amadeo") + self.assertEqual(response.data["name"], "Guillermo") def test_update_student_by_educator(self): - student = Student.objects.create(**self.student) - self.student["family"] = self.family.id - self.student["education_center"] = self.education_center.id - self.student["name"] = "Jose" + student = Student.objects.create(**self.student_data) + self.student_data["family"] = self.family.id + self.student_data["education_center"] = self.education_center.id + self.student_data["name"] = "Jose" response = self.client.put( f"/api/student/{student.id}/", - self.student, + self.student_data, HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_delete_student_by_educator(self): - student = Student.objects.create(**self.student) + student = Student.objects.create(**self.student_data) response = self.client.delete( f"/api/student/{student.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}", @@ -81,39 +52,7 @@ def test_delete_student_by_educator(self): class EducatorQuarterMArksApiViewSetTestCase(APITestCase): def setUp(self): - self.family = Family.objects.create(name="Los Pedraz") - self.educator = Educator.objects.create( - birthdate="1969-06-09", description="EL profesor de lengua" - ) - self.factory = APIRequestFactory() - self.user = User.objects.create( - username="testuser", - email="example@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) - self.token = Token.objects.create(user=self.user) - self.education_center = EducationCenter.objects.create( - name="San Francisco Solano" - ) - self.student = Student.objects.create( - name="Amadeo", - surname="Portillo", - education_center=self.education_center, - is_morning_student=True, - activities_during_exit="", - status="ACEPTADO", - current_education_year="TRES AÑOS", - education_center_tutor="Don Carlos Perez", - nationality="Alemania", - birthdate="2015-04-21", - family=self.family, - ) - self.quartermarks = {"date": "2024-03-21", "student": self.student} - file_content = b"Test file content" - self.quartermarks["marks"] = SimpleUploadedFile( - "student_marks.pdf", file_content - ) + testSetupEducator(self) def test_create_quarterMarks_by_educator(self): self.quartermarks["student"] = self.student.id @@ -132,7 +71,7 @@ def test_obtain_quarterMarks_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data["date"], "2024-03-21") + self.assertEqual(response.data["date"], "2024-03-05") def test_update_quarterMarks_by_educator(self): quartermarks = QuarterMarks.objects.create(**self.quartermarks) diff --git a/nexong/api/helpers/testsSetup.py b/nexong/api/helpers/testsSetup.py new file mode 100644 index 00000000..f7a78c2f --- /dev/null +++ b/nexong/api/helpers/testsSetup.py @@ -0,0 +1,186 @@ +from django.core.files.uploadedfile import SimpleUploadedFile +from nexong.models import * +from rest_framework.authtoken.models import Token +from rest_framework.test import APIRequestFactory + + +def testSetupEducator(self): + self.factory = APIRequestFactory() + self.educator_data = { + "description": "Test description", + "birthdate": "1969-06-09", + } + self.educator_error_desc = { + "description": "", + "birthdate": "1969-06-09", + } + self.educator_error_date = { + "description": "Test description", + "birthdate": "2069-06-09", + } + self.family = Family.objects.create(name="Los Morales del Valle") + self.educator = Educator.objects.create( + birthdate="1969-06-09", description="EL profesor de lengua de Manos abiertas" + ) + self.user = User.objects.create( + username="educatortestusernexong", + email="educatorone@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) + self.token = Token.objects.create(user=self.user) + self.educator2 = Educator.objects.create(birthdate="1969-03-21") + self.educator3 = Educator.objects.create(birthdate="1987-05-22") + self.education_center = EducationCenter.objects.create( + name="Virgen de la Pureza" + ) + self.student = Student.objects.create( + name="Luis", + surname="Morales", + education_center=self.education_center, + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="CUATRO AÑOS", + education_center_tutor="Don Joaquin Medina", + nationality="Frances", + birthdate="2015-04-21", + family=self.family, + ) + self.volunteer = Volunteer.objects.create( + academic_formation="Test Volunteer for educator", + motivation="volunteer motivation", + status="ACEPTADO", + address="Centro sevilla", + postal_code=13334, + birthdate="1976-07-05", + start_date="2001-02-08", + end_date="2008-07-09", + ) + self.lesson = Lesson.objects.create( + name="Lengua y literatura", + description="Clases de lengua de segundo de ESO", + capacity=20, + is_morning_lesson=True, + educator=self.educator, + start_date="2025-01-28", + end_date="2025-07-29", + ) + self.lesson_event = LessonEvent.objects.create( + name="Taller de manualidades", + description="Taller para los niños con los voluntarios", + place="Centro de Montequinto", + price=5, + max_volunteers=6, + start_date="2025-04-18 17:00-00:00", + end_date="2025-04-18 20:00-00:00", + lesson=self.lesson, + ) + self.center_exit = { + "student": self.student, + "is_authorized": True, + "lesson_event": self.lesson_event, + } + file_content = b"test for center exit authorization" + self.center_exit["authorization"] = SimpleUploadedFile( + "ce_authorization.pdf", file_content + ) + self.lesson_data = { + "name": "Filosofia", + "description": "Filosofia para los de cuarto de ESO", + "capacity": 20, + "is_morning_lesson": True, + "educator": self.educator, + "start_date": "2024-01-28", + "end_date": "2024-07-28", + } + self.lessonAtendance_data = { + "date": "2024-02-23", + "lesson": self.lesson, + "volunteer": self.volunteer, + } + self.quartermarks = {"date": "2024-03-05", "student": self.student} + file_content = b"Test content for quartermarks" + self.quartermarks["marks"] = SimpleUploadedFile( + "marks.pdf", file_content + ) + self.student_data = { + "name": "Guillermo", + "surname": "Morales", + "education_center": self.education_center, + "is_morning_student": True, + "activities_during_exit": "", + "status": "ACEPTADO", + "current_education_year": "CINCO AÑOS", + "education_center_tutor": "Reina Victoria", + "nationality": "Frances", + "birthdate": "2014-04-21", + "family": self.family, + } + self.lesson2 = Lesson.objects.create( + name="Plastica", + description="Manualidades para niños de cuatro años", + capacity=15, + is_morning_lesson=True, + educator=self.educator2, + start_date="2024-08-28", + end_date="2024-09-28", + ) + self.evaluation_type_data = { + "name": "Asistencia", + "description": "asitencia diaria", + "evaluation_type": "DIARIO", + "grade_system": "CERO A UNO", + "lesson": self.lesson, + } + self.evaluation_type_data_forbiden = { + "name": "Nota Lengua", + "description": "Puntuacion del alumno en lengua y literatura", + "evaluation_type": "ANUAL", + "grade_system": "CERO A DIEZ", + "lesson": self.lesson2, + } + self.evaluation_type_data_bad_request = { + "name": "", + "description": "Notas plastica", + "evaluation_type": "TRIMESTRAL", + "grade_system": "UNO A CINCO", + "lesson": self.lesson, + } + self.evaluation_type = EvaluationType.objects.create( + name="Asistencia", + description="asitencia diaria", + evaluation_type=DAILY, + grade_system=ZERO_TO_ONE, + lesson=self.lesson, + ) + self.evaluation_type2 = EvaluationType.objects.create( + name="Nota Lengua", + description="Puntuacion del alumno en lengua y literatura", + evaluation_type=ANNUAL, + grade_system=ZERO_TO_TEN, + lesson=self.lesson2, + ) + self.student_eval_data = { + "grade": 0, + "date": "2024-01-28", + "comment": "Puede mejorar", + "student": self.student, + "evaluation_type": self.evaluation_type, + } + self.student_eval_data_forbiden = { + "grade": 5, + "date": "2024-01-28", + "comment": "Suficiente", + "student": self.student, + "evaluation_type": self.evaluation_type2, + } + self.student_eval_data_bad_request = { + "grade": -1, + "date": "2024-01-28", + "comment": "No vino", + "student": self.student, + "evaluation_type": self.evaluation_type, + } + self.lesson.students.add(self.student) + self.lesson2.students.add(self.student) From efd4e57b198009bafb459275297d04048c004b2b Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Thu, 18 Apr 2024 23:07:27 +0000 Subject: [PATCH 7/8] refactor: Format code with Black --- nexong/api/Authentication/tests.py | 11 +- nexong/api/CenterExit/tests.py | 1 - nexong/api/Evaluation/test.py | 10 +- nexong/api/Lesson/tests.py | 5 +- nexong/api/Student/tests.py | 2 +- nexong/api/helpers/testsSetup.py | 290 ++++++++++++++--------------- 6 files changed, 155 insertions(+), 164 deletions(-) diff --git a/nexong/api/Authentication/tests.py b/nexong/api/Authentication/tests.py index 581d7f84..891f7871 100644 --- a/nexong/api/Authentication/tests.py +++ b/nexong/api/Authentication/tests.py @@ -8,11 +8,14 @@ from django.test import TestCase from nexong.api.helpers.testsSetup import testSetupEducator + class EducatorApiViewSetTestCase(APITestCase): def setUp(self): testSetupEducator(self) self.userAdmin = User.objects.create( - username="testAdminUserForEducator", email="exampleAdmin@outlook.com", role=ADMIN + username="testAdminUserForEducator", + email="exampleAdmin@outlook.com", + role=ADMIN, ) self.token2 = Token.objects.create(user=self.userAdmin) @@ -40,7 +43,7 @@ def test_create_educator(self): context2.exception.detail["non_field_errors"][0], "Birthdate can't be greater than today", ) - + count = Educator.objects.count() response = self.client.post( "/api/educator/", @@ -49,7 +52,7 @@ def test_create_educator(self): HTTP_AUTHORIZATION=f"Token {self.token2.key}", ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) - self.assertEqual(Educator.objects.count(), count+1) + self.assertEqual(Educator.objects.count(), count + 1) self.assertEqual(response.data["description"], "Test description") self.assertEqual(response.data["birthdate"], "1969-06-09") @@ -85,7 +88,7 @@ def test_delete_educator(self): HTTP_AUTHORIZATION=f"Token {self.token2.key}", ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) - self.assertEqual(Educator.objects.count(), count-1) + self.assertEqual(Educator.objects.count(), count - 1) class AdminUserApiViewSetTestCase(TestCase): diff --git a/nexong/api/CenterExit/tests.py b/nexong/api/CenterExit/tests.py index 3655bac0..a987f221 100644 --- a/nexong/api/CenterExit/tests.py +++ b/nexong/api/CenterExit/tests.py @@ -8,7 +8,6 @@ class EducatorCenterExitApiViewSetTestCase(APITestCase): def setUp(self): testSetupEducator(self) - def test_create_center_exit_by_educator(self): response = self.client.post( diff --git a/nexong/api/Evaluation/test.py b/nexong/api/Evaluation/test.py index ae55d483..71a4d852 100644 --- a/nexong/api/Evaluation/test.py +++ b/nexong/api/Evaluation/test.py @@ -5,12 +5,10 @@ from nexong.api.helpers.testsSetup import testSetupEducator - class EducatorEvaluationTypeTestCase(APITestCase): def setUp(self): testSetupEducator(self) - - + def test_create_evaluation_type_by_educator(self): self.evaluation_type_data["lesson"] = self.lesson.id self.evaluation_type_data_bad_request["lesson"] = self.lesson.id @@ -96,7 +94,7 @@ def test_delete_evaluation_type_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) - self.assertEqual(EvaluationType.objects.count(), count-1) + self.assertEqual(EvaluationType.objects.count(), count - 1) self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) @@ -156,9 +154,7 @@ def test_update_student_evaluation_by_educator(self): HTTP_AUTHORIZATION=f"Token {self.token.key}", ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual( - response.data["comment"], "Mejoro tras la revision" - ) + self.assertEqual(response.data["comment"], "Mejoro tras la revision") student_eval_forbid = StudentEvaluation.objects.create( **self.student_eval_data_forbiden diff --git a/nexong/api/Lesson/tests.py b/nexong/api/Lesson/tests.py index 541bc2df..6e562347 100644 --- a/nexong/api/Lesson/tests.py +++ b/nexong/api/Lesson/tests.py @@ -8,7 +8,6 @@ from nexong.api.helpers.testsSetup import testSetupEducator - class AdminLessonApiViewSetTestCase(TestCase): def setUp(self): self.factory = APIRequestFactory() @@ -214,8 +213,7 @@ def test_delete_lesson_attendance_by_admin(self): class EducatorLessonApiViewSetTestCase(APITestCase): def setUp(self): - testSetupEducator(self) - + testSetupEducator(self) def test_create_lesson_by_educator(self): self.lesson_data["educator"] = self.educator.id @@ -259,7 +257,6 @@ def test_delete_lesson_by_educator(self): class EducatorLessonAttendanceApiViewSetTestCase(APITestCase): def setUp(self): testSetupEducator(self) - def test_create_lessonAttendance_by_educator(self): self.lessonAtendance_data["lesson"] = self.lesson.id diff --git a/nexong/api/Student/tests.py b/nexong/api/Student/tests.py index 40f878e0..a2cdaf81 100644 --- a/nexong/api/Student/tests.py +++ b/nexong/api/Student/tests.py @@ -8,7 +8,7 @@ class EducatorStudentApiViewSetTestCase(APITestCase): def setUp(self): testSetupEducator(self) - + def test_create_student_by_educator(self): self.student_data["family"] = self.family.id self.student_data["education_center"] = self.education_center.id diff --git a/nexong/api/helpers/testsSetup.py b/nexong/api/helpers/testsSetup.py index f7a78c2f..61915f00 100644 --- a/nexong/api/helpers/testsSetup.py +++ b/nexong/api/helpers/testsSetup.py @@ -7,180 +7,176 @@ def testSetupEducator(self): self.factory = APIRequestFactory() self.educator_data = { - "description": "Test description", - "birthdate": "1969-06-09", - } + "description": "Test description", + "birthdate": "1969-06-09", + } self.educator_error_desc = { - "description": "", - "birthdate": "1969-06-09", - } + "description": "", + "birthdate": "1969-06-09", + } self.educator_error_date = { - "description": "Test description", - "birthdate": "2069-06-09", - } + "description": "Test description", + "birthdate": "2069-06-09", + } self.family = Family.objects.create(name="Los Morales del Valle") self.educator = Educator.objects.create( - birthdate="1969-06-09", description="EL profesor de lengua de Manos abiertas" - ) + birthdate="1969-06-09", description="EL profesor de lengua de Manos abiertas" + ) self.user = User.objects.create( - username="educatortestusernexong", - email="educatorone@gmail.com", - role=EDUCATOR, - educator=self.educator, - ) + username="educatortestusernexong", + email="educatorone@gmail.com", + role=EDUCATOR, + educator=self.educator, + ) self.token = Token.objects.create(user=self.user) self.educator2 = Educator.objects.create(birthdate="1969-03-21") self.educator3 = Educator.objects.create(birthdate="1987-05-22") - self.education_center = EducationCenter.objects.create( - name="Virgen de la Pureza" - ) + self.education_center = EducationCenter.objects.create(name="Virgen de la Pureza") self.student = Student.objects.create( - name="Luis", - surname="Morales", - education_center=self.education_center, - is_morning_student=True, - activities_during_exit="", - status="ACEPTADO", - current_education_year="CUATRO AÑOS", - education_center_tutor="Don Joaquin Medina", - nationality="Frances", - birthdate="2015-04-21", - family=self.family, - ) + name="Luis", + surname="Morales", + education_center=self.education_center, + is_morning_student=True, + activities_during_exit="", + status="ACEPTADO", + current_education_year="CUATRO AÑOS", + education_center_tutor="Don Joaquin Medina", + nationality="Frances", + birthdate="2015-04-21", + family=self.family, + ) self.volunteer = Volunteer.objects.create( - academic_formation="Test Volunteer for educator", - motivation="volunteer motivation", - status="ACEPTADO", - address="Centro sevilla", - postal_code=13334, - birthdate="1976-07-05", - start_date="2001-02-08", - end_date="2008-07-09", - ) + academic_formation="Test Volunteer for educator", + motivation="volunteer motivation", + status="ACEPTADO", + address="Centro sevilla", + postal_code=13334, + birthdate="1976-07-05", + start_date="2001-02-08", + end_date="2008-07-09", + ) self.lesson = Lesson.objects.create( - name="Lengua y literatura", - description="Clases de lengua de segundo de ESO", - capacity=20, - is_morning_lesson=True, - educator=self.educator, - start_date="2025-01-28", - end_date="2025-07-29", - ) + name="Lengua y literatura", + description="Clases de lengua de segundo de ESO", + capacity=20, + is_morning_lesson=True, + educator=self.educator, + start_date="2025-01-28", + end_date="2025-07-29", + ) self.lesson_event = LessonEvent.objects.create( - name="Taller de manualidades", - description="Taller para los niños con los voluntarios", - place="Centro de Montequinto", - price=5, - max_volunteers=6, - start_date="2025-04-18 17:00-00:00", - end_date="2025-04-18 20:00-00:00", - lesson=self.lesson, - ) + name="Taller de manualidades", + description="Taller para los niños con los voluntarios", + place="Centro de Montequinto", + price=5, + max_volunteers=6, + start_date="2025-04-18 17:00-00:00", + end_date="2025-04-18 20:00-00:00", + lesson=self.lesson, + ) self.center_exit = { - "student": self.student, - "is_authorized": True, - "lesson_event": self.lesson_event, - } + "student": self.student, + "is_authorized": True, + "lesson_event": self.lesson_event, + } file_content = b"test for center exit authorization" self.center_exit["authorization"] = SimpleUploadedFile( - "ce_authorization.pdf", file_content - ) + "ce_authorization.pdf", file_content + ) self.lesson_data = { - "name": "Filosofia", - "description": "Filosofia para los de cuarto de ESO", - "capacity": 20, - "is_morning_lesson": True, - "educator": self.educator, - "start_date": "2024-01-28", - "end_date": "2024-07-28", - } + "name": "Filosofia", + "description": "Filosofia para los de cuarto de ESO", + "capacity": 20, + "is_morning_lesson": True, + "educator": self.educator, + "start_date": "2024-01-28", + "end_date": "2024-07-28", + } self.lessonAtendance_data = { - "date": "2024-02-23", - "lesson": self.lesson, - "volunteer": self.volunteer, - } + "date": "2024-02-23", + "lesson": self.lesson, + "volunteer": self.volunteer, + } self.quartermarks = {"date": "2024-03-05", "student": self.student} file_content = b"Test content for quartermarks" - self.quartermarks["marks"] = SimpleUploadedFile( - "marks.pdf", file_content - ) + self.quartermarks["marks"] = SimpleUploadedFile("marks.pdf", file_content) self.student_data = { - "name": "Guillermo", - "surname": "Morales", - "education_center": self.education_center, - "is_morning_student": True, - "activities_during_exit": "", - "status": "ACEPTADO", - "current_education_year": "CINCO AÑOS", - "education_center_tutor": "Reina Victoria", - "nationality": "Frances", - "birthdate": "2014-04-21", - "family": self.family, - } + "name": "Guillermo", + "surname": "Morales", + "education_center": self.education_center, + "is_morning_student": True, + "activities_during_exit": "", + "status": "ACEPTADO", + "current_education_year": "CINCO AÑOS", + "education_center_tutor": "Reina Victoria", + "nationality": "Frances", + "birthdate": "2014-04-21", + "family": self.family, + } self.lesson2 = Lesson.objects.create( - name="Plastica", - description="Manualidades para niños de cuatro años", - capacity=15, - is_morning_lesson=True, - educator=self.educator2, - start_date="2024-08-28", - end_date="2024-09-28", - ) + name="Plastica", + description="Manualidades para niños de cuatro años", + capacity=15, + is_morning_lesson=True, + educator=self.educator2, + start_date="2024-08-28", + end_date="2024-09-28", + ) self.evaluation_type_data = { - "name": "Asistencia", - "description": "asitencia diaria", - "evaluation_type": "DIARIO", - "grade_system": "CERO A UNO", - "lesson": self.lesson, - } + "name": "Asistencia", + "description": "asitencia diaria", + "evaluation_type": "DIARIO", + "grade_system": "CERO A UNO", + "lesson": self.lesson, + } self.evaluation_type_data_forbiden = { - "name": "Nota Lengua", - "description": "Puntuacion del alumno en lengua y literatura", - "evaluation_type": "ANUAL", - "grade_system": "CERO A DIEZ", - "lesson": self.lesson2, - } + "name": "Nota Lengua", + "description": "Puntuacion del alumno en lengua y literatura", + "evaluation_type": "ANUAL", + "grade_system": "CERO A DIEZ", + "lesson": self.lesson2, + } self.evaluation_type_data_bad_request = { - "name": "", - "description": "Notas plastica", - "evaluation_type": "TRIMESTRAL", - "grade_system": "UNO A CINCO", - "lesson": self.lesson, - } + "name": "", + "description": "Notas plastica", + "evaluation_type": "TRIMESTRAL", + "grade_system": "UNO A CINCO", + "lesson": self.lesson, + } self.evaluation_type = EvaluationType.objects.create( - name="Asistencia", - description="asitencia diaria", - evaluation_type=DAILY, - grade_system=ZERO_TO_ONE, - lesson=self.lesson, - ) + name="Asistencia", + description="asitencia diaria", + evaluation_type=DAILY, + grade_system=ZERO_TO_ONE, + lesson=self.lesson, + ) self.evaluation_type2 = EvaluationType.objects.create( - name="Nota Lengua", - description="Puntuacion del alumno en lengua y literatura", - evaluation_type=ANNUAL, - grade_system=ZERO_TO_TEN, - lesson=self.lesson2, - ) + name="Nota Lengua", + description="Puntuacion del alumno en lengua y literatura", + evaluation_type=ANNUAL, + grade_system=ZERO_TO_TEN, + lesson=self.lesson2, + ) self.student_eval_data = { - "grade": 0, - "date": "2024-01-28", - "comment": "Puede mejorar", - "student": self.student, - "evaluation_type": self.evaluation_type, - } + "grade": 0, + "date": "2024-01-28", + "comment": "Puede mejorar", + "student": self.student, + "evaluation_type": self.evaluation_type, + } self.student_eval_data_forbiden = { - "grade": 5, - "date": "2024-01-28", - "comment": "Suficiente", - "student": self.student, - "evaluation_type": self.evaluation_type2, - } + "grade": 5, + "date": "2024-01-28", + "comment": "Suficiente", + "student": self.student, + "evaluation_type": self.evaluation_type2, + } self.student_eval_data_bad_request = { - "grade": -1, - "date": "2024-01-28", - "comment": "No vino", - "student": self.student, - "evaluation_type": self.evaluation_type, - } + "grade": -1, + "date": "2024-01-28", + "comment": "No vino", + "student": self.student, + "evaluation_type": self.evaluation_type, + } self.lesson.students.add(self.student) - self.lesson2.students.add(self.student) + self.lesson2.students.add(self.student) From 20422917af9a6a07684e45599fad1033086e6175 Mon Sep 17 00:00:00 2001 From: JuanluRM Date: Sat, 20 Apr 2024 11:17:13 +0000 Subject: [PATCH 8/8] refactor: Format code with Black --- nexong/api/CenterExit/tests.py | 1 + nexong/api/Evaluation/tests.py | 1 + nexong/api/Student/tests.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/nexong/api/CenterExit/tests.py b/nexong/api/CenterExit/tests.py index 699f0358..a19890f0 100644 --- a/nexong/api/CenterExit/tests.py +++ b/nexong/api/CenterExit/tests.py @@ -156,6 +156,7 @@ def test_delete_center_authorization(self): self.assertEqual(response.status_code, 204) self.assertEqual(CenterExitAuthorization.objects.count(), initial_count - 1) + class EducatorCenterExitApiViewSetTestCase(APITestCase): def setUp(self): testSetupEducator(self) diff --git a/nexong/api/Evaluation/tests.py b/nexong/api/Evaluation/tests.py index 041271f3..1091accd 100644 --- a/nexong/api/Evaluation/tests.py +++ b/nexong/api/Evaluation/tests.py @@ -195,6 +195,7 @@ def test_delete_student_evaluation_by_educator(self): self.assertEqual(StudentEvaluation.objects.count(), 1) self.assertEqual(response2.status_code, status.HTTP_403_FORBIDDEN) + class Student_Evaluation_ApiViewSetTestCase(TestCase): def setUp(self): self.factory = APIRequestFactory() diff --git a/nexong/api/Student/tests.py b/nexong/api/Student/tests.py index 263ca904..9b97bdd5 100644 --- a/nexong/api/Student/tests.py +++ b/nexong/api/Student/tests.py @@ -9,7 +9,6 @@ from rest_framework.test import APITestCase - def add_files_to_student_data(self): file_content = b"Test file content" # Content of the file self.student_data["enrollment_document"] = SimpleUploadedFile( @@ -438,6 +437,7 @@ def test_delete_quater_authorization_family(self): ) self.assertEqual(response.status_code, 204) + class EducatorStudentApiViewSetTestCase(APITestCase): def setUp(self): testSetupEducator(self)