def test_next_sync_setting_retroactive(self):
""" Test whether the migration can also handle existing data. """
now = timezone.now().replace(microsecond=0)
TemperatureReading.objects.create(
read_at=now + timezone.timedelta(hours=1),
degrees_celcius=20,
)
TemperatureReading.objects.create(
read_at=now,
degrees_celcius=20,
)
self.assertIsNone(WeatherSettings.get_solo().next_sync)
# Now we fake applying the migration (again for this test).
MigrationRecorder.Migration.objects.filter(
app='dsmr_weather', name='0004_next_sync_setting_retroactive'
).delete()
MigrationExecutor(connection=connection).migrate([(self.app, '0004_next_sync_setting_retroactive')])
# When having existing data, next_sync should be based on latest reading.
self.assertEqual(WeatherSettings.get_solo().next_sync, now + timezone.timedelta(hours=2))
test_next_sync_setting_retroactive.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录