Beispiel #1
0
def test_dump_fixtures(monkeypatch, tmpdir):
    records = [
        model_factories.make_fake_dashboard(name=i, max_charts=1)
        for i in range(10)]
    # Also ensure _id is popped off.
    for r in records:
        r.update(_id='foo')
    monkeypatch.setattr(_db, 'read', lambda *args, **kwargs: records)
    runner = CliRunner()
    tmp = tmpdir.mkdir('dumped_fixtures_test')
    args = ['--dump', tmp.strpath]
    result = runner.invoke(model_factories.insert_dashboards, args)
    assert 'Saving db as fixtures to:' in result.output
    assert result.exit_code == 0
    assert len(os.listdir(tmp.strpath)) == len(records)
Beispiel #2
0
def test_dump_fixtures_delete(monkeypatch, tmpdir):
    records = [
        model_factories.make_fake_dashboard(name=i, max_charts=1)
        for i in range(10)]

    def delete_all():
        global records
        records = []

    monkeypatch.setattr(_db, 'read', lambda *args, **kwargs: records)
    monkeypatch.setattr(_db, 'delete_all', lambda *a, **kw: [])
    runner = CliRunner()
    tmp = tmpdir.mkdir('dumped_fixtures_test')
    args = ['--dump', tmp.strpath, '--delete']
    result = runner.invoke(model_factories.insert_dashboards, args)
    assert 'Saving db as fixtures to:' in result.output
    assert result.exit_code == 0
    assert len(os.listdir(tmp.strpath)) == 10
    assert len(read()) == 0
Beispiel #3
0
def test_dump_fixtures_delete_bad_path_show_errors_no_exception(monkeypatch):
    records = [
        model_factories.make_fake_dashboard(name=i, max_charts=1)
        for i in range(1)]

    def delete_all():
        global records
        records = []

    monkeypatch.setattr(_db, 'read', lambda *args, **kwargs: records)
    monkeypatch.setattr(_db, 'delete_all', lambda *a, **kw: [])
    runner = CliRunner()
    args = ['--dump', '/fakepath/', '--delete']
    result = runner.invoke(model_factories.insert_dashboards, args)
    assert 'Saving db as fixtures to:' in result.output
    assert result.exit_code == 0
    assert len(read()) == 0
    err_msg = "The following records could not be dumped: ['//fakepath/"
    assert err_msg in result.output
def test_make_fake_dashboard():
    fdash = model_factories.make_fake_dashboard(name='Foo', max_charts=4)
    assert isinstance(fdash, dict)
    assert fdash.get('name') == 'Foo'