Commit 7af7880b by Bill DeRusha

Refactor 'value' models into shared abstract model

parent 3870cec7
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('course_metadata', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='expectedlearningitem',
options={},
),
migrations.AlterModelOptions(
name='syllabusitem',
options={},
),
]
......@@ -23,6 +23,17 @@ class AbstractNamedModel(TimeStampedModel):
abstract = True
class AbstractValueModel(TimeStampedModel):
""" Abstract base class for models with only a value field. """
value = models.CharField(max_length=255)
def __str__(self):
return self.value
class Meta(object):
abstract = True
class AbstractMediaModel(TimeStampedModel):
""" Abstract base class for media-related (e.g. image, video) models. """
src = models.URLField(max_length=255, unique=True)
......@@ -58,18 +69,14 @@ class Prerequisite(AbstractNamedModel):
pass
class ExpectedLearningItem(TimeStampedModel):
class ExpectedLearningItem(AbstractValueModel):
""" ExpectedLearningItem model. """
value = models.CharField(max_length=255)
def __str__(self):
return self.value
pass
class SyllabusItem(TimeStampedModel):
class SyllabusItem(AbstractValueModel):
""" SyllabusItem model. """
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
value = models.CharField(max_length=255)
class Organization(TimeStampedModel):
......
......@@ -2,7 +2,7 @@ import ddt
from django.test import TestCase
from course_discovery.apps.course_metadata.models import(
AbstractNamedModel, AbstractMediaModel, CourseOrganization, ExpectedLearningItem
AbstractNamedModel, AbstractMediaModel, AbstractValueModel, CourseOrganization
)
from course_discovery.apps.course_metadata.tests import factories
......@@ -124,12 +124,15 @@ class AbstractMediaModelTests(TestCase):
self.assertEqual(str(instance), src)
class ExpectedLearningItemTests(TestCase):
""" Tests for ExpectedLearningItem. """
class AbstractValueModelTests(TestCase):
""" Tests for AbstractValueModel. """
def test_str(self):
""" Verify casting an instance to a string returns a string containing the value. """
value = 'Expected learnings'
instance = ExpectedLearningItem(value=value)
class TestAbstractValueModel(AbstractValueModel):
pass
value = 'abc'
instance = TestAbstractValueModel(value=value)
self.assertEqual(str(instance), value)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment