Example #1
0
    def test_running_without_changes(self):
        project_state = self.set_up_test_model("test_arstd")
        operation = AlterStorageEngine("Pony", from_engine="MyISAM",
                                       to_engine="InnoDB")

        assert table_storage_engine("test_arstd_pony") == "InnoDB"

        # Forwards - shouldn't actually do an ALTER since it is already InnoDB
        new_state = project_state.clone()
        operation.state_forwards("test_arstd", new_state)
        capturer = CaptureQueriesContext(connection)
        with capturer, connection.schema_editor() as editor:
            operation.database_forwards("test_arstd", editor, project_state,
                                        new_state)
        queries = [q['sql'] for q in capturer.captured_queries]
        assert not any(q.startswith('ALTER TABLE ') for q in queries), (
            "One of the executed queries was an unexpected ALTER TABLE:\n{}"
            .format("\n".join(queries))
        )
        assert table_storage_engine("test_arstd_pony") == "InnoDB"

        # Backwards - will actually ALTER since it is going 'back' to MyISAM
        with connection.schema_editor() as editor:
            operation.database_backwards("test_arstd", editor, new_state,
                                         project_state)
        assert table_storage_engine("test_arstd_pony") == "MyISAM"
Example #2
0
    def test_no_from_means_unreversible(self):
        operation = AlterStorageEngine("mymodel", to_engine="InnoDB")
        assert not operation.reversible

        with pytest.raises(NotImplementedError) as excinfo:
            operation.database_backwards(None, None, None, None)

        assert str(excinfo.value) == "You cannot reverse this operation"
    def test_no_from_means_unreversible(self):
        operation = AlterStorageEngine("mymodel", to_engine="InnoDB")
        assert not operation.reversible

        with pytest.raises(NotImplementedError) as excinfo:
            operation.database_backwards(None, None, None, None)

        assert str(excinfo.value) == "You cannot reverse this operation"
Example #4
0
    def test_no_from_means_unreversible(self):
        operation = AlterStorageEngine("mymodel", to_engine="InnoDB")
        self.assertFalse(operation.reversible)

        with self.assertRaises(NotImplementedError) as cm:
            operation.database_backwards(None, None, None, None)

        self.assertEqual(
            str(cm.exception),
            "You cannot reverse this operation"
        )
Example #5
0
    def test_running_with_changes(self):
        project_state = self.set_up_test_model("test_arstd")
        operation = AlterStorageEngine("Pony", from_engine="MyISAM",
                                       to_engine="InnoDB")

        assert table_storage_engine("test_arstd_pony") == "MyISAM"

        # Forwards
        new_state = project_state.clone()
        operation.state_forwards("test_arstd", new_state)
        with connection.schema_editor() as editor:
            operation.database_forwards("test_arstd", editor, project_state,
                                        new_state)
        assert table_storage_engine("test_arstd_pony") == "InnoDB"

        # Backwards
        with connection.schema_editor() as editor:
            operation.database_backwards("test_arstd", editor, new_state,
                                         project_state)
        assert table_storage_engine("test_arstd_pony") == "MyISAM"