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))
    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.assertEqual('\n'.join(sql),
                         self.get_sql_mapping(sql_name, database))
Exemple #3
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)