Skip to content

Commit

Permalink
DE-1824: step 1 of 4 in renaming 'exists' field in ThirdPartyTranscri…
Browse files Browse the repository at this point in the history
…ptCredentialsState to 'has_creds' (#191)

* DE-1824: Add has_creds field to replace exists in 
ThirdPartyTranscriptCredentialsState, to eventually replace the
'exists' column.
* Update version number.
* Leave the API method signature unchanged.

The 'exists' column name in ThirdPartyTranscriptCredentialsState is a reserved keyword in SQL, so this PR starts the process of renaming the field to 'has_creds' in its place. This is step 1, to add the field to replace it. Step 2 will be to use a migration to copy the contents of existing 'exists' to 'has_creds'. Step 3 will be to remove the logic that relies on 'exists', and step 4 will be to add a migration to remove the 'exists' column from the database. This will also require bumping the version of edx-val, and updating the other repo that use edx-val, i.e. edx-platform.
  • Loading branch information
brianhw committed Dec 5, 2019
1 parent b0a78b0 commit e21b7ab
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions edxval/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class TranscriptPreferenceAdmin(admin.ModelAdmin):

class ThirdPartyTranscriptCredentialsStateAdmin(admin.ModelAdmin):
""" Admin for ThirdPartyTranscriptCredentialsState """
# TODO: change "exists" to "has_creds" once the new column exists, in step 3
# of the renaming process.
list_display = ('org', 'provider', 'exists', 'created', 'modified')

model = ThirdPartyTranscriptCredentialsState
Expand Down
3 changes: 2 additions & 1 deletion edxval/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def get_transcript_credentials_state_for_org(org, provider=None):
query_filter['provider'] = provider

return {
# TODO: rename credential.exists to credential.has_creds in step 3 of renaming.
credential.provider: credential.exists
for credential in ThirdPartyTranscriptCredentialsState.objects.filter(**query_filter)
}
Expand Down Expand Up @@ -510,7 +511,7 @@ def create_profile(profile_name):
"""
Used to create Profile objects in the database
A profile needs to exists before an EncodedVideo object can be created.
A profile needs to exist before an EncodedVideo object can be created.
Args:
profile_name (str): ID of the profile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.25 on 2019-12-03 05:48
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('edxval', '0011_data__add_audio_mp3_profile'),
]

operations = [
migrations.AddField(
model_name='thirdpartytranscriptcredentialsstate',
name='has_creds',
field=models.BooleanField(default=False, help_text='Transcript credentials state'),
),
]
8 changes: 6 additions & 2 deletions edxval/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,17 +659,20 @@ class Meta:
max_length=20,
choices=TranscriptProviderType.CHOICES,
)
# TODO remove exists in step 3 of renaming.
exists = models.BooleanField(default=False, help_text=u'Transcript credentials state')
has_creds = models.BooleanField(default=False, help_text=u'Transcript credentials state')

@classmethod
def update_or_create(cls, org, provider, exists):
def update_or_create(cls, org, provider, has_creds):
"""
Update or create credentials state.
"""
# TODO: remove 'exists' in step 3 of renaming.
instance, created = cls.objects.update_or_create(
org=org,
provider=provider,
defaults={'exists': exists},
defaults={'exists': has_creds, 'has_creds': has_creds},
)

return instance, created
Expand All @@ -682,6 +685,7 @@ def __str__(self):
edX has Cielo24 credentials
edX doesn't have 3PlayMedia credentials
"""
# TODO: rename exists to has_creds in set 3 of renaming.
return u'{org} {state} {provider} credentials'.format(
org=self.org, provider=self.provider, state='has' if self.exists else "doesn't have"
)
Expand Down
5 changes: 3 additions & 2 deletions edxval/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3014,11 +3014,12 @@ def setUp(self):
Tests setup
"""
super(TranscripCredentialsStateTest, self).setUp()
# TODO: remove exists in step 3 of renaming.
third_party_trans_true = ThirdPartyTranscriptCredentialsState.objects.create(
org='edX', provider='Cielo24', exists=True
org='edX', provider='Cielo24', exists=True, has_creds=True
)
third_party_trans_false = ThirdPartyTranscriptCredentialsState.objects.create(
org='edX', provider='3PlayMedia', exists=False
org='edX', provider='3PlayMedia', exists=False, has_creds=False
)

# casting an instance to a string returns a valid value.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def load_requirements(*requirements_paths):
return list(requirements)


VERSION = '1.1.30'
VERSION = '1.1.31'

if sys.argv[-1] == 'tag':
print("Tagging the version on github:")
Expand Down

0 comments on commit e21b7ab

Please sign in to comment.