def test_fetch_and_save(self, mock_client_call):
        mock_client_call.return_value = None
        obj = queue_stud_perf.fetch_and_save(self.student_performance.registration_id,
                                             self.student_performance.academic_year,
                                             self.student_performance.acronym)
        self.assertIsNone(obj, "Should return None")

        mock_client_call.return_value = self.json_points.encode()
        obj = queue_stud_perf.fetch_and_save(self.student_performance.registration_id,
                                             self.student_performance.academic_year,
                                             self.student_performance.acronym)
        self.assertIsNotNone(obj, "Should return a valid student performance object")
        self.assertJSONEqual(json.dumps(obj.data), self.json_points, "Incorrect student points json")
        self.assertEqual(self.student_performance.registration_id, obj.registration_id, "Incorrect student")
        self.assertEqual(self.student_performance.academic_year, obj.academic_year, "Incorrect academic_year")
        self.assertEqual(self.student_performance.acronym, obj.acronym, "Incorrect acronym")
Beispiel #2
0
    def test_fetch_and_save(self, mock_client_call):
        mock_client_call.return_value = None
        obj = queue_stud_perf.fetch_and_save(self.student_performance.registration_id,
                                             self.student_performance.academic_year,
                                             self.student_performance.acronym)
        self.assertIsNone(obj, "Should return None")

        mock_client_call.return_value = self.json_points.encode()
        obj = queue_stud_perf.fetch_and_save(self.student_performance.registration_id,
                                             self.student_performance.academic_year,
                                             self.student_performance.acronym)
        self.assertIsNotNone(obj, "Should return a valid student performance object")
        self.assertJSONEqual(json.dumps(obj.data), self.json_points, "Incorrect student points json")
        self.assertEqual(self.student_performance.registration_id, obj.registration_id, "Incorrect student")
        self.assertEqual(self.student_performance.academic_year, obj.academic_year, "Incorrect academic_year")
        self.assertEqual(self.student_performance.acronym, obj.acronym, "Incorrect acronym")
def find_actual_by_pk(student_performance_pk):
    result = find_by_pk(student_performance_pk)
    if result and has_expired(result):
            new_result = fetch_and_save(result.registration_id, result.academic_year, result.acronym)
            if new_result:
                result = new_result
            else:
                result.fetch_timed_out = True
    return result
def find_actual_by_student_and_offer_year(registration_id, academic_year, acronym):
    try:
        result = StudentPerformance.objects.get(registration_id=registration_id,
                                                academic_year=academic_year,
                                                acronym=acronym)
    except ObjectDoesNotExist:
        result = None
    if result and has_expired(result):
        new_result = fetch_and_save(result.registration_id, result.academic_year, result.acronym)
        if new_result:
            result = new_result
        else:
            result.fetch_timed_out = True
    return result
def find_or_fetch(registration_id, academic_year, acronym):
    result = find_by_student_and_offer_year(registration_id, academic_year, acronym)
    if result is None or has_expired(result):
        new_result = fetch_and_save(registration_id, academic_year, acronym)
        result = new_result if new_result else result
    return result
def find_actual_by_pk(student_performance_pk):
    result = find_by_pk(student_performance_pk)
    if result and has_expired(result):
        new_result = fetch_and_save(result.registration_id, result.academic_year, result.acronym)
        result = new_result if new_result else result
    return result