Skip to content

Commit

Permalink
feat: add reference to new generic verification model in platform
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharis278 committed Sep 19, 2024
1 parent 55d0912 commit b7ce9ca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.16 on 2024-09-19 12:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('edx_name_affirmation', '0008_alter_historicalverifiedname_options'),
]

operations = [
migrations.AlterModelOptions(
name='historicalverifiedname',
options={'get_latest_by': 'history_date', 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical verified name'},
),
migrations.AddField(
model_name='historicalverifiedname',
name='platform_verification_attempt_id',
field=models.PositiveIntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='verifiedname',
name='platform_verification_attempt_id',
field=models.PositiveIntegerField(blank=True, null=True),
),
]
12 changes: 12 additions & 0 deletions edx_name_affirmation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class VerifiedName(TimeStampedModel):
verification_attempt_id = models.PositiveIntegerField(null=True, blank=True)
proctored_exam_attempt_id = models.PositiveIntegerField(null=True, blank=True)

# Reference to a generic VerificationAttempt object in the platform
platform_verification_attempt_id = models.PositiveIntegerField(null=True, blank=True)

status = models.CharField(
max_length=32,
choices=[(st.value, st.value) for st in VerifiedNameStatus],
Expand Down Expand Up @@ -74,6 +77,15 @@ def verification_attempt_status(self):
except ObjectDoesNotExist:
return None

def save(self, *args, **kwargs):
"""
Validate only one of `verification_attempt_id` or `platform_verification_attempt_id`
can be set.
"""
if self.verification_attempt_id and self.platform_verification_attempt_id:
raise ValueError('Only one of `verification_attempt_id` or `platform_verification_attempt_id` can be set.')
super().save(*args, **kwargs)


class VerifiedNameConfig(ConfigurationModel):
"""
Expand Down
9 changes: 9 additions & 0 deletions edx_name_affirmation/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def test_verification_status(self, sspv_mock):
self.verified_name.verification_attempt_id = self.idv_attempt_id
assert self.verified_name.verification_attempt_status is self.idv_attempt_status

def test_verification_id_exclusivity(self):
"""
Test that only one verification ID can be set at a time
"""
self.verified_name.verification_attempt_id = 1
self.verified_name.platform_verification_attempt_id = 1
with self.assertRaises(ValueError):
self.verified_name.save()

# Helper methods

def _obj(self, dictionary):
Expand Down

0 comments on commit b7ce9ca

Please sign in to comment.