-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from edx/schen/MST-1404
chore: Add simple_history tracking table for VerifiedName model
- Loading branch information
Showing
14 changed files
with
119 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
edx_name_affirmation/migrations/0007_historicalverifiedname.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Generated by Django 3.2.12 on 2022-03-11 08:10 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import model_utils.fields | ||
import simple_history.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('edx_name_affirmation', '0006_auto_20210830_2029'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='HistoricalVerifiedName', | ||
fields=[ | ||
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), | ||
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), | ||
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), | ||
('verified_name', models.CharField(db_index=True, max_length=255)), | ||
('profile_name', models.CharField(max_length=255, null=True)), | ||
('verification_attempt_id', models.PositiveIntegerField(blank=True, null=True)), | ||
('proctored_exam_attempt_id', models.PositiveIntegerField(blank=True, null=True)), | ||
('status', models.CharField(choices=[('pending', 'pending'), ('submitted', 'submitted'), ('approved', 'approved'), ('denied', 'denied')], default='pending', max_length=32)), | ||
('history_id', models.AutoField(primary_key=True, serialize=False)), | ||
('history_date', models.DateTimeField()), | ||
('history_change_reason', models.CharField(max_length=100, null=True)), | ||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), | ||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), | ||
('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'verbose_name': 'historical verified name', | ||
'ordering': ('-history_date', '-history_id'), | ||
'get_latest_by': 'history_date', | ||
}, | ||
bases=(simple_history.models.HistoricalChanges, models.Model), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Tests for Name Affirmation models | ||
""" | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
|
||
from edx_name_affirmation.models import VerifiedName | ||
from edx_name_affirmation.statuses import VerifiedNameStatus | ||
|
||
User = get_user_model() | ||
|
||
|
||
class VerifiedNameModelTests(TestCase): | ||
""" | ||
Test suite for the VerifiedName models | ||
""" | ||
def setUp(self): | ||
self.verified_name = 'Test Tester' | ||
self.user = User.objects.create(username='modelTester', email='[email protected]') | ||
self.verified_name = VerifiedName.objects.create( | ||
user=self.user, | ||
verified_name=self.verified_name, | ||
status=VerifiedNameStatus.SUBMITTED, | ||
) | ||
return super().setUp() | ||
|
||
def test_histories(self): | ||
""" | ||
Test the model history is recording records as expected | ||
""" | ||
verified_name_history = self.verified_name.history.all().order_by('history_date') # pylint: disable=no-member | ||
assert len(verified_name_history) == 1 | ||
idv_attempt_id = 34455 | ||
self.verified_name.status = VerifiedNameStatus.APPROVED | ||
self.verified_name.verification_attempt_id = idv_attempt_id | ||
self.verified_name.save() | ||
verified_name_history = self.verified_name.history.all().order_by('history_date') # pylint: disable=no-member | ||
assert len(verified_name_history) == 2 | ||
|
||
first_history_record = verified_name_history[0] | ||
assert first_history_record.status == VerifiedNameStatus.SUBMITTED | ||
assert first_history_record.verification_attempt_id is None | ||
|
||
second_history_record = verified_name_history[1] | ||
assert second_history_record.status == VerifiedNameStatus.APPROVED | ||
assert second_history_record.verification_attempt_id == idv_attempt_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters