Skip to content

Commit

Permalink
Merge pull request #83 from edx/schen/MST-1404
Browse files Browse the repository at this point in the history
chore: Add simple_history tracking table for VerifiedName model
  • Loading branch information
schenedx authored Mar 11, 2022
2 parents 5577bac + 92a75aa commit 62cff3e
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .annotation_safe_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ sessions.Session:
".. pii": "The session can be used to store user information"
".. pii_types": "other"
".. pii_retirement": "consumer_api"
edx_name_affirmation.HistoricalVerifiedName:
".. pii": "This model contains name fields"
".. pii_types": "name"
".. pii_retirement": "local_api"
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Change Log
Unreleased
~~~~~~~~~~
[2.3.2] - 2022-03-11
~~~~~~~~~~~~~~~~~~~~
* Add simple_history tracking to the VerifiedName model

[2.3.1] - 2022-03-02
~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion edx_name_affirmation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Django app housing name affirmation logic.
"""

__version__ = '2.3.1'
__version__ = '2.3.2'

default_app_config = 'edx_name_affirmation.apps.EdxNameAffirmationConfig' # pylint: disable=invalid-name
44 changes: 44 additions & 0 deletions edx_name_affirmation/migrations/0007_historicalverifiedname.py
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),
),
]
2 changes: 2 additions & 0 deletions edx_name_affirmation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from config_models.models import ConfigurationModel
from model_utils.models import TimeStampedModel
from simple_history.models import HistoricalRecords

from django.contrib.auth import get_user_model
from django.db import models
Expand Down Expand Up @@ -37,6 +38,7 @@ class VerifiedName(TimeStampedModel):
choices=[(st.value, st.value) for st in VerifiedNameStatus],
default=VerifiedNameStatus.PENDING.value,
)
history = HistoricalRecords()

class Meta:
""" Meta class for this Django model """
Expand Down
47 changes: 47 additions & 0 deletions edx_name_affirmation/tests/test_models.py
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
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Django>=2.2 # Web application framework
django-config-models
django-model-utils # Provides TimeStampedModel abstract base class
djangorestframework
django-simple-history # Provides historical records on models

edx-celeryutils
edx-django-utils>=3.12.0
Expand Down
6 changes: 4 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# make upgrade
#
amqp==5.0.9
amqp==5.1.0
# via kombu
asgiref==3.5.0
# via django
Expand Down Expand Up @@ -61,6 +61,8 @@ django-model-utils==4.2.0
# via
# -r requirements/base.in
# edx-celeryutils
django-simple-history==3.0.0
# via -r requirements/base.in
django-waffle==2.3.0
# via
# edx-django-utils
Expand Down Expand Up @@ -98,7 +100,7 @@ jinja2==3.0.3
# via code-annotations
jsonfield==3.1.0
# via edx-celeryutils
kombu==5.2.3
kombu==5.2.4
# via celery
markupsafe==2.1.0
# via jinja2
Expand Down
4 changes: 2 additions & 2 deletions requirements/celery50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# make upgrade
#
amqp==5.0.9
amqp==5.1.0
# via kombu
billiard==3.6.4.0
# via celery
Expand All @@ -22,7 +22,7 @@ click-plugins==1.1.1
# via celery
click-repl==0.2.0
# via celery
kombu==5.2.3
kombu==5.2.4
# via celery
prompt-toolkit==3.0.28
# via click-repl
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ tox-battery==0.6.1
# via -r requirements/ci.in
urllib3==1.26.8
# via requests
virtualenv==20.13.2
virtualenv==20.13.3
# via tox
25 changes: 2 additions & 23 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ certifi==2021.10.8
# -r requirements/ci.txt
# -r requirements/quality.txt
# requests
cffi==1.15.0
# via
# -r requirements/quality.txt
# cryptography
chardet==4.0.0
# via diff-cover
charset-normalizer==2.0.12
Expand Down Expand Up @@ -59,10 +55,6 @@ coverage==6.3.2
# via
# -r requirements/ci.txt
# codecov
cryptography==36.0.1
# via
# -r requirements/quality.txt
# secretstorage
diff-cover==6.4.4
# via -r requirements/dev.in
distlib==0.3.4
Expand Down Expand Up @@ -102,11 +94,6 @@ isort==5.10.1
# via
# -r requirements/quality.txt
# pylint
jeepney==0.7.1
# via
# -r requirements/quality.txt
# keyring
# secretstorage
jinja2==3.0.3
# via
# -r requirements/quality.txt
Expand Down Expand Up @@ -170,10 +157,6 @@ py==1.11.0
# tox
pycodestyle==2.8.0
# via -r requirements/quality.txt
pycparser==2.21
# via
# -r requirements/quality.txt
# cffi
pydocstyle==6.1.1
# via -r requirements/quality.txt
pygments==2.11.2
Expand Down Expand Up @@ -219,7 +202,7 @@ pyyaml==6.0
# -r requirements/quality.txt
# code-annotations
# edx-i18n-tools
readme-renderer==32.0
readme-renderer==33.0
# via
# -r requirements/quality.txt
# twine
Expand All @@ -240,10 +223,6 @@ rfc3986==2.0.0
# twine
rstcheck==3.3.1
# via -r requirements/quality.txt
secretstorage==3.3.1
# via
# -r requirements/quality.txt
# keyring
six==1.16.0
# via
# -r requirements/ci.txt
Expand Down Expand Up @@ -303,7 +282,7 @@ urllib3==1.26.8
# -r requirements/quality.txt
# requests
# twine
virtualenv==20.13.2
virtualenv==20.13.3
# via
# -r requirements/ci.txt
# tox
Expand Down
8 changes: 5 additions & 3 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
alabaster==0.7.12
# via sphinx
amqp==5.0.9
amqp==5.1.0
# via kombu
asgiref==3.5.0
# via django
Expand Down Expand Up @@ -67,6 +67,8 @@ django-model-utils==4.2.0
# via
# -r requirements/base.in
# edx-celeryutils
django-simple-history==3.0.0
# via -r requirements/base.in
django-waffle==2.3.0
# via
# edx-django-utils
Expand Down Expand Up @@ -120,7 +122,7 @@ jinja2==3.0.3
# sphinx
jsonfield==3.1.0
# via edx-celeryutils
kombu==5.2.3
kombu==5.2.4
# via celery
markupsafe==2.1.0
# via jinja2
Expand Down Expand Up @@ -169,7 +171,7 @@ pytz==2021.3
# djangorestframework
pyyaml==6.0
# via code-annotations
readme-renderer==32.0
readme-renderer==33.0
# via -r requirements/doc.in
requests==2.27.1
# via
Expand Down
14 changes: 1 addition & 13 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ bleach==4.1.0
# via readme-renderer
certifi==2021.10.8
# via requests
cffi==1.15.0
# via cryptography
charset-normalizer==2.0.12
# via requests
click==8.0.4
Expand All @@ -29,8 +27,6 @@ code-annotations==1.3.0
# via edx-lint
colorama==0.4.4
# via twine
cryptography==36.0.1
# via secretstorage
django==3.2.12
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
Expand All @@ -51,10 +47,6 @@ isort==5.10.1
# via
# -r requirements/quality.in
# pylint
jeepney==0.7.1
# via
# keyring
# secretstorage
jinja2==3.0.3
# via code-annotations
keyring==23.5.0
Expand All @@ -75,8 +67,6 @@ platformdirs==2.5.1
# via pylint
pycodestyle==2.8.0
# via -r requirements/quality.in
pycparser==2.21
# via cffi
pydocstyle==6.1.1
# via -r requirements/quality.in
pygments==2.11.2
Expand All @@ -103,7 +93,7 @@ pytz==2021.3
# via django
pyyaml==6.0
# via code-annotations
readme-renderer==32.0
readme-renderer==33.0
# via twine
requests==2.27.1
# via
Expand All @@ -115,8 +105,6 @@ rfc3986==2.0.0
# via twine
rstcheck==3.3.1
# via -r requirements/quality.in
secretstorage==3.3.1
# via keyring
six==1.16.0
# via
# bleach
Expand Down
2 changes: 2 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ django-model-utils==4.2.0
# via
# -r requirements/base.txt
# edx-celeryutils
django-simple-history==3.0.0
# via -r requirements/base.txt
django-waffle==2.3.0
# via
# -r requirements/base.txt
Expand Down

0 comments on commit 62cff3e

Please sign in to comment.