Commit fd3c38ca by Clinton Blackburn Committed by Clinton Blackburn

Added __str__ methods to the ProgramType and SeatType models

ECOM-5173
parent e617b248
...@@ -411,6 +411,9 @@ class SeatType(TimeStampedModel): ...@@ -411,6 +411,9 @@ class SeatType(TimeStampedModel):
name = models.CharField(max_length=64, unique=True) name = models.CharField(max_length=64, unique=True)
slug = AutoSlugField(populate_from='name') slug = AutoSlugField(populate_from='name')
def __str__(self):
return self.name
class Seat(TimeStampedModel): class Seat(TimeStampedModel):
""" Seat model. """ """ Seat model. """
...@@ -503,6 +506,9 @@ class ProgramType(TimeStampedModel): ...@@ -503,6 +506,9 @@ class ProgramType(TimeStampedModel):
'of the course counted toward the completion of the program.'), 'of the course counted toward the completion of the program.'),
) )
def __str__(self):
return self.name
class Program(TimeStampedModel): class Program(TimeStampedModel):
class ProgramStatus(DjangoChoices): class ProgramStatus(DjangoChoices):
......
...@@ -12,7 +12,7 @@ from course_discovery.apps.core.tests.factories import PartnerFactory ...@@ -12,7 +12,7 @@ from course_discovery.apps.core.tests.factories import PartnerFactory
from course_discovery.apps.core.tests.utils import FuzzyURL from course_discovery.apps.core.tests.utils import FuzzyURL
from course_discovery.apps.course_metadata.models import ( from course_discovery.apps.course_metadata.models import (
Course, CourseRun, Organization, Person, Image, Video, Subject, Seat, Prerequisite, LevelType, Program, Course, CourseRun, Organization, Person, Image, Video, Subject, Seat, Prerequisite, LevelType, Program,
AbstractSocialNetworkModel, CourseRunSocialNetwork, PersonSocialNetwork, ProgramType AbstractSocialNetworkModel, CourseRunSocialNetwork, PersonSocialNetwork, ProgramType, SeatType,
) )
from course_discovery.apps.ietf_language_tags.models import LanguageTag from course_discovery.apps.ietf_language_tags.models import LanguageTag
...@@ -229,3 +229,10 @@ class CourseRunSocialNetworkFactory(AbstractSocialNetworkModelFactory): ...@@ -229,3 +229,10 @@ class CourseRunSocialNetworkFactory(AbstractSocialNetworkModelFactory):
class Meta: class Meta:
model = CourseRunSocialNetwork model = CourseRunSocialNetwork
class SeatTypeFactory(factory.django.DjangoModelFactory):
class Meta(object):
model = SeatType
name = FuzzyText()
...@@ -316,7 +316,7 @@ class ProgramTests(TestCase): ...@@ -316,7 +316,7 @@ class ProgramTests(TestCase):
factories.SeatFactory(type='credit', currency=currency, course_run=course_run, price=600) factories.SeatFactory(type='credit', currency=currency, course_run=course_run, price=600)
factories.SeatFactory(type='verified', currency=currency, course_run=course_run, price=100) factories.SeatFactory(type='verified', currency=currency, course_run=course_run, price=100)
applicable_seat_types = SeatType.objects.filter(slug__in=['credit', 'verified']) applicable_seat_types = SeatType.objects.filter(slug__in=['credit', 'verified'])
program_type = factories.ProgramTypeFactory(name='XSeries', applicable_seat_types=applicable_seat_types) program_type = factories.ProgramTypeFactory(applicable_seat_types=applicable_seat_types)
program = factories.ProgramFactory(type=program_type, courses=[course_run.course]) program = factories.ProgramFactory(type=program_type, courses=[course_run.course])
expected_price_ranges = [{'currency': 'USD', 'min': Decimal(100), 'max': Decimal(600)}] expected_price_ranges = [{'currency': 'USD', 'min': Decimal(100), 'max': Decimal(600)}]
...@@ -374,3 +374,17 @@ class CourseSocialNetworkTests(TestCase): ...@@ -374,3 +374,17 @@ class CourseSocialNetworkTests(TestCase):
factories.CourseRunSocialNetworkFactory(course_run=self.course_run, type='facebook') factories.CourseRunSocialNetworkFactory(course_run=self.course_run, type='facebook')
with self.assertRaises(IntegrityError): with self.assertRaises(IntegrityError):
factories.CourseRunSocialNetworkFactory(course_run=self.course_run, type='facebook') factories.CourseRunSocialNetworkFactory(course_run=self.course_run, type='facebook')
class SeatTypeTests(TestCase):
""" Tests of the SeatType model. """
def test_str(self):
seat_type = factories.SeatTypeFactory()
self.assertEqual(str(seat_type), seat_type.name)
class ProgramTypeTests(TestCase):
""" Tests of the ProgramType model. """
def test_str(self):
program_type = factories.ProgramTypeFactory()
self.assertEqual(str(program_type), program_type.name)
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