コード例 #1
0
def test_generate_md5():
    """Test that generate_md5 generates an MD5 hash"""
    bytes_to_hash = 'abc'.encode('utf-8')
    md5_hash = generate_md5(bytes_to_hash)
    assert isinstance(md5_hash, str)
    assert len(md5_hash) == 32
    repeat_md5_hash = generate_md5(bytes_to_hash)
    assert md5_hash == repeat_md5_hash
コード例 #2
0
ファイル: utils_test.py プロジェクト: mitodl/micromasters
def test_generate_md5():
    """Test that generate_md5 generates an MD5 hash"""
    bytes_to_hash = 'abc'.encode('utf-8')
    md5_hash = generate_md5(bytes_to_hash)
    assert isinstance(md5_hash, str)
    assert len(md5_hash) == 32
    repeat_md5_hash = generate_md5(bytes_to_hash)
    assert md5_hash == repeat_md5_hash
コード例 #3
0
def add_final_grade(apps, schema_editor):
    MicromastersCourseCertificate = apps.get_model('grades', 'MicromastersCourseCertificate')
    FinalGrade = apps.get_model('grades', 'FinalGrade')
    Course = apps.get_model('courses', 'Course')

    certificates= MicromastersCourseCertificate.objects.filter(course__isnull=True)
    for certificate in certificates:
        certificate.delete()
    certificates = MicromastersCourseCertificate.objects.filter(course__program__financial_aid_availability=True)

    for certificate in certificates:
        passing_final_grades = FinalGrade.objects.filter(
            user=certificate.user,
            course_run__course=certificate.course,
            passed=True
        ).order_by('-grade')
        certificate.final_grade = passing_final_grades.first()
        certificate.save()
        # check if has other passing final_grades
        for final_grade in passing_final_grades[1:]:
            hash = generate_md5('{}|{}'.format(certificate.user_id, final_grade.course_run_id).encode('utf-8'))
            MicromastersCourseCertificate.objects.create(
                final_grade=final_grade,
                user=final_grade.user,
                course=certificate.course,
                hash=hash
            )
コード例 #4
0
ファイル: models.py プロジェクト: mitodl/micromasters
 def save(self, *args, **kwargs):  # pylint: disable=arguments-differ
     """Overridden save method"""
     if not self.hash:
         self.hash = generate_md5(
             '{}|{}'.format(self.user_id, self.program_id).encode('utf-8')
         )
     super().save(*args, **kwargs)
コード例 #5
0
def populate_enrollment_hash(apps, schema_editor):
    ProgramEnrollment = apps.get_model('dashboard', 'ProgramEnrollment')
    for enrollment in ProgramEnrollment.objects.all():
        enrollment.hash = generate_md5(
            '{}|{}'.format(enrollment.user_id, enrollment.program_id).encode('utf-8')
        )
        enrollment.save()
コード例 #6
0
class MicromastersCourseCertificateFactory(DjangoModelFactory):
    """Factory for MicromastersCourseCertificate"""
    user = SubFactory(UserFactory)
    course = SubFactory(CourseFactory)
    hash = LazyAttribute(lambda cert: generate_md5('{}|{}'.format(cert.user.id, cert.course.id).encode('utf-8')))

    class Meta:  # pylint: disable=missing-docstring,no-init,too-few-public-methods
        model = MicromastersCourseCertificate
コード例 #7
0
 def test_autogenerated_hash(self):
     """Test that MicromastersCourseCertificate auto-generates a hash when none is provided"""
     user = UserFactory.create()
     course = CourseFactory.create()
     mm_certificate = MicromastersCourseCertificate.objects.create(
         user=user, course=course)
     assert len(mm_certificate.hash) == 32
     assert mm_certificate.hash == generate_md5('{}|{}'.format(
         user.id, course.id).encode('utf-8'))
コード例 #8
0
def populate_enrollment_hash(apps, schema_editor):
    ProgramEnrollment = apps.get_model('dashboard', 'ProgramEnrollment')
    for enrollment in ProgramEnrollment.objects.all():
        enrollment.hash = generate_md5('{}|{}'.format(
            enrollment.user_id, enrollment.program_id).encode('utf-8'))
        enrollment.save()
コード例 #9
0
 def save(self, *args, **kwargs):  # pylint: disable=arguments-differ
     """Overridden save method"""
     if not self.hash:
         self.hash = generate_md5('{}|{}'.format(
             self.user_id, self.program_id).encode('utf-8'))
     super().save(*args, **kwargs)
コード例 #10
0
 def save(self, *args, **kwargs):  # pylint: disable=signature-differs
     """Overridden save method"""
     if not self.hash:
         self.hash = generate_md5('{}|{}'.format(
             self.user_id, self.course_id).encode('utf-8'))
     super().save(*args, **kwargs)