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

Add description to User Subscriptions EDLY-2211 #181

Open
wants to merge 2 commits into
base: develop-multisite
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion openedx/features/subscriptions/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserSubscriptionSerializer(serializers.ModelSerializer):

class Meta:
model = UserSubscription
fields = ['subscription_id', 'subscription_type', 'expiration_date', 'course_enrollments', 'max_allowed_courses', 'user']
fields = ['subscription_id', 'subscription_type', 'description', 'expiration_date', 'course_enrollments', 'max_allowed_courses', 'user']

def to_internal_value(self, data):
"""
Expand Down
3 changes: 2 additions & 1 deletion openedx/features/subscriptions/api/v1/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date
import factory
from factory import SubFactory
from factory.fuzzy import FuzzyDate, FuzzyInteger
from factory.fuzzy import FuzzyDate, FuzzyInteger, FuzzyText
from factory.django import DjangoModelFactory

from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
Expand All @@ -22,6 +22,7 @@ class Meta(object):
expiration_date = FuzzyDate(start_date=date.today(), end_date=date.today())
subscription_type = UserSubscription.LIMITED_ACCESS
site = SubFactory(SiteFactory)
description = FuzzyText(length=50)

@factory.post_generation
def course_enrollments(self, create, extracted, **kwargs):
Expand Down
18 changes: 11 additions & 7 deletions openedx/features/subscriptions/api/v1/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setUp(self):
# Lifetime access subscription
(None, None, UserSubscription.LIFETIME_ACCESS, 1, None, True),
)
def test_is_active(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value):
def test_is_active(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value, description):
"""
Verify the method properly maps mode slugs to display names.
"""
Expand All @@ -59,7 +59,8 @@ def test_is_active(self, max_allowed_courses, expiration_date, subscription_type
subscription_type=subscription_type,
subscription_id=subscription_id,
user=self.user,
site=self.site
site=self.site,
description=description
)
if number_of_enrollments:
course_enrollments = _get_course_enrollments(number_of_enrollments, self.user)
Expand All @@ -84,7 +85,7 @@ def test_is_active(self, max_allowed_courses, expiration_date, subscription_type
# Lifetime access subscription
(None, None, UserSubscription.LIFETIME_ACCESS, 1, None, True),
)
def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value):
def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value, description):
"""
Verify the method returns the slug if it has no known mapping.
"""
Expand All @@ -93,7 +94,8 @@ def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type,
expiration_date=expiration_date,
subscription_type=subscription_type,
subscription_id=subscription_id,
user=self.user
user=self.user,
description=description
)
if number_of_enrollments:
course_enrollments = _get_course_enrollments(number_of_enrollments, self.user)
Expand All @@ -118,7 +120,7 @@ def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type,
# Lifetime access subscription
(None, None, UserSubscription.LIFETIME_ACCESS, 1, None, True),
)
def test_get_valid_subscription(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value):
def test_get_valid_subscription(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value, description):
"""
Verify that get_valid_subscription returns valid subscription correctly.
"""
Expand All @@ -128,7 +130,8 @@ def test_get_valid_subscription(self, max_allowed_courses, expiration_date, subs
subscription_type=subscription_type,
subscription_id=subscription_id,
user=self.user,
site=self.site
site=self.site,
description=description
)
if number_of_enrollments:
course_enrollments = _get_course_enrollments(number_of_enrollments, self.user)
Expand All @@ -152,7 +155,8 @@ def test_user_subscription_post_update_receiver(self):
subscription_type=UserSubscription.LIMITED_ACCESS,
subscription_id=1,
user=self.user,
site=self.site
site=self.site,
description=description
)
user_subscription_history = UserSubscriptionHistory.objects.filter(
site=user_subscription.site,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ def test_user_subscription_seriaizer(self):
'subscription_type': user_subscription.subscription_type,
'user': user_subscription.user.id,
'course_enrollments': [],
'description': user_subscription.description,
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-12-01 13:36
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('subscriptions', '0003_add_user_subscription_history_model'),
]

operations = [
migrations.AddField(
model_name='usersubscription',
name='description',
field=models.TextField(blank=True, verbose_name='Description'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-12-02 10:43
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('subscriptions', '0004_usersubscription_description'),
]

operations = [
migrations.AddField(
model_name='usersubscriptionhistory',
name='description',
field=models.TextField(blank=True, verbose_name='Description'),
),
]
7 changes: 5 additions & 2 deletions openedx/features/subscriptions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class UserSubscription(TimeStampedModel):
user = models.ForeignKey(User, on_delete=models.CASCADE)
subscription_id = models.PositiveIntegerField(db_index=True)
expiration_date = models.DateField(default=None, null=True, blank=True)

description = models.TextField(_('Description'), blank=True)

LIMITED_ACCESS = 'limited-access'
FULL_ACCESS_COURSES = 'full-access-courses'
FULL_ACCESS_TIME_PERIOD = 'full-access-time-period'
Expand Down Expand Up @@ -117,6 +118,7 @@ class UserSubscriptionHistory(TimeStampedModel):
user = models.ForeignKey(User, on_delete=models.CASCADE)
subscription_id = models.PositiveIntegerField()
expiration_date = models.DateField(default=None, null=True, blank=True)
description = models.TextField(_('Description'), blank=True)

LIMITED_ACCESS = 'limited-access'
FULL_ACCESS_COURSES = 'full-access-courses'
Expand Down Expand Up @@ -167,7 +169,8 @@ def update_user_subscription_history(sender, instance, **kwargs): # pylint: dis
subscription_id=instance.subscription_id,
expiration_date=instance.expiration_date,
subscription_type=instance.subscription_type,
max_allowed_courses=instance.max_allowed_courses
max_allowed_courses=instance.max_allowed_courses,
description=instance.description
)
for course_enrollment in instance.course_enrollments.all():
user_subscription_history.course_enrollments.add(course_enrollment)