def test_with_bad_app(self):
        """Testing DeleteApplication with application not in signature"""
        mutation = DeleteApplication()

        message = (
            'Cannot delete the application "badapp". The application could '
            'not be found in the signature.')

        with self.assertRaisesMessage(SimulationFailure, message):
            mutation.run_simulation(app_label='badapp',
                                    project_sig=ProjectSignature(),
                                    database_state=None)
    def test_with_bad_app(self):
        """Testing DeleteApplication with application not in signature"""
        mutation = DeleteApplication()

        message = (
            'Cannot delete the application "badapp". The application could '
            'not be found in the signature.'
        )

        with self.assertRaisesMessage(SimulationFailure, message):
            mutation.run_simulation(app_label='badapp',
                                    project_sig=ProjectSignature(),
                                    database_state=None)
    def _perform_delete_app_test(self, sql_name, database=None):
        # Simulate deletion of the app.
        self.set_base_model(self.default_base_model,
                            extra_models=self.default_extra_models,
                            db_name=database)

        end_sig = self.copy_sig(self.start_sig)
        end_sig.pop('tests')

        d = Diff(self.start_sig, end_sig)
        self.assertEqual(sorted(d.deleted.keys()), ['tests'])
        self.assertEqual(d.deleted['tests'], [
            'TestModel', 'AppDeleteAnchor1', 'AppDeleteAnchor2',
            'CustomTestModel'
        ])

        mutation = DeleteApplication()
        self.perform_simulations([mutation],
                                 end_sig,
                                 ignore_apps=True,
                                 db_name=database)

        test_database_sig = self.copy_sig(self.database_sig)
        test_sig = self.copy_sig(self.start_sig)

        app_mutator = AppMutator('tests', test_sig, test_database_sig,
                                 database)
        app_mutator.run_mutation(mutation)
        sql = app_mutator.to_sql()

        self.assertEqual('\n'.join(sql),
                         self.get_sql_mapping(sql_name, database))
Exemple #4
0
    def _perform_delete_app_test(self, sql_name, database=None):
        # Simulate deletion of the app.
        self.set_base_model(self.default_base_model,
                            extra_models=self.default_extra_models,
                            db_name=database)

        end_sig = self.start_sig.clone()
        end_sig.remove_app_sig('tests')

        d = Diff(self.start_sig, end_sig)
        self.assertEqual(sorted(six.iterkeys(d.deleted)), ['tests'])
        self.assertEqual(d.deleted['tests'], [
            'TestModel', 'AppDeleteAnchor1', 'AppDeleteAnchor2',
            'CustomTestModel'
        ])

        mutation = DeleteApplication()
        self.perform_simulations([mutation],
                                 end_sig,
                                 ignore_apps=True,
                                 db_name=database)

        test_database_state = self.database_state.clone()
        test_sig = self.start_sig.clone()

        app_mutator = AppMutator(app_label='tests',
                                 project_sig=test_sig,
                                 database_state=test_database_state,
                                 database=database)
        app_mutator.run_mutation(mutation)
        sql = app_mutator.to_sql()

        self.assertSQLMappingEqual(sql, sql_name, database=database)
    def prepare(self, **kwargs):
        """Prepare state for this task.

        This will determine if the app's tables need to be deleted from
        the database, and prepare the SQL for doing so.

        Args:
            **kwargs (dict, unused):
                Keyword arguments passed for task preparation.
        """
        evolver = self.evolver
        mutation = DeleteApplication()

        if self.is_mutation_mutable(mutation, app_label=self.app_label):
            app_mutator = AppMutator.from_evolver(
                evolver=evolver,
                app_label=self.app_label)
            app_mutator.run_mutation(mutation)

            self.evolution_required = True
            self.sql = app_mutator.to_sql()

        self.can_simulate = True
        self.new_evolutions = []
