Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: creating mcdc tests to get_current_year_and_period method #226

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion api/utils/schedule_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _make_disciplines_list(self) -> None:

for classes in self.disciplines.values():
self.disciplines_list.append(classes)

def _handle_conflict(self, conflicting_class: Class, schedule: tuple) -> None:
# Depois, verificamos se há uma grade horária válida sem a disciplina atual
schedule_valid = self._valid_schedule(schedule, conflicting_class)
Expand Down Expand Up @@ -239,3 +239,12 @@ def sort_by_priority(self):
lambda _class: self.schedule_info[_class.schedule]["priority"], priority)), reverse=True)

return self.schedules

def test_discipline_hour(self, discipline: str, hours: dict[str], departaments: dict[str], choice_disciplines: dict[str]):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_discipline_hour has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.

for key, values in departaments.items():
for key_hours, values_hours in hours.items():
for key_ch, values_ch in choice_disciplines.items():
if discipline == values and values == key_hours and values_hours == key_ch:
return values_ch


11 changes: 11 additions & 0 deletions api/utils/tests/test_discipline_hour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from itertools import product
from collections import defaultdict, Counter
from ..db_handler import get_class_by_id
from re import search
from api.models import Class
from schedule_generator import discipline_hour

class Test_discipline:
"""Esse Teste ainda não passa, pois é necessário passar parametros dentro dos dicionarios na função principal"""
def test_discipline_hour(self):
self.AssertEqual(discipline_hour("MD2", {"10:45":"MD2", "11:00":"FSO"}, {"Matematica":"10:45", "Sistemas Operacionais": "11:00"}, {"MD2":"Matematica Discreta 2", "FSO":"Fundamentos de Sistemas Operacionais"}, "Matematica Discreta 2"))
63 changes: 63 additions & 0 deletions api/utils/tests/test_generator_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from rest_framework.test import APITestCase
from utils import sessions as sns
from datetime import datetime

class TestGeneratorDate(APITestCase):

def test_valid_generator_date(self):
# Testando datas válidas que devem retornar período "1"
list_dates = [
datetime(2024, 1, 1),
datetime(2024, 2, 1),
datetime(2024, 3, 1),
datetime(2024, 4, 1)
]

for date in list_dates:
year, period = sns.get_current_year_and_period(date)
self.assertEqual("2024", year)
self.assertEqual("1", period)

def test_valid_generator_date_period_2(self):
# Testando datas válidas que devem retornar período "2"
list_dates_period_2 = [
datetime(2024, 5, 2),
datetime(2024, 6, 1),
datetime(2024, 10, 1),
datetime(2024, 12, 31),
datetime(2025, 1, 1)
]

for date in list_dates_period_2:
year, period = sns.get_current_year_and_period(date)
self.assertEqual("2024", year)
self.assertEqual("2", period)

def test_generator_date_none(self):
# Testando o caso onde a data é None
year, period = sns.get_current_year_and_period(None)
expected_year = str(datetime.now().year)
if datetime.now() >= datetime(datetime.now().year, 5, 2):
expected_period = "2"
else:
expected_period = "1"
self.assertEqual(expected_year, year)
self.assertEqual(expected_period, period)

def test_invalid_generator_date(self):
# Testando datas que não devem estar no período "2"
list_dates_invalid = [
datetime(2024, 5, 1),
datetime(2025, 1, 2),
datetime(2024, 4, 30)
]

for date in list_dates_invalid:
year, period = sns.get_current_year_and_period(date)
if date.year == 2025:
self.assertEqual("2025", year)
else:
self.assertEqual("2024", year)
self.assertEqual("1", period)