def test_diff_identical_model(self): """Testing Diff with identical signatures""" class DestModel(BaseTestModel): name = models.CharField(max_length=20) age = models.IntegerField() ref = models.ForeignKey(DiffAnchor1, on_delete=models.CASCADE) end_sig = self.make_end_signatures(DestModel, 'TestModel')[1] d = Diff(self.start_sig, end_sig) self.assertTrue(d.is_empty()) self.assertEqual(d.evolution(), {})
def test_diff_identical_model(self): """Testing Diff with identical signatures""" class DestModel(models.Model): name = models.CharField(max_length=20) age = models.IntegerField() ref = models.ForeignKey(DiffAnchor1, on_delete=models.CASCADE) end_sig = self.make_end_signatures(DestModel, 'TestModel')[1] d = Diff(self.start_sig, end_sig) self.assertTrue(d.is_empty()) self.assertEqual(d.evolution(), {})
def perform_diff_test(self, end_sig, diff_text, expected_hint, expect_empty=False): d = Diff(self.start_sig, end_sig) self.assertEqual(d.is_empty(), expect_empty) if not expect_empty: if diff_text is not None: self.assertEqual(str(d), diff_text) if expected_hint is not None: self.assertEqual( [str(e) for e in d.evolution()['tests']], expected_hint) return d
def perform_diff_test(self, end_sig, diff_text=None, expected_hint=None, expect_empty=False): """Generate a diff between signatures and check for expected results. The registered base signature and the provided ending signature will be diffed, asserted to be empty/not empty (depending on the arguments), and then checked against the provided diff text and hint. Args: end_sig (django_evolution.signature.ProjectSignature): The expected project signature at the end of the evolution. This is generated by :py:meth:`make_end_signatures`. diff_text (unicode, optional): The expected generated text describing a diff that must match, if provided. expected_hint (unicode, optional): The expected generated hint text that must match, if provided. expect_empty (bool, optional): Whether the diff is expected to be empty. Returns: django_evolution.diff.Diff: The resulting diff. Raises: AssertionError: One of the expectations has failed. """ d = Diff(self.start_sig, end_sig) self.assertEqual(d.is_empty(), expect_empty) if not expect_empty: if diff_text is not None: self.assertEqual(str(d), diff_text) if expected_hint is not None: self.assertEqual([str(e) for e in d.evolution()['tests']], expected_hint) return d
def perform_diff_test(self, end_sig, diff_text, expected_hint, expect_empty=False): d = Diff(self.start_sig, end_sig) self.assertEqual(d.is_empty(), expect_empty) if not expect_empty: if diff_text is not None: self.assertEqual(str(d), diff_text) if expected_hint is not None: self.assertEqual([str(e) for e in d.evolution()['tests']], expected_hint) return d
latest_version = Version.objects.using(database).latest('when') else: latest_version = Version.objects.latest('when') database_sig = pickle.loads(str(latest_version.signature)) diff = Diff(database_sig, current_proj_sig) except Evolution.DoesNotExist: raise CommandError("Can't evolve yet. Need to set an " "evolution baseline.") try: for app in app_list: app_label = app.__name__.split('.')[-2] if hint: evolutions = [] hinted_evolution = diff.evolution() temp_mutations = hinted_evolution.get(app_label, []) else: evolutions = get_unapplied_evolutions(app, database) temp_mutations = get_mutations(app, evolutions, database) mutations = [ mutation for mutation in temp_mutations if mutation.is_mutable(app_label, database_sig, database) ] if mutations: app_sql = ['-- Evolve application %s' % app_label] evolution_required = True for mutation in mutations:
latest_version = Version.objects.using(database).latest('when') else: latest_version = Version.objects.latest('when') database_sig = pickle.loads(str(latest_version.signature)) diff = Diff(database_sig, current_proj_sig) except Evolution.DoesNotExist: raise CommandError("Can't evolve yet. Need to set an " "evolution baseline.") try: for app in app_list: app_label = app.__name__.split('.')[-2] if hint: evolutions = [] hinted_evolution = diff.evolution() temp_mutations = hinted_evolution.get(app_label, []) else: evolutions = get_unapplied_evolutions(app, database) temp_mutations = get_mutations(app, evolutions, database) mutations = [ mutation for mutation in temp_mutations if mutation.is_mutable(app_label, database_sig, database) ] if mutations: app_sql = ['-- Evolve application %s' % app_label] evolution_required = True