Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammad-ammar committed Oct 10, 2017
1 parent e135490 commit 3b8222c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-10-05 05:54
# Generated by Django 1.11.4 on 2017-10-10 07:29
from __future__ import unicode_literals

from django.db import migrations, models
import django.utils.timezone
import model_utils.fields


class Migration(migrations.Migration):
Expand All @@ -16,6 +18,8 @@ class Migration(migrations.Migration):
name='ThirdPartyTranscriptCredentialsState',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, 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')),
('org', models.CharField(max_length=32, verbose_name=b'Course Organization')),
('provider', models.CharField(choices=[(b'Custom', b'Custom'), (b'3PlayMedia', b'3PlayMedia'), (b'Cielo24', b'Cielo24')], max_length=20, verbose_name=b'Transcript Provider')),
('exists', models.BooleanField(default=False, help_text=b'Transcript credentials state')),
Expand Down
16 changes: 4 additions & 12 deletions edxval/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def __unicode__(self):
return u'{course_id} - {provider}'.format(course_id=self.course_id, provider=self.provider)


class ThirdPartyTranscriptCredentialsState(models.Model):
class ThirdPartyTranscriptCredentialsState(TimeStampedModel):
"""
State of transcript credentials for a course organization
"""
Expand All @@ -633,7 +633,8 @@ def update_or_create(cls, org, provider, exists):
Update or create credentials state.
"""
instance, created = cls.objects.update_or_create(
org=org, provider=provider,
org=org,
provider=provider,
defaults={'exists': exists},
)

Expand All @@ -645,22 +646,13 @@ def __unicode__(self):
NOTE: Message will look like below:
edX has Cielo24 credentials
edX has no 3PlayMedia credentials
edX doesn't have 3PlayMedia credentials
"""
return u'{org} {state} {provider} credentials'.format(
org=self.org, provider=self.provider, state='has' if self.exists else "doesn't have"
)


@receiver(models.signals.pre_save, sender=ThirdPartyTranscriptCredentialsState)
def validate_provider(sender, instance, **kwargs): # pylint: disable=unused-argument
"""
Validate that input provider value must be one of TranscriptProviderType.CHOICES.
"""
if instance.provider not in dict(TranscriptProviderType.CHOICES).keys():
raise ValidationError('Invalid transcript provider value')


@receiver(models.signals.post_save, sender=Video)
def video_status_update_callback(sender, **kwargs): # pylint: disable=unused-argument
"""
Expand Down
17 changes: 1 addition & 16 deletions edxval/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,21 +2063,6 @@ def setUp(self):
org='edX', provider='3PlayMedia', exists=False
)

@data(
{'provider': ''},
{'provider': 'fake'},
{'provider': None},
)
@unpack
def test_provider_validation(self, provider):
"""
Verify that provider value is validated
"""
with self.assertRaises(ValidationError):
ThirdPartyTranscriptCredentialsState.objects.create(
org='edX', provider=provider, exists=False
)

@data(
{'org': 'MAX', 'provider': 'Cielo24', 'exists': True},
{'org': 'MAX', 'provider': '3PlayMedia', 'exists': True},
Expand Down Expand Up @@ -2114,7 +2099,7 @@ def test_credentials_state_update(self, **kwargs):
@unpack
def test_get_credentials_state(self, org, provider, result):
"""
Verify that `get_organization_transcript_credentials_state` method works as expected
Verify that `get_transcript_credentials_state_for_org` method works as expected
"""
credentials_exists = api.get_transcript_credentials_state_for_org(org=org, provider=provider)
self.assertEqual(credentials_exists, result)

0 comments on commit 3b8222c

Please sign in to comment.