Skip to content

Commit

Permalink
Merge pull request #144 from ISPP-G5/feature/139-tests-for-partner
Browse files Browse the repository at this point in the history
feature/139-tests-for-partner
  • Loading branch information
auroranavas authored May 6, 2024
2 parents e6e0334 + 9c7e514 commit 509b087
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 10 deletions.
58 changes: 48 additions & 10 deletions nexong/api/Authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def setUp(self):
"birthdate": "1956-07-05",
"start_date": "1956-07-05",
}
self.volunteer2 = Volunteer.objects.create(**self.volunteer_data)
self.user2 = User.objects.create(
self.volunteer3 = Volunteer.objects.create(**self.volunteer_data)
self.user3 = User.objects.create(
username="testuser",
email="example@gmail.com",
role=VOLUNTEER,
volunteer=self.volunteer2,
volunteer=self.volunteer3,
)
self.token = Token.objects.create(user=self.user2)
self.token = Token.objects.create(user=self.user3)

def test_create_volunteer(self):
add_files_to_volunteer_data(self)
Expand All @@ -65,28 +65,25 @@ def test_create_volunteer(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_retrieve_volunteer(self):
volunteer = Volunteer.objects.create(**self.volunteer_data)
response = self.client.get(
f"/api/volunteer/{volunteer.id}/",
f"/api/volunteer/{self.volunteer3.id}/",
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_update_volunteer(self):
volunteer = Volunteer.objects.create(**self.volunteer_data)
add_files_to_volunteer_data(self)
self.volunteer_data["academic_formation"] = "Updated formation"
response = self.client.put(
f"/api/volunteer/{volunteer.id}/",
f"/api/volunteer/{self.volunteer3.id}/",
self.volunteer_data,
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_delete_volunteer(self):
volunteer = Volunteer.objects.create(**self.volunteer_data)
response = self.client.delete(
f"/api/volunteer/{volunteer.id}/",
f"/api/volunteer/{self.volunteer3.id}/",
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Expand Down Expand Up @@ -379,3 +376,44 @@ def test_delete_education_center_error_by_admin(self):
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, 204)


class PartnerApiViewSetTestCase(TestCase):
def setUp(self):
self.factory = APIRequestFactory()
self.partner = Partner.objects.create(
address="789 Oak St", birthdate="2000-10-10", description="MONDONGO"
)
self.user = User.objects.create(
username="testuser",
email="example2@gmail.com",
role=PARTNER,
partner=self.partner,
)
self.token = Token.objects.create(user=self.user)

def test_update_partner(self):
partner = Partner.objects.create(address="789 Oak St", birthdate="2000-10-10")
response = self.client.put(
f"/api/partner/{partner.id}/",
data={
"id": partner.id,
"address": "789 Oak St",
"enrollment_document": None,
"description": "Mondongo",
"birthdate": "2000-10-10",
},
content_type="application/json",
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, 200)
partner.refresh_from_db()

def test_delete_partner(self):
partner = Partner.objects.create(address="321 Maple St", birthdate="1970-12-12")
initial_count = Partner.objects.count()
response = self.client.delete(
f"/api/partner/{partner.id}/", HTTP_AUTHORIZATION=f"Token {self.token.key}"
)
self.assertEqual(response.status_code, 204)
self.assertEqual(Partner.objects.count(), initial_count - 1)
52 changes: 52 additions & 0 deletions nexong/api/Donation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,55 @@ def test_create_donations_by_admin(self):
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)


class PartnerDonationApiViewSetTestCase(TestCase):
def setUp(self):
self.factory = APIRequestFactory()
self.partner2 = Partner.objects.create(
description="testdeprueba2", address="333 Elm St", birthdate="1996-05-05"
)
self.user2 = User.objects.create(
username="testuser",
email="example2@gmail.com",
role=PARTNER,
partner=self.partner2,
)
self.token2 = Token.objects.create(user=self.user2)
self.donation2 = Donation.objects.create(
iban="ES8004875667823641839785",
quantity="1054.00",
frequency="SEMESTRAL",
holder="Keko jones",
date="2024-01-22",
partner=self.partner2,
)

def test_get_donations_by_partner(self):
response = self.client.get(
f"/api/donation/{self.donation2.id}/",
HTTP_AUTHORIZATION=f"Token {self.token2.key}",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_create_donations_by_partner(self):
response = self.client.post(
f"/api/donation/",
data={
"iban": "ES3304875667823641839785",
"quantity": "1065",
"frequency": "SEMESTRAL",
"holder": "Paco Jones",
"date": "2025-01-23",
"partner": self.partner2.id,
},
HTTP_AUTHORIZATION=f"Token {self.token2.key}",
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_delete_donations_by_partner_error(self):
response = self.client.delete(
f"/api/donation/{self.donation2.id}/",
HTTP_AUTHORIZATION=f"Token {self.token2.key}",
)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
118 changes: 118 additions & 0 deletions nexong/api/Event/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,3 +776,121 @@ def test_update_lesson_event_by_volunteer(self):
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.lessonevent2.refresh_from_db()


class PartnerEventApiViewSetTestCase(TestCase):
def setUp(self):
self.factory = APIRequestFactory()
self.partner3 = Partner.objects.create(
description="testdeprueba22", address="333 Elm St", birthdate="1996-05-05"
)
self.family2 = Family.objects.create(name="Familia Pedriza")
self.education_center2 = EducationCenter.objects.create(
name="San Francisco Pelano"
)
self.educator2 = Educator.objects.create(
description="testdeprueba4", birthdate="2000-04-22"
)
self.educator3 = Educator.objects.create(
description="testdeprueba5", birthdate="2001-06-21"
)
self.user2 = User.objects.create(
username="usuariotest",
email="usuariotets@gmail.com",
role=PARTNER,
partner=self.partner3,
)

self.token = Token.objects.create(user=self.user2)

self.student = Student.objects.create(
name="José Manuela",
surname="Colino",
education_center=self.education_center2,
is_morning_student=False,
activities_during_exit="",
status="PENDIENTE",
current_education_year="TRES AÑOS",
education_center_tutor="Don Pedro Picapiedra",
nationality="Británico",
birthdate="2017-04-21",
family=self.family2,
)
self.student2 = Student.objects.create(
name="Antonio",
surname="Garcia",
education_center=self.education_center2,
is_morning_student=True,
activities_during_exit="",
status="PENDIENTE",
current_education_year="TRES AÑOS",
education_center_tutor="Gaiskas",
nationality="España",
birthdate="2015-04-21",
family=self.family2,
)

self.voluntario = Volunteer.objects.create(
academic_formation="Test partner",
motivation="Test partneer",
status="PENDIENTE",
address="Test address3",
postal_code=12350,
birthdate="1956-07-06",
start_date="1956-07-06",
end_date="1956-07-07",
)
self.voluntario2 = Volunteer.objects.create(
academic_formation="Test formation7",
motivation="Test motivation7",
status="ACEPTADO",
address="Test address8",
postal_code=12349,
birthdate="1956-07-05",
start_date="1956-07-05",
end_date="1956-07-05",
)

self.event2 = Event.objects.create(
name="Feria noseque",
description="Se necesitan 2 camareros para atenderlos",
place="Cacharritos",
max_volunteers=2,
max_attendees=2,
price=5,
start_date="2024-06-13 06:00-00:00",
end_date="2024-06-13 11:00-00:00",
)
self.event2.attendees.add(self.student, self.student2)
self.event2.volunteers.add(self.voluntario, self.voluntario2)

def test_obtain_event_by_partner(self):
response = self.client.get(
f"/api/event/{self.event2.id}/",
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_create_event_by_partner_error(self):
attendees_ids1 = [self.student.id, self.student2.id]
volunteers_ids1 = [
self.voluntario.id,
self.voluntario2.id,
] # Asegurarse de que se esté pasando el ID del voluntario
response = self.client.post(
"/api/event/",
data={
"name": "Viene la familia Peruana",
"description": "Se necesitan gente",
"place": "La cocina",
"max_volunteers": 2,
"max_attendees": 2,
"price": 5,
"start_date": "2025-06-12T06:00:00Z",
"end_date": "2025-06-12T11:00:00Z",
"attendees": attendees_ids1,
"volunteers": volunteers_ids1,
},
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
71 changes: 71 additions & 0 deletions nexong/api/Meeting/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,74 @@ def test_delete_donations_by_admin(self):
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)


class PartnerMeetingApiViewSetTestCase(TestCase):
def setUp(self):
self.factory = APIRequestFactory()
self.partner3 = Partner.objects.create(
description="testdeprueba8", address="333 Elm St", birthdate="1996-05-05"
)
self.user2 = User.objects.create(
username="testuser",
email="example1@gmail.com",
role=PARTNER,
partner=self.partner3,
)
self.token = Token.objects.create(user=self.user2)

self.partner4 = Partner.objects.create(
description="testdeprueba10",
address="333 Elmlos St",
birthdate="1997-05-05",
)
self.meeting2 = Meeting.objects.create(
name="Papi", description="Chulo", date="2025-01-22", time="17:50-00:00"
)
self.meeting2.attendees.add(self.partner3, self.partner4)

def test_obtain_meeting_by_partner(self):
response = self.client.get(
f"/api/meeting/{self.meeting2.id}/",
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_update_meeting_by_partner(self):
attendees_ids = [self.partner3.id, self.partner4.id]
response = self.client.put(
f"/api/meeting/{self.meeting2.id}/",
data={
"name": "Prueba Update meeting",
"description": "Prueba Update meeting",
"date": "2025-01-22",
"time": "17:50-00:00",
"attendees": attendees_ids,
"url": f"http://localhost:8000/api/meeting/{self.meeting2.id}/",
},
content_type="application/json",
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_create_meeting_by_partner(self):
attendees_ids = [self.partner3.id, self.partner4.id]
response = self.client.post(
f"/api/meeting/",
data={
"name": "Prueba3",
"description": "Prueba meeting3",
"date": "2025-01-22",
"time": "17:50-00:00",
"attendees": attendees_ids,
},
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_delete_meeting_by_partner(self):
response = self.client.delete(
f"/api/meeting/{self.meeting2.id}/",
HTTP_AUTHORIZATION=f"Token {self.token.key}",
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

0 comments on commit 509b087

Please sign in to comment.