def test_rename_to_existing_table(testdb, fs): fs.create_file(template.path('table1')) with pytest.raises(DestinationExistsError) as excinfo: commands.rename('table1', 'table2') assert str(excinfo.value) == 'Action cancelled: a table named "table2" '\ 'already exists. Please rename or remove it before using this name.'
def test_rename(testdb, fs, mocker): m = mocker.patch('memini.core.database.rename_table') fs.create_file(template.path('table1')) commands.rename('table1', 'table3') assert os.path.exists(template.path('table3')) assert not os.path.exists(template.path('table1')) m.assert_called_with('table1', 'table3')
def test_rename_missing_template(testdb, fs, mocker): # No template for source table: automatic creation def create_fake_template(*args): fs.create_file(template.path('table1')) m = mocker.patch('memini.core.template.create', side_effect=create_fake_template) commands.rename('table1', 'table4') m.assert_called_with('table1') assert os.path.exists(template.path('table4')) assert not os.path.exists(template.path('table1')) assert database.table_exists('table4') assert not database.table_exists('table1')
def test_rename_nonexistent_table(testdb): with pytest.raises(NoSuchTableError) as excinfo: commands.rename('nonexistent', 'newname') assert str(excinfo.value) == 'Cannot find a table named "nonexistent"'