Exemple #6
0
                            print 'MUTATIONS = ['
                            print '   ',
                            print ',\n    '.join(unicode(m) for m in mutations)
                            print ']'
                            print '#----------------------'

                    sql.extend(app_sql)
                else:
                    if verbosity > 1:
                        print 'Application %s is up to date' % app_label

            # Process the purged applications if requested to do so.
            if purge:
                if diff.deleted:
                    evolution_required = True
                    delete_app = DeleteApplication()
                    purge_sql = []

                    for app_label in diff.deleted:
                        if delete_app.is_mutable(app_label, database_sig,
                                                 database):
                            if compile_sql or execute:
                                purge_sql.append('-- Purge application %s' %
                                                 app_label)
                                purge_sql.extend(
                                    delete_app.mutate(app_label, database_sig,
                                                      database))
                            delete_app.simulate(app_label, database_sig,
                                                database)

                    if not execute:
Exemple #7
0
                            print 'MUTATIONS = ['
                            print '   ',
                            print ',\n    '.join(unicode(m) for m in mutations)
                            print ']'
                            print '#----------------------'

                    sql.extend(app_sql)
                else:
                    if verbosity > 1:
                        print 'Application %s is up to date' % app_label

            # Process the purged applications if requested to do so.
            if purge:
                if diff.deleted:
                    evolution_required = True
                    delete_app = DeleteApplication()
                    purge_sql = []

                    for app_label in diff.deleted:
                        if delete_app.is_mutable(app_label, database_sig,
                                                 database):
                            if compile_sql or execute:
                                purge_sql.append('-- Purge application %s'
                                                 % app_label)
                                purge_sql.extend(
                                    delete_app.mutate(app_label, database_sig,
                                                      database))
                            delete_app.simulate(app_label, database_sig,
                                                database)

                    if not execute:
Exemple #8
0
                     print 'MUTATIONS = ['
                     print '   ',
                     print ',\n    '.join(unicode(m) for m in mutations)
                     print ']'
                     print '#----------------------'
                     
             sql.extend(app_sql)
         else:
             if verbosity > 1:
                 print 'Application %s is up to date' % app_label
 
     # Process the purged applications if requested to do so.
     if purge:
         if diff.deleted:
             evolution_required = True
             delete_app = DeleteApplication()
             purge_sql = []
             for app_label in diff.deleted:
                 if compile_sql or execute:
                     purge_sql.append('-- Purge application %s' % app_label)
                     purge_sql.extend(delete_app.mutate(app_label, database_sig))
                 delete_app.simulate(app_label, database_sig)
             
             if not execute:
                 if compile_sql:
                     write_sql(purge_sql)
                 else:
                     print 'The following application(s) can be purged:'
                     for app_label in diff.deleted:
                         print '    ', app_label
                     print
Exemple #9
0
                    if not execute:
                        if compile_sql:
                            write_sql(app_sql, database)
                        else:
                            print self.generate_hint(app, app_label, mutations)

                    sql.extend(app_sql)
                else:
                    if verbosity > 1:
                        print "Application %s is up to date" % app_label

            # Process the purged applications if requested to do so.
            if purge:
                if diff.deleted:
                    evolution_required = True
                    delete_app = DeleteApplication()
                    purge_sql = []

                    for app_label in diff.deleted:
                        if delete_app.is_mutable(app_label, database_sig, database):
                            if compile_sql or execute:
                                purge_sql.append("-- Purge application %s" % app_label)
                                purge_sql.extend(delete_app.mutate(app_label, database_sig, database))
                            delete_app.simulate(app_label, database_sig, database)

                    if not execute:
                        if compile_sql:
                            write_sql(purge_sql, database)
                        else:
                            print "The following application(s) can be purged:"
Exemple #10
0
                            print 'MUTATIONS = ['
                            print '   ',
                            print ',\n    '.join(unicode(m) for m in mutations)
                            print ']'
                            print '#----------------------'

                    sql.extend(app_sql)
                else:
                    if verbosity > 1:
                        print 'Application %s is up to date' % app_label

            # Process the purged applications if requested to do so.
            if purge:
                if diff.deleted:
                    evolution_required = True
                    delete_app = DeleteApplication()
                    purge_sql = []
                    for app_label in diff.deleted:
                        if compile_sql or execute:
                            purge_sql.append('-- Purge application %s' %
                                             app_label)
                            purge_sql.extend(
                                delete_app.mutate(app_label, database_sig))
                        delete_app.simulate(app_label, database_sig)

                    if not execute:
                        if compile_sql:
                            write_sql(purge_sql)
                        else:
                            print 'The following application(s) can be purged:'
                            for app_label in diff.deleted: