def test_evolve_with_hinted(self): """Testing Evolver.evolve with hinting""" model_sig = ModelSignature.from_model(EvolverTestModel) model_sig.get_field_sig('value').field_attrs['max_length'] = 50 app_sig = AppSignature(app_id='tests') app_sig.add_model_sig(model_sig) orig_version = Version.objects.current_version() orig_version.signature.add_app_sig(app_sig) orig_version.save() with ensure_test_db(model_entries=[('TestModel', EvolverTestModel)]): evolver = Evolver(hinted=True) evolver.queue_evolve_app(evo_test) evolver.evolve() self.assertTrue(evolver.evolved) version = Version.objects.current_version() self.assertNotEqual(version, orig_version) self.assertTrue(version.is_hinted()) model_sig = ( version.signature.get_app_sig('tests').get_model_sig('TestModel')) self.assertEqual( model_sig.get_field_sig('value').field_attrs['max_length'], 100)
def test_evolve_with_hinted(self): """Testing Evolver.evolve with hinting""" model_sig = ModelSignature.from_model(EvolverTestModel) model_sig.get_field_sig('value').field_attrs['max_length'] = 50 app_sig = AppSignature(app_id='tests') app_sig.add_model_sig(model_sig) orig_version = Version.objects.current_version() orig_version.signature.add_app_sig(app_sig) orig_version.save() with ensure_test_db(model_entries=[('TestModel', EvolverTestModel)]): evolver = Evolver(hinted=True) evolver.queue_evolve_app(evo_test) evolver.evolve() self.assertTrue(evolver.evolved) version = Version.objects.current_version() self.assertNotEqual(version, orig_version) self.assertTrue(version.is_hinted()) model_sig = ( version.signature .get_app_sig('tests') .get_model_sig('TestModel') ) self.assertEqual( model_sig.get_field_sig('value').field_attrs['max_length'], 100)
def test_evolve(self): """Testing Evolver.evolve""" model_sig = ModelSignature.from_model(EvolverTestModel) model_sig.get_field_sig('value').field_attrs['max_length'] = 50 app_sig = AppSignature(app_id='tests') app_sig.add_model_sig(model_sig) orig_version = Version.objects.current_version() orig_version.signature.add_app_sig(app_sig) orig_version.save() with ensure_test_db(model_entries=[('TestModel', EvolverTestModel)]): evolver = Evolver() evolver.queue_task( EvolveAppTask(evolver=evolver, app=evo_test, evolutions=[ { 'label': 'my_evolution1', 'mutations': [ ChangeField('TestModel', 'value', max_length=200), ], }, { 'label': 'my_evolution2', 'mutations': [ AddField('TestModel', 'new_field', models.BooleanField, null=True), ], }, ])) evolver.evolve() self.assertTrue(evolver.evolved) version = Version.objects.current_version() self.assertNotEqual(version, orig_version) self.assertFalse(version.is_hinted()) evolutions = list(version.evolutions.all()) self.assertEqual(len(evolutions), 2) self.assertEqual(evolutions[0].app_label, 'tests') self.assertEqual(evolutions[0].label, 'my_evolution1') self.assertEqual(evolutions[1].app_label, 'tests') self.assertEqual(evolutions[1].label, 'my_evolution2') model_sig = ( version.signature.get_app_sig('tests').get_model_sig('TestModel')) self.assertEqual( model_sig.get_field_sig('value').field_attrs['max_length'], 200) self.assertIsNotNone(model_sig.get_field_sig('new_field'))
def test_evolve(self): """Testing Evolver.evolve""" model_sig = ModelSignature.from_model(EvolverTestModel) model_sig.get_field_sig('value').field_attrs['max_length'] = 50 app_sig = AppSignature(app_id='tests') app_sig.add_model_sig(model_sig) orig_version = Version.objects.current_version() orig_version.signature.add_app_sig(app_sig) orig_version.save() with ensure_test_db(model_entries=[('TestModel', EvolverTestModel)]): evolver = Evolver() evolver.queue_task(EvolveAppTask( evolver=evolver, app=evo_test, evolutions=[ { 'label': 'my_evolution1', 'mutations': [ ChangeField('TestModel', 'value', max_length=200), ], }, { 'label': 'my_evolution2', 'mutations': [ AddField('TestModel', 'new_field', models.BooleanField, null=True), ], }, ])) evolver.evolve() self.assertTrue(evolver.evolved) version = Version.objects.current_version() self.assertNotEqual(version, orig_version) self.assertFalse(version.is_hinted()) evolutions = list(version.evolutions.all()) self.assertEqual(len(evolutions), 2) self.assertEqual(evolutions[0].app_label, 'tests') self.assertEqual(evolutions[0].label, 'my_evolution1') self.assertEqual(evolutions[1].app_label, 'tests') self.assertEqual(evolutions[1].label, 'my_evolution2') model_sig = ( version.signature .get_app_sig('tests') .get_model_sig('TestModel') ) self.assertEqual( model_sig.get_field_sig('value').field_attrs['max_length'], 200) self.assertIsNotNone(model_sig.get_field_sig('new_field'))
def ensure_evolved_apps(self, apps): """Ensure an app's models and evolutions are applied to the database. Args: apps (list of module): The app modules to evolve. """ evolver = Evolver() for app in apps: evolver.queue_evolve_app(app) evolver.evolve()