aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2018-01-27 19:28:37 +0100
committerAlban Gruin2018-01-27 20:03:07 +0100
commit661fbb63d8f6e3607e7449b25f45613a08a1c6bb (patch)
treee2820130a1da96f7ccf934edace189eaa931252b
parent0838f8a7ab0863c8e1cd277a4dd7de62ba61b5f4 (diff)
Création des tests de la requête de QSJPS
On y créée sept salles, avec différents agencements de cours : 0. Le cours se finit dans l’intervalle sélectionné 1. Le cours se commence dans l’intervalle 2. Combinaison de 0. et de 1. 3. Le cours commence avant et fini après l’intervalle 4. Le cours commence et fini pendant l’intervalle 5. Un cours se finit avant et un autre commence après 6. Aucun cours liste des salles. Normalement, seules les salles des cas cinq et six doivent se retrouver dans la liste des salles.
-rw-r--r--models.py7
-rw-r--r--tests.py65
2 files changed, 71 insertions, 1 deletions
diff --git a/models.py b/models.py
index 9f36a6f..1a638ac 100644
--- a/models.py
+++ b/models.py
@@ -160,7 +160,14 @@ class Group(SlugModel):
verbose_name_plural = "groupes"
+class RoomManager(Manager):
+ def qsjps(self, begin, end):
+ return None
+
+
class Room(SlugModel):
+ objects = RoomManager()
+
name = models.CharField(max_length=255, unique=True, verbose_name="nom")
slug = models.SlugField(max_length=64, default="", unique=True)
diff --git a/tests.py b/tests.py
index e671973..d19203e 100644
--- a/tests.py
+++ b/tests.py
@@ -14,9 +14,13 @@
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
from django.test import TestCase
-from .models import Course, Group, Source, Timetable, Year
+from django.utils import timezone
+
+from .models import Course, Group, Room, Source, Timetable, Year
from .utils import tz_now
+import datetime
+
class CourseTestCase(TestCase):
def setUp(self):
@@ -200,3 +204,62 @@ class GroupTestCase(TestCase):
self.assertEqual(tpb21.group_info, ("L1 info", 2, "B21"))
self.assertEqual(general.group_info, ("L1 info", None, ""))
+
+
+class RoomTestCase(TestCase):
+ def setUp(self):
+ self.day = datetime.datetime(year=2018, month=1, day=27)
+
+ self.year = Year.objects.create(name="L1")
+ self.source = Source.objects.create(url="http://example.org/")
+
+ # Pas besoin de créer plus de groupes que ça, ni de le rendre
+ # global
+ group = Group.objects.create(celcat_name="L1 info s2 CMA",
+ source=self.source)
+
+ self.rooms = [Room.objects.create(name="0"),
+ Room.objects.create(name="1"),
+ Room.objects.create(name="2"),
+ Room.objects.create(name="3"),
+ Room.objects.create(name="4"),
+ Room.objects.create(name="5"),
+ Room.objects.create(name="6")]
+
+ hours = [({"begin": datetime.time(hour=14, minute=0)},),
+ ({"begin": datetime.time(hour=16, minute=0)},),
+ ({"begin": datetime.time(hour=13, minute=30)},
+ {"begin": datetime.time(hour=16, minute=0)}),
+ ({"begin": datetime.time(hour=14, minute=0), "duration": 4},),
+ ({"begin": datetime.time(hour=15, minute=30),
+ "duration": 1},),
+ ({"begin": datetime.time(hour=13, minute=0)},
+ {"begin": datetime.time(hour=17, minute=0)}),
+ ()]
+
+ for i, room in enumerate(self.rooms):
+ for rn in hours[i]:
+ begin = timezone.make_aware(
+ datetime.datetime.combine(self.day, rn["begin"]))
+ end = begin + datetime.timedelta(hours=rn.get("duration", 2))
+
+ course = Course.objects.create(source=self.source,
+ begin=begin, end=end)
+ course.groups.add(group)
+ course.rooms.add(room)
+
+ def test_qsjps(self):
+ begin = timezone.make_aware(datetime.datetime.combine(
+ self.day, datetime.time(hour=15, minute=0)))
+ end = begin + datetime.timedelta(hours=2)
+
+ rooms = Room.objects.qsjps(begin, end)
+ self.assertEqual(rooms.count(), 2)
+
+ self.assertNotIn(self.rooms[0], rooms)
+ self.assertNotIn(self.rooms[1], rooms)
+ self.assertNotIn(self.rooms[2], rooms)
+ self.assertNotIn(self.rooms[3], rooms)
+ self.assertNotIn(self.rooms[4], rooms)
+ self.assertIn(self.rooms[5], rooms)
+ self.assertIn(self.rooms[6], rooms)