Skip to content

Commit

Permalink
Better tests, fix evaluations
Browse files Browse the repository at this point in the history
Co-Authored-By: Josselin R. <45465075+ModernChocolate@users.noreply.github.com>
  • Loading branch information
bain3 and JsonLinesCode committed Apr 1, 2021
1 parent a8a0685 commit a3ef42b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions pronotepy/dataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, client, parsed_json):
@property
def grades(self):
"""Get grades from the period."""
json_data = {'Periode': {'N': self.id, 'L': self.name}}
json_data = {'periode': {'N': self.id, 'L': self.name}}
response = self._client.post('DernieresNotes', 198, json_data)
log.debug(response)
grades = response['donneesSec']['donnees']['listeDevoirs']['V']
Expand All @@ -137,7 +137,7 @@ def grades(self):
def averages(self):
"""Get averages from the period."""

json_data = {'Periode': {'N': self.id, 'L': self.name}}
json_data = {'periode': {'N': self.id, 'L': self.name}}
response = self._client.post('DernieresNotes', 198, json_data)
crs = response['donneesSec']['donnees']['listeServices']['V']
return [Average(c) for c in crs]
Expand All @@ -146,7 +146,7 @@ def averages(self):
def overall_average(self):
"""Get overall average from the period. If the period average is not provided by pronote, then it's calculated.
Calculation may not be the same as the actual average. (max difference 0.01)"""
json_data = {'Periode': {'N': self.id, 'L': self.name}}
json_data = {'periode': {'N': self.id, 'L': self.name}}
response = self._client.post('DernieresNotes', 198, json_data)
average = response['donneesSec']['donnees'].get('moyGenerale')
if average:
Expand Down Expand Up @@ -174,7 +174,7 @@ def overall_average(self):

@property
def evaluations(self):
json_data = {'Periode': {'N': self.id, 'L': self.name, 'G': 2}}
json_data = {'periode': {'N': self.id, 'L': self.name, 'G': 2}}
response = self._client.post('DernieresEvaluations', 201, json_data)
evaluations = response['donneesSec']['donnees']['listeEvaluations']['V']
return [Evaluation(e) for e in evaluations]
Expand Down
34 changes: 25 additions & 9 deletions pronotepy/test_pronotepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ def test__get_week(self):
self.assertEqual(client.get_week(client.start_day + datetime.timedelta(days=8)), 2)

def test_lessons(self):
self.assertIsNotNone(
client.lessons(client.start_day, client.start_day + datetime.timedelta(days=8)))
start = client.start_day
end = client.start_day+datetime.timedelta(days=8)
lessons = client.lessons(start, end)
# We assume demo website will always have some lessons
self.assertGreater(len(lessons), 0)
for lesson in lessons:
self.assertLessEqual(start, lesson.start.date())
self.assertLessEqual(lesson.start.date(), end)

def test_periods(self):
self.assertIsNotNone(client.periods)
Expand All @@ -23,8 +29,15 @@ def test_current_period(self):
self.assertIsNotNone(client.current_period)

def test_homework(self):
self.assertIsNotNone(
client.homework(client.start_day, client.start_day + datetime.timedelta(days=8)))
start = client.start_day
end = client.start_day+datetime.timedelta(days=31)
homework = client.homework(start, end)

# We assume demo website will always have homework
self.assertGreater(len(homework), 0)
for hw in homework:
self.assertLessEqual(start, hw.date)
self.assertLessEqual(hw.date, end)

def test_refresh(self):
client.refresh()
Expand All @@ -38,17 +51,19 @@ def setUpClass(cls) -> None:
cls.period = client.current_period

def test_grades(self):
self.assertIsNotNone(self.period.grades)
# We assume demo website will have grades
grades = self.period.grades
self.assertGreater(len(grades), 0)

def test_averages(self):
self.assertIsNotNone(self.period.averages)
self.assertGreater(len(self.period.averages), 0)

def test_overall_average(self):
self.assertIsNotNone(self.period.overall_average)

def test_evaluations(self):
evaluations = self.period.evaluations
self.assertIsNotNone(evaluations)
self.assertGreater(len(evaluations), 0)
for evaluation in evaluations:
for acquisition in evaluation.acquisitions:
self.assertIsNotNone(acquisition)
Expand Down Expand Up @@ -80,15 +95,16 @@ def test_files(self):
class TestParentClient(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.client = pronotepy.ParentClient('https://demo.index-education.net/pronote/parent.html', 'demonstration', 'pronotevs')
cls.client = pronotepy.ParentClient('https://demo.index-education.net/pronote/parent.html',
'demonstration', 'pronotevs')

def test_set_child(self):
self.client.set_child(self.client.children[1])
self.client.set_child('PARENT Fanny')

def test_homework(self):
self.assertIsNotNone(
self.client.homework(self.client.start_day, self.client.start_day + datetime.timedelta(days=8)))
self.client.homework(self.client.start_day, self.client.start_day + datetime.timedelta(days=31)))


if __name__ == '__main__':
Expand Down

0 comments on commit a3ef42b

Please sign in to comment.