aboutsummaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests.py')
-rw-r--r--tests.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/tests.py b/tests.py
index 8ec90ba..89aefdb 100644
--- a/tests.py
+++ b/tests.py
@@ -18,6 +18,7 @@ from unittest import mock
from django.test import TestCase
from django.utils import timezone
+from .management.parsers.abstractparser import ParserError
from .management.parsers.ups2018 import Parser as UPS2018Parser
from .models import Course, Group, Room, Source, Timetable, Year
from .utils import tz_now
@@ -43,12 +44,14 @@ def mock_requests_get(*args, **kwargs):
return MockedResponse(response.read())
if args[0] == "https://example.org/2018":
- if not kwargs["params"]:
+ if "params" not in kwargs or not kwargs["params"]:
return mocked_response_from_file("tests/data/2018/september.html")
elif kwargs["params"].get("Date") == "20181001":
return mocked_response_from_file("tests/data/2018/october.html")
else:
- return MockedResponse("<html></html>")
+ return mocked_response_from_file("tests/data/2018/empty.html")
+
+ return MockedResponse("<html></html>")
class CourseTestCase(TestCase):
@@ -581,3 +584,28 @@ class UPS2018ParserTestCase(TestCase):
def test_get_update_date(self):
# Pas de date de mise à jour dans ce format
self.assertIsNone(self.parser.get_update_date())
+
+
+class UPS2018BrokenSourceTestCase(TestCase):
+ @mock.patch("requests.get")
+ def test_broken_source(self, mock_get):
+ mock_get.return_value = mock_requests_get("")
+
+ source = Source.objects.create(url="https://example.org/2018")
+ with self.assertRaises(ParserError):
+ UPS2018Parser(source)
+
+ @mock.patch("requests.get")
+ def test_half_broken_source(self, mock_get):
+ source = Source.objects.create(url="https://example.org/2018")
+ mock_get.side_effect = [
+ mock_requests_get(""),
+ mock_requests_get(source.url)
+ ]
+
+ parser = UPS2018Parser(source)
+ self.assertEqual(parser.months, [
+ "September, 2018", "October, 2018", "November, 2018",
+ "December, 2018", "January, 2019", "February, 2019", "March, 2019",
+ "April, 2019", "May, 2019", "June, 2019", "July, 2019"
+ ])