Skip to content

Commit

Permalink
feat: Add default value for status in Program Model and remove hardco…
Browse files Browse the repository at this point in the history
…ded value from degree loader
  • Loading branch information
AliAdnanSohail committed Jun 23, 2022
1 parent fece2d4 commit 6bb3974
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import csv
import logging

from course_discovery.apps.course_metadata.choices import ProgramStatus
from course_discovery.apps.course_metadata.data_loaders import AbstractDataLoader
from course_discovery.apps.course_metadata.models import (
Curriculum, Degree, DegreeAdditionalMetadata, LanguageTag, LevelType, Organization, Program, ProgramType,
Expand Down Expand Up @@ -164,7 +163,6 @@ def _update_or_create_degree(
"""
data_dict = {
"type": program_type,
"status": ProgramStatus.Unpublished,
"primary_subject_override": primary_subject_override,
"level_type_override": level_type_override,
"language_override": language_override,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from course_discovery.apps.api.v1.tests.test_views.mixins import APITestCase, OAuth2Mixin
from course_discovery.apps.core.tests.factories import USER_PASSWORD, UserFactory
from course_discovery.apps.course_metadata.choices import ProgramStatus
from course_discovery.apps.course_metadata.data_loaders.degrees_loader import DegreeCSVDataLoader
from course_discovery.apps.course_metadata.data_loaders.tests import mock_data
from course_discovery.apps.course_metadata.data_loaders.tests.mixins import DegreeCSVLoaderMixin
Expand Down Expand Up @@ -258,6 +259,7 @@ def test_ingest_flow_for_minimal_degree_data(self, jwt_decode_patch): # pylint:
assert degree.additional_metadata.external_identifier == '123456'
assert degree.additional_metadata.organic_url == 'http://example.com/organic-page.html'
assert degree.specializations.count() == 2
assert degree.status == ProgramStatus.Unpublished

@responses.activate
def test_image_download_failure(self, jwt_decode_patch): # pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.13 on 2022-06-20 16:21

from django.db import migrations, models
import djchoices.choices


class Migration(migrations.Migration):

dependencies = [
('course_metadata', '0285_org_uuid_editable'),
]

operations = [
migrations.AlterField(
model_name='historicalprogram',
name='status',
field=models.CharField(choices=[('unpublished', 'Unpublished'), ('active', 'Active'), ('retired', 'Retired'), ('deleted', 'Deleted')], db_index=True, default='unpublished', help_text='The lifecycle status of this Program.', max_length=24, validators=[djchoices.choices.ChoicesValidator({'active': 'Active', 'deleted': 'Deleted', 'retired': 'Retired', 'unpublished': 'Unpublished'})]),
),
migrations.AlterField(
model_name='program',
name='status',
field=models.CharField(choices=[('unpublished', 'Unpublished'), ('active', 'Active'), ('retired', 'Retired'), ('deleted', 'Deleted')], db_index=True, default='unpublished', help_text='The lifecycle status of this Program.', max_length=24, validators=[djchoices.choices.ChoicesValidator({'active': 'Active', 'deleted': 'Deleted', 'retired': 'Retired', 'unpublished': 'Unpublished'})]),
),
]
2 changes: 1 addition & 1 deletion course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ class Program(PkSearchableMixin, TimeStampedModel):
type = models.ForeignKey(ProgramType, models.CASCADE, null=True, blank=True)
status = models.CharField(
help_text=_('The lifecycle status of this Program.'), max_length=24, null=False, blank=False, db_index=True,
choices=ProgramStatus.choices, validators=[ProgramStatus.validator]
choices=ProgramStatus.choices, validators=[ProgramStatus.validator], default=ProgramStatus.Unpublished
)
marketing_slug = models.CharField(
help_text=_('Slug used to generate links to the marketing site'), unique=True, max_length=255, db_index=True)
Expand Down
7 changes: 5 additions & 2 deletions course_discovery/apps/course_metadata/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class Meta:
source = FuzzyText(length=99)


class ProgramFactory(factory.django.DjangoModelFactory):
class ProgramBaseFactory(factory.django.DjangoModelFactory):
class Meta:
model = Program

Expand All @@ -514,7 +514,6 @@ class Meta:
subtitle = FuzzyText()
marketing_hook = FuzzyText()
type = factory.SubFactory(ProgramTypeFactory)
status = ProgramStatus.Active
marketing_slug = factory.Sequence(lambda n: f'test-slug-{n}')
card_image_url = FuzzyText(prefix='https://example.com/program/card')
partner = factory.SubFactory(PartnerFactory)
Expand Down Expand Up @@ -590,6 +589,10 @@ def curricula(self, create, extracted, **kwargs):
add_m2m_data(self.curricula, extracted)


class ProgramFactory(ProgramBaseFactory):
status = ProgramStatus.Active


class SpecializationFactory(factory.django.DjangoModelFactory):
class Meta:
model = Specialization
Expand Down
5 changes: 5 additions & 0 deletions course_discovery/apps/course_metadata/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,11 @@ def test_same_title_slug_programs(self):
weeks_to_complete=15
)

def test_program_default_status(self):
"""Verify that program default status is Unpublished"""
program = factories.ProgramBaseFactory()
assert program.status == ProgramStatus.Unpublished


class PathwayTests(TestCase):
""" Tests of the Pathway model."""
Expand Down

0 comments on commit 6bb3974

Please sign in to comment.