Skip to content

Commit

Permalink
refactor: use GeneratedCertificates main fields
Browse files Browse the repository at this point in the history
PR recomendations:
This ensure I create a django test model that only use the fields
that test or the implementation use.\
  • Loading branch information
johanseto committed Sep 13, 2023
1 parent 7db2846 commit 6ed2d7d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
9 changes: 0 additions & 9 deletions eox_nelp/edxapp_wrapper/test_backends/certificates_m_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,9 @@ def get_generated_certificate():
generated_certificate_fields = {
"user": models.ForeignKey(User, on_delete=models.CASCADE),
"course_id": CourseKeyField(max_length=255, blank=True, default=None),
"verify_uuid": models.CharField(max_length=32, blank=True, default='', db_index=True),
"grade": models.CharField(max_length=5, blank=True, default=''),
"key": models.CharField(max_length=32, blank=True, default=''),
"distinction": models.BooleanField(default=False),
"status": models.CharField(max_length=32, default='unavailable'),
"mode": models.CharField(max_length=32, choices=MODES, default=MODES.honor),
"name": models.CharField(blank=True, max_length=255),
"created_date": models.DateTimeField(auto_now_add=True),
"modified_date": models.DateTimeField(auto_now=True),
"download_uuid": models.CharField(max_length=32, blank=True, default=''),
"download_url": models.CharField(max_length=128, blank=True, default=''),
"error_reason": models.CharField(max_length=512, blank=True, default=''),
# not model fields :
"MODES": MODES,
}
Expand Down
11 changes: 1 addition & 10 deletions eox_nelp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,11 @@ class Migration(migrations.Migration):
name='GeneratedCertificate',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
('course_id', opaque_keys.edx.django.models.CourseKeyField(default=None, max_length=255, blank=True)),
('verify_uuid', models.CharField(default='', max_length=32, blank=True)),
('download_uuid', models.CharField(default='', max_length=32, blank=True)),
('download_url', models.CharField(default='', max_length=128, blank=True)),
('grade', models.CharField(default='', max_length=5, blank=True)),
('key', models.CharField(default='', max_length=32, blank=True)),
('distinction', models.BooleanField(default=False)),
('status', models.CharField(default='unavailable', max_length=32)),
('mode', models.CharField(default='honor', max_length=32, choices=[('verified', 'verified'), ('honor', 'honor'), ('audit', 'audit'), ('professional', 'professional'), ('no-id-professional', 'no-id-professional')])),
('name', models.CharField(max_length=255, blank=True)),
('created_date', models.DateTimeField(auto_now_add=True)),
('modified_date', models.DateTimeField(auto_now=True)),
('error_reason', models.CharField(default='', max_length=512, blank=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
]
Expand Down
26 changes: 3 additions & 23 deletions eox_nelp/stats/tests/tests_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,51 +266,31 @@ def setUp(self): # pylint: disable=invalid-name
distinct_result = values_result.distinct.return_value
distinct_result.count.return_value = self.expected_returned_roles

# this block set the GeneratedCertificates mock and its returned values.

# this block use the GeneratedCertificates django test model defined
user, _ = User.objects.get_or_create(username="vader")
user2, _ = User.objects.get_or_create(username="vader2")
GeneratedCertificate.objects.get_or_create(**{
'user': user,
'course_id': CourseKey.from_string("course-v1:test+Cx105+2022_T4"),
'verify_uuid': 'ddad6d87c5084a3facfd7925b0b2b9a3',
'download_uuid': '',
'download_url': '',
'grade': '71.0',
'key': '807e31d92ab6aeaab514d7669bb2b014',
'distinction': False,
'status': 'downloadable',
'mode': 'no-id-professional',
'name': 'Peter Park',
'error_reason': '',

})
GeneratedCertificate.objects.get_or_create(**{
'user': user2,
'course_id': CourseKey.from_string("course-v1:test+Cx105+2022_T4"),
'verify_uuid': 'ddad6d87c5084a3facfd7925b0b2b9a3',
'download_uuid': '',
'download_url': '',
'grade': '59.0',
'key': '807e31d92ab6aeaab514d7669bb2b014',
'distinction': False,
'status': 'notpassing',
'mode': 'honor',
'name': 'Ben Park',
'error_reason': '',

})
GeneratedCertificate.objects.get_or_create(**{
'user': user,
'course_id': CourseKey.from_string("course-v1:test2+Cx105+2022_T4"),
'verify_uuid': 'ddad6d87c5084a3facfd7925b0b2b9a3',
'download_uuid': '',
'download_url': '',
'grade': '90.0',
'key': '807e31d92ab6aeaab514d7669bb2b014',
'distinction': False,
'status': 'downloadable',
'mode': 'honor',
'name': 'Peter Park',
'error_reason': '',
})

def tearDown(self):
Expand Down

0 comments on commit 6ed2d7d

Please sign in to comment.