Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reference to new generic verification model in platform #223

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading