示例#1
0
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.'
示例#2
0
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')
示例#3
0
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')
示例#4
0
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"'