-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from unb-mds/task/schedule
task(schedule): Cria o algoritmo de geração de matérias
- Loading branch information
Showing
8 changed files
with
596 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
from rest_framework.serializers import ModelSerializer | ||
from api.models import Department, Discipline, Class | ||
|
||
|
||
class DepartmentSerializer(ModelSerializer): | ||
class Meta: | ||
model = Department | ||
fields = '__all__' | ||
|
||
|
||
class ClassSerializer(ModelSerializer): | ||
class Meta: | ||
model = Class | ||
fields = '__all__' | ||
|
||
class DisciplineSerializer(ModelSerializer): | ||
department = DepartmentSerializer() | ||
classes = ClassSerializer(many=True) | ||
|
||
|
||
class DisciplineSerializerSchedule(ModelSerializer): | ||
class Meta: | ||
model = Discipline | ||
fields = '__all__' | ||
fields = '__all__' | ||
|
||
|
||
class DisciplineSerializer(DisciplineSerializerSchedule): | ||
department = DepartmentSerializer() | ||
classes = ClassSerializer(many=True) | ||
|
||
|
||
class ClassSerializerSchedule(ClassSerializer): | ||
discipline = DisciplineSerializerSchedule() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from rest_framework.test import APITestCase, APIRequestFactory | ||
from utils.db_handler import get_or_create_department, get_or_create_discipline, create_class | ||
from random import randint | ||
import json | ||
|
||
class TestScheduleAPI(APITestCase): | ||
def setUp(self): | ||
self.factory = APIRequestFactory() | ||
self.content_type = 'application/json' | ||
self.api_url = '/courses/schedule/' | ||
self.department = get_or_create_department( | ||
code='518', year='2023', period='2') | ||
self.discipline = get_or_create_discipline( | ||
name='CÁLCULO 1', code='MAT518', department=self.department) | ||
self.class_1 = create_class(teachers=['RICARDO FRAGELLI'], classroom='S9', schedule='46M34', days=[ | ||
'Quarta-Feira 10:00 às 11:50', 'Sexta-Feira 10:00 às 11:50'], _class="1", special_dates=[], discipline=self.discipline) | ||
self.class_2 = create_class(teachers=['VINICIUS RISPOLI'], classroom='S1', schedule='24M34', days=[ | ||
'Segunda-Feira 10:00 às 11:50', 'Quarta-Feira 10:00 às 11:50'], _class="2", special_dates=[], discipline=self.discipline) | ||
self.discipline_2 = get_or_create_discipline( | ||
name='CÁLCULO 2', code='MAT519', department=self.department) | ||
self.class_3 = create_class(teachers=['LUIZA YOKO'], classroom='S1', schedule='56M23', days=[ | ||
'Segunda-Feira 10:00 às 11:50', 'Quarta-Feira 10:00 às 11:50'], _class="1", special_dates=[], discipline=self.discipline_2) | ||
self.class_4 = create_class(teachers=['Tatiana'], classroom='S1', schedule='7M1234', days=[ | ||
'Sábado 08:00 às 11:50'], _class="2", special_dates=[], discipline=self.discipline_2) | ||
|
||
def test_with_correct_parameters(self): | ||
""" | ||
Testa a geração de horários com todos os parâmetros corretos | ||
Os parâmetros enviados permitem que pelo menos uma solução seja encontrada | ||
""" | ||
body = json.dumps({ | ||
'preference': [3, 2, 1], | ||
'classes': [self.class_1.id, self.class_2.id, self.class_3.id, self.class_4.id] | ||
}) | ||
|
||
response = self.client.post(self.api_url, body, content_type=self.content_type) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue(len(response.data) > 0) | ||
|
||
def test_with_conflicting_classes(self): | ||
""" | ||
Testa a geração de horários com classes conflitantes | ||
""" | ||
body = json.dumps({ | ||
'preference': [3, 2, 1], | ||
'classes': [self.class_1.id, self.class_3.id] | ||
}) | ||
|
||
response = self.client.post(self.api_url, body, content_type=self.content_type) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(len(response.data)) | ||
|
||
def test_with_invalid_class(self): | ||
""" | ||
Testa a geração de horários com uma classe inválida | ||
""" | ||
|
||
classes_ids = [self.class_1.id, self.class_2.id, self.class_3.id, self.class_4.id] | ||
random_id = randint(1, 10000) | ||
|
||
while(random_id in classes_ids): # pragma: no cover | ||
random_id = randint(1, 10000) | ||
|
||
body = json.dumps({ | ||
'preference': [3, 2, 1], | ||
'classes': classes_ids + [random_id] | ||
}) | ||
|
||
response = self.client.post(self.api_url, body, content_type=self.content_type) | ||
|
||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_with_invalid_preference(self): | ||
""" | ||
Testa a geração de horários com uma preferência inválida | ||
""" | ||
body = json.dumps({ | ||
'preference': [3, 2, 1, 4], | ||
'classes': [self.class_1.id, self.class_2.id, self.class_3.id, self.class_4.id] | ||
}) | ||
|
||
response = self.client.post(self.api_url, body, content_type=self.content_type) | ||
|
||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_with_invalid_preference_type(self): | ||
""" | ||
Testa a geração de horários com uma preferência inválida (tipo) | ||
""" | ||
body = json.dumps({ | ||
'preference': [3, 2, '1'], | ||
'classes': [self.class_1.id, self.class_2.id, self.class_3.id, self.class_4.id] | ||
}) | ||
|
||
response = self.client.post(self.api_url, body, content_type=self.content_type) | ||
|
||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_with_no_classes(self): | ||
""" | ||
Testa a geração de horários sem classes | ||
""" | ||
body = json.dumps({ | ||
'classes': [] | ||
}) | ||
|
||
response = self.client.post(self.api_url, body, content_type=self.content_type) | ||
|
||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_with_no_preference(self): | ||
""" | ||
Testa a geração de horários sem preferência | ||
""" | ||
body = json.dumps({ | ||
'classes': [self.class_1.id] | ||
}) | ||
|
||
response = self.client.post(self.api_url, body, content_type=self.content_type) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue(len(response.data) > 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.