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"
Esempio n. 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"
Esempio n. 3
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"
        )
Esempio n. 4
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"
Esempio n. 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"
Esempio n. 6
0
 def test_references_model(self):
     operation = AlterStorageEngine("Pony", "InnoDB")
     assert operation.references_model("PONY")
     assert operation.references_model("Pony")
     assert operation.references_model("pony")
     assert not operation.references_model("poony")
Esempio n. 7
0
 def test_describe_with_from(self):
     operation = AlterStorageEngine("Pony",
                                    from_engine="MyISAM",
                                    to_engine="InnoDB")
     assert operation.describe(
     ) == "Alter storage engine for Pony from MyISAM to InnoDB"
Esempio n. 8
0
 def test_describe_without_from(self):
     operation = AlterStorageEngine("Pony", "InnoDB")
     assert operation.describe(
     ) == "Alter storage engine for Pony to InnoDB"
Esempio n. 9
0
 def test_from_means_reversible(self):
     operation = AlterStorageEngine("mymodel",
                                    from_engine="MyISAM",
                                    to_engine="InnoDB")
     assert operation.reversible
 def test_references_model(self):
     operation = AlterStorageEngine("Pony", "InnoDB")
     assert operation.references_model("PONY")
     assert operation.references_model("Pony")
     assert operation.references_model("pony")
     assert not operation.references_model("poony")
 def test_describe_with_from(self):
     operation = AlterStorageEngine("Pony", from_engine="MyISAM",
                                    to_engine="InnoDB")
     assert (operation.describe() ==
             "Alter storage engine for Pony from MyISAM to InnoDB")
 def test_describe_without_from(self):
     operation = AlterStorageEngine("Pony", "InnoDB")
     assert (operation.describe() ==
             "Alter storage engine for Pony to InnoDB")
Esempio n. 13
0
 def test_references_model(self):
     operation = AlterStorageEngine("Pony", "InnoDB")
     self.assertTrue(operation.references_model("PONY"))
     self.assertTrue(operation.references_model("Pony"))
     self.assertTrue(operation.references_model("pony"))
     self.assertFalse(operation.references_model("poony"))