From fa6633ba4e8762c3aceb3f6c952d246829a74984 Mon Sep 17 00:00:00 2001 From: Abdul Hannan Date: Fri, 13 Mar 2020 00:40:19 +0500 Subject: [PATCH] DO NOT MERGE - NEED FAKE - Rename start in schedule 5/5 (#22392) * Remove start field in Schedules Co-authored-by: hunytalk Co-authored-by: Cory Lee --- common/djangoapps/student/tests/test_views.py | 9 +++------ common/djangoapps/util/tests/test_db.py | 1 - lms/djangoapps/mobile_api/users/tests.py | 1 - .../setup_models_to_send_test_emails.py | 5 ----- .../commands/tests/send_email_base.py | 1 - .../commands/tests/test_send_course_update.py | 1 - .../0016_remove_start_from_schedules.py | 19 +++++++++++++++++++ openedx/core/djangoapps/schedules/models.py | 7 +------ openedx/core/djangoapps/schedules/signals.py | 2 -- .../djangoapps/schedules/tests/factories.py | 2 -- .../tests/test_course_expiration.py | 4 ++-- 11 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 openedx/core/djangoapps/schedules/migrations/0016_remove_start_from_schedules.py diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index 1e9ecc2360..be6102ed4e 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -783,12 +783,9 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin, user=self.user, course_id=course.id ) - startdate = self.THREE_YEARS_AGO + timedelta(days=1) - schedule = ScheduleFactory( - start=startdate, - start_date=startdate, - enrollment=enrollment - ) + + # pylint: disable=unused-variable + schedule = ScheduleFactory(start_date=self.THREE_YEARS_AGO + timedelta(days=1), enrollment=enrollment) response = self.client.get(reverse('dashboard')) dashboard_html = self._remove_whitespace_from_response(response) diff --git a/common/djangoapps/util/tests/test_db.py b/common/djangoapps/util/tests/test_db.py index 25dcc3b151..efec55919f 100644 --- a/common/djangoapps/util/tests/test_db.py +++ b/common/djangoapps/util/tests/test_db.py @@ -196,7 +196,6 @@ class MigrationTests(TestCase): """ Tests for migrations. """ - @unittest.skip( "Need to skip as part of renaming a field in schedules app. This will be unskipped in DE-1825." ) diff --git a/lms/djangoapps/mobile_api/users/tests.py b/lms/djangoapps/mobile_api/users/tests.py index 3497766157..e06de0309f 100644 --- a/lms/djangoapps/mobile_api/users/tests.py +++ b/lms/djangoapps/mobile_api/users/tests.py @@ -281,7 +281,6 @@ class TestUserEnrollmentApi(UrlResetMixin, MobileAPITestCase, MobileAuthUserTest course_id=course.id ) ScheduleFactory( - start=self.THREE_YEARS_AGO + datetime.timedelta(days=1), start_date=self.THREE_YEARS_AGO + datetime.timedelta(days=1), enrollment=enrollment ) diff --git a/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py b/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py index a4cd3c9c5a..a8206f6685 100644 --- a/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py +++ b/openedx/core/djangoapps/schedules/management/commands/setup_models_to_send_test_emails.py @@ -26,7 +26,6 @@ class ThreeDayNudgeSchedule(ScheduleFactory): """ A ScheduleFactory that creates a Schedule set up for a 3-day nudge email. """ - start = factory.Faker('date_time_between', start_date='-3d', end_date='-3d', tzinfo=pytz.UTC) start_date = factory.Faker('date_time_between', start_date='-3d', end_date='-3d', tzinfo=pytz.UTC) @@ -34,7 +33,6 @@ class TenDayNudgeSchedule(ScheduleFactory): """ A ScheduleFactory that creates a Schedule set up for a 10-day nudge email. """ - start = factory.Faker('date_time_between', start_date='-10d', end_date='-10d', tzinfo=pytz.UTC) start_date = factory.Faker('date_time_between', start_date='-10d', end_date='-10d', tzinfo=pytz.UTC) @@ -42,7 +40,6 @@ class UpgradeReminderSchedule(ScheduleFactory): """ A ScheduleFactory that creates a Schedule set up for a 2-days-remaining upgrade reminder. """ - start = factory.Faker('past_datetime', tzinfo=pytz.UTC) start_date = factory.Faker('past_datetime', tzinfo=pytz.UTC) upgrade_deadline = factory.Faker('date_time_between', start_date='+2d', end_date='+2d', tzinfo=pytz.UTC) @@ -51,7 +48,6 @@ class ContentHighlightSchedule(ScheduleFactory): """ A ScheduleFactory that creates a Schedule set up for a course highlights email. """ - start = factory.Faker('date_time_between', start_date='-7d', end_date='-7d', tzinfo=pytz.UTC) start_date = factory.Faker('date_time_between', start_date='-7d', end_date='-7d', tzinfo=pytz.UTC) experience = factory.RelatedFactory(ScheduleExperienceFactory, 'schedule', experience_type=ScheduleExperience.EXPERIENCES.course_updates) @@ -74,7 +70,6 @@ class Command(BaseCommand): CourseFactory.reset_sequence(max_org_sequence_id + 1, force=True) course = CourseFactory.create( start=datetime.datetime.today() - datetime.timedelta(days=30), - start_date=datetime.datetime.today() - datetime.timedelta(days=30), end=datetime.datetime.today() + datetime.timedelta(days=30), number=factory.Sequence('schedules_test_course_{}'.format), display_name=factory.Sequence(u'Schedules Test Course {}'.format), diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py index b76054d8fb..a9beb4311f 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/send_email_base.py @@ -136,7 +136,6 @@ class ScheduleSendEmailTestMixin(FilteredQueryCountMixin): def _schedule_factory(self, offset=None, **factory_kwargs): _, _, target_day, upgrade_deadline = self._get_dates(offset=offset) - factory_kwargs.setdefault('start', target_day) factory_kwargs.setdefault('start_date', target_day) factory_kwargs.setdefault('upgrade_deadline', upgrade_deadline) factory_kwargs.setdefault('enrollment__course__self_paced', True) diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py index 866102116b..abda561ab8 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py @@ -75,7 +75,6 @@ class TestSendCourseUpdate(ScheduleUpsellTestMixin, ScheduleSendEmailTestMixin, self.assertEqual(enrollment.schedule.get_experience_type(), ScheduleExperience.EXPERIENCES.course_updates) _, offset, target_day, _ = self._get_dates(offset=self.expected_offsets[0]) - enrollment.schedule.start = target_day enrollment.schedule.start_date = target_day enrollment.schedule.save() diff --git a/openedx/core/djangoapps/schedules/migrations/0016_remove_start_from_schedules.py b/openedx/core/djangoapps/schedules/migrations/0016_remove_start_from_schedules.py new file mode 100644 index 0000000000..fbbee57218 --- /dev/null +++ b/openedx/core/djangoapps/schedules/migrations/0016_remove_start_from_schedules.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-01-07 18:46 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('schedules', '0015_schedules_start_nullable'), + ] + + operations = [ + migrations.RemoveField( + model_name='schedule', + name='start', + ), + ] diff --git a/openedx/core/djangoapps/schedules/models.py b/openedx/core/djangoapps/schedules/models.py index 4d758678ba..fd3c5a0dd3 100644 --- a/openedx/core/djangoapps/schedules/models.py +++ b/openedx/core/djangoapps/schedules/models.py @@ -19,17 +19,12 @@ class Schedule(TimeStampedModel): default=True, help_text=_('Indicates if this schedule is actively used') ) - # TODO Delete this field during last stage of rolling out field renames - start = models.DateTimeField( + start_date = models.DateTimeField( db_index=True, help_text=_('Date this schedule went into effect'), null=True, default=None ) - start_date = models.DateTimeField( - db_index=True, - help_text=_('Date this schedule went into effect') - ) upgrade_deadline = models.DateTimeField( blank=True, db_index=True, diff --git a/openedx/core/djangoapps/schedules/signals.py b/openedx/core/djangoapps/schedules/signals.py index 0dbc6a7ee8..dae8082184 100644 --- a/openedx/core/djangoapps/schedules/signals.py +++ b/openedx/core/djangoapps/schedules/signals.py @@ -210,8 +210,6 @@ def _create_schedule(enrollment, enrollment_created): schedule = Schedule.objects.create( enrollment=enrollment, - # TODO remove 'start' field in removing writes from old field step in column renaming release - start=content_availability_date, start_date=content_availability_date, upgrade_deadline=upgrade_deadline ) diff --git a/openedx/core/djangoapps/schedules/tests/factories.py b/openedx/core/djangoapps/schedules/tests/factories.py index 966e41f981..f7d13ab8a3 100644 --- a/openedx/core/djangoapps/schedules/tests/factories.py +++ b/openedx/core/djangoapps/schedules/tests/factories.py @@ -22,8 +22,6 @@ class ScheduleFactory(factory.DjangoModelFactory): class Meta(object): model = models.Schedule - # TODO drop 'start' when removing this field in column renaming release - start = factory.Faker('future_datetime', tzinfo=pytz.UTC) start_date = factory.Faker('future_datetime', tzinfo=pytz.UTC) upgrade_deadline = factory.Faker('future_datetime', tzinfo=pytz.UTC) enrollment = factory.SubFactory(CourseEnrollmentFactory) diff --git a/openedx/features/course_duration_limits/tests/test_course_expiration.py b/openedx/features/course_duration_limits/tests/test_course_expiration.py index 720af17159..68f87527c1 100644 --- a/openedx/features/course_duration_limits/tests/test_course_expiration.py +++ b/openedx/features/course_duration_limits/tests/test_course_expiration.py @@ -338,7 +338,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase): expired_staff = role_factory.create(password=TEST_PASSWORD, course_key=self.course.id) ScheduleFactory( - start=self.THREE_YEARS_AGO, + start_date=self.THREE_YEARS_AGO, enrollment__mode=CourseMode.AUDIT, enrollment__course_id=self.course.id, enrollment__user=expired_staff @@ -386,7 +386,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase): role.users.add(expired_staff) ScheduleFactory( - start=self.THREE_YEARS_AGO, + start_date=self.THREE_YEARS_AGO, enrollment__mode=CourseMode.AUDIT, enrollment__course_id=self.course.id, enrollment__user=expired_staff