From 88cbf7f4bfd34b83ca05dbb15da4567add1c9adf Mon Sep 17 00:00:00 2001 From: Yevgeny Kazakov Date: Tue, 8 Oct 2024 12:05:02 +0200 Subject: [PATCH] Check if solution requires assignment download --- ngshare_exchange/list.py | 8 +- ngshare_exchange/tests/test_list.py | 126 +++++++++++++++++++++++----- 2 files changed, 112 insertions(+), 22 deletions(-) diff --git a/ngshare_exchange/list.py b/ngshare_exchange/list.py index eb603a7..dacfbd0 100644 --- a/ngshare_exchange/list.py +++ b/ngshare_exchange/list.py @@ -353,8 +353,10 @@ def format_outbound_assignment(self, info): def format_solution(self, info): msg = "{course_id} {assignment_id}".format(**info) - if os.path.exists(os.path.join(info['assignment_id'], 'solution')): + if info['status'] == "fetched_solution": msg += " (already downloaded)" + elif info['status'] == "fetch_assignment": + msg += " (download assignment!)" return msg def copy_files(self): @@ -394,8 +396,10 @@ def parse_assignments(self): if os.path.exists(solution_dir): info['status'] = 'fetched_solution' info['path'] = os.path.abspath(solution_dir) - else: + elif os.path.exists(assignment_dir): info['status'] = 'released_solution' + else: + info['status'] = 'fetch_assignment' elif os.path.exists(assignment_dir): info['status'] = 'fetched' info['path'] = os.path.abspath(assignment_dir) diff --git a/ngshare_exchange/tests/test_list.py b/ngshare_exchange/tests/test_list.py index 05c1265..1c17a03 100644 --- a/ngshare_exchange/tests/test_list.py +++ b/ngshare_exchange/tests/test_list.py @@ -673,7 +673,7 @@ def test_list_solution_2x1_course1(self): { "course_id": self.course_id, "assignment_id": self.assignment_id, - "status": "released_solution", + "status": "fetch_assignment", "notebooks": [{"notebook_id": self.notebook_id}], }, ], @@ -684,7 +684,7 @@ def test_list_solution_2x1_course1(self): == dedent( """ [INFO] Released solutions: - [INFO] {} {} + [INFO] {} {} (download assignment!) """ ) .lstrip() @@ -703,7 +703,7 @@ def test_list_solution_2x1_course2(self): { "course_id": self.course_id2, "assignment_id": self.assignment_id, - "status": "released_solution", + "status": "fetch_assignment", "notebooks": [{"notebook_id": self.notebook_id}], }, ], @@ -714,7 +714,7 @@ def test_list_solution_2x1_course2(self): == dedent( """ [INFO] Released solutions: - [INFO] {} {} + [INFO] {} {} (download assignment!) """ ) .lstrip() @@ -733,7 +733,7 @@ def test_list_solution_2x1(self): { "course_id": course_id, "assignment_id": self.assignment_id, - "status": "released_solution", + "status": "fetch_assignment", "notebooks": [{"notebook_id": self.notebook_id}], } for course_id in (self.course_id, self.course_id2) @@ -745,8 +745,8 @@ def test_list_solution_2x1(self): == dedent( """ [INFO] Released solutions: - [INFO] {} {} - [INFO] {} {} + [INFO] {} {} (download assignment!) + [INFO] {} {} (download assignment!) """ ) .lstrip() @@ -770,7 +770,7 @@ def test_list_solution_2x2_assignment1(self): { "course_id": course_id, "assignment_id": self.assignment_id, - "status": "released_solution", + "status": "fetch_assignment", "notebooks": [{"notebook_id": self.notebook_id}], } for course_id in (self.course_id, self.course_id2) @@ -782,8 +782,8 @@ def test_list_solution_2x2_assignment1(self): == dedent( """ [INFO] Released solutions: - [INFO] {} {} - [INFO] {} {} + [INFO] {} {} (download assignment!) + [INFO] {} {} (download assignment!) """ ) .lstrip() @@ -807,7 +807,7 @@ def test_list_solution_2x2_assignment2(self): { "course_id": course_id, "assignment_id": self.assignment_id2, - "status": "released_solution", + "status": "fetch_assignment", "notebooks": [{"notebook_id": self.notebook_id}], } for course_id in (self.course_id, self.course_id2) @@ -819,8 +819,8 @@ def test_list_solution_2x2_assignment2(self): == dedent( """ [INFO] Released solutions: - [INFO] {} {} - [INFO] {} {} + [INFO] {} {} (download assignment!) + [INFO] {} {} (download assignment!) """ ) .lstrip() @@ -843,7 +843,7 @@ def test_list_solution_2x2(self): { "course_id": course_id, "assignment_id": assignment_id, - "status": "released_solution", + "status": "fetch_assignment", "notebooks": [{"notebook_id": self.notebook_id}], } for course_id in (self.course_id, self.course_id2) @@ -856,10 +856,10 @@ def test_list_solution_2x2(self): == dedent( """ [INFO] Released solutions: - [INFO] {} {} - [INFO] {} {} - [INFO] {} {} - [INFO] {} {} + [INFO] {} {} (download assignment!) + [INFO] {} {} (download assignment!) + [INFO] {} {} (download assignment!) + [INFO] {} {} (download assignment!) """ ) .lstrip() @@ -875,7 +875,93 @@ def test_list_solution_2x2(self): ) ) + def test_list_solution_fetched_assignment_1(self): + self.num_assignments = 2 + self._fetch(self.course_dir) + self.num_solutions = 2 + self.list.solution = True + data = self.list.start() + solution_path = self.course_dir / self.assignment_id / "solution" + notebook_solution_path = solution_path / (self.notebook_id + '.ipynb') + self.assertEqual( + data, + [ + { + "course_id": self.course_id, + "assignment_id": self.assignment_id, + "status": "released_solution", + "notebooks": [{"notebook_id": self.notebook_id}], + }, + { + "course_id": self.course_id, + "assignment_id": self.assignment_id2, + "status": "fetch_assignment", + "notebooks": [{"notebook_id": self.notebook_id}], + }, + ], + ) + output = self._read_log() + assert ( + output + == dedent( + """ + [INFO] Released solutions: + [INFO] {} {} + [INFO] {} {} (download assignment!) + """ + ) + .lstrip() + .format( + self.course_id, + self.assignment_id, + self.course_id, + self.assignment_id2, + ) + ) + + def test_list_solution_fetched_assignment_2(self): + self.num_assignments = 2 + self._fetch(self.course_dir) + self._fetch(self.course_dir, assignment_id=self.assignment_id2) + self.num_solutions = 2 + self.list.solution = True + data = self.list.start() + solution_path = self.course_dir / self.assignment_id / "solution" + notebook_solution_path = solution_path / (self.notebook_id + '.ipynb') + self.assertEqual( + data, + [ + { + "course_id": self.course_id, + "assignment_id": assignment_id, + "status": "released_solution", + "notebooks": [{"notebook_id": self.notebook_id}], + } + for assignment_id in (self.assignment_id, self.assignment_id2) + ], + ) + output = self._read_log() + assert ( + output + == dedent( + """ + [INFO] Released solutions: + [INFO] {} {} + [INFO] {} {} + """ + ) + .lstrip() + .format( + self.course_id, + self.assignment_id, + self.course_id, + self.assignment_id2, + ) + ) + def test_list_fetched_solution(self): + self.num_assignments = 2 + self._fetch(self.course_dir) self.num_solutions = 2 self._fetch_solution(self.course_dir) self.list.solution = True @@ -900,7 +986,7 @@ def test_list_fetched_solution(self): { "course_id": self.course_id, "assignment_id": self.assignment_id2, - "status": "released_solution", + "status": "fetch_assignment", "notebooks": [{"notebook_id": self.notebook_id}], }, ], @@ -912,7 +998,7 @@ def test_list_fetched_solution(self): """ [INFO] Released solutions: [INFO] {} {} (already downloaded) - [INFO] {} {} + [INFO] {} {} (download assignment!) """ ) .lstrip()