def test_update_or_create(self):
        fields_value = {
            "data": self.json_points,
            "update_date": datetime.date.today(),
            "creation_date": datetime.date.today()
        }
        stud_perf = mdl_perf.update_or_create(
            self.student_performance.registration_id,
            self.student_performance.academic_year,
            self.student_performance.acronym, fields_value)

        self.student_performance.refresh_from_db()
        self.assertEqual(stud_perf, self.student_performance,
                         "Object should be updated")

        mdl_perf.update_or_create("489461",
                                  self.student_performance.academic_year,
                                  self.student_performance.acronym,
                                  fields_value)
        try:
            mdl_perf.StudentPerformance.objects.get(
                registration_id="489461",
                academic_year=self.student_performance.academic_year,
                acronym=self.student_performance.acronym)
        except ObjectDoesNotExist:
            self.fail("Object should be created")
def save(registration_id, academic_year, acronym, json_data,
         default_update_date):
    from performance.models.student_performance import update_or_create
    expiration_date = json_data.pop("expirationDate", None)
    if expiration_date:
        update_date = datetime.datetime.fromtimestamp(expiration_date / 1e3)
    else:
        update_date = default_update_date
    authorized = json_data.pop("authorized", False)
    session_locked = json_data.pop("sessionMonth", None)
    offer_registration_state = json_data.pop("etatInscr", None)
    creation_date = get_creation_date()
    courses_registration_validated = get_course_registration_validation_status(
        academic_year, json_data.pop("validationInscrCours", None))
    learning_units_outside_catalog = json_data.pop("coursHorsPgmPrerequis",
                                                   None)
    fields = {
        "data": json_data,
        "update_date": update_date,
        "creation_date": creation_date,
        "authorized": authorized,
        "session_locked": session_locked,
        "offer_registration_state": offer_registration_state,
        "courses_registration_validated": courses_registration_validated,
        "learning_units_outside_catalog": learning_units_outside_catalog
    }
    try:
        obj = update_or_create(registration_id, academic_year, acronym, fields)
    except Exception:
        obj = None
    return obj
def save(registration_id, academic_year, acronym, json_data):
    from performance.models.student_performance import update_or_create
    update_date = get_expiration_date()
    creation_date = get_creation_date()
    fields = {"data": json_data, "update_date": update_date, "creation_date": creation_date}
    try:
        obj = update_or_create(registration_id, academic_year, acronym, fields)
    except Exception:
        obj = None
    return obj
def save(registration_id, academic_year, acronym, json_data):
    from performance.models.student_performance import update_or_create
    if json_data.get("expirationDate"):
        update_date = json_data.pop("expirationDate")
        update_date = datetime.datetime.fromtimestamp(update_date / 1e3)
    else:
        update_date = get_expiration_date(academic_year)
    creation_date = get_creation_date()
    fields = {"data": json_data, "update_date": update_date, "creation_date": creation_date}
    try:
        obj = update_or_create(registration_id, academic_year, acronym, fields)
    except Exception:
        obj = None
    return obj
    def test_update_or_create(self):
        fields_value = {"data": self.json_points, "update_date": datetime.date.today()}
        stud_perf = mdl_perf.update_or_create(
            self.student_performance.registration_id,
            self.student_performance.academic_year,
            self.student_performance.acronym,
            fields_value,
        )

        self.student_performance.refresh_from_db()
        self.assertEqual(stud_perf, self.student_performance, "Object should be updated")

        mdl_perf.update_or_create(
            "489461", self.student_performance.academic_year, self.student_performance.acronym, fields_value
        )
        try:
            mdl_perf.StudentPerformance.objects.get(
                registration_id="489461",
                academic_year=self.student_performance.academic_year,
                acronym=self.student_performance.acronym,
            )
        except ObjectDoesNotExist:
            self.fail("Object should be created")