@@ 95-113 (lines=19) @@ | ||
92 | assert len(os.listdir(tmp.strpath)) == len(records) |
|
93 | ||
94 | ||
95 | def test_dump_fixtures_delete(monkeypatch, tmpdir): |
|
96 | records = [ |
|
97 | model_factories.make_fake_dashboard(name=i, max_charts=1) |
|
98 | for i in range(10)] |
|
99 | ||
100 | def delete_all(): |
|
101 | global records |
|
102 | records = [] |
|
103 | ||
104 | monkeypatch.setattr(_db, 'read', lambda *args, **kwargs: records) |
|
105 | monkeypatch.setattr(_db, 'delete_all', lambda *a, **kw: []) |
|
106 | runner = CliRunner() |
|
107 | tmp = tmpdir.mkdir('dumped_fixtures_test') |
|
108 | args = ['--dump', tmp.strpath, '--delete'] |
|
109 | result = runner.invoke(model_factories.insert_dashboards, args) |
|
110 | assert 'Saving db as fixtures to:' in result.output |
|
111 | assert result.exit_code == 0 |
|
112 | assert len(os.listdir(tmp.strpath)) == 10 |
|
113 | assert len(read()) == 0 |
|
114 | ||
115 | ||
116 | def test_dump_fixtures_delete_bad_path_show_errors_no_exception(monkeypatch): |
|
@@ 116-133 (lines=18) @@ | ||
113 | assert len(read()) == 0 |
|
114 | ||
115 | ||
116 | def test_dump_fixtures_delete_bad_path_show_errors_no_exception(monkeypatch): |
|
117 | records = [ |
|
118 | model_factories.make_fake_dashboard(name=i, max_charts=1) |
|
119 | for i in range(1)] |
|
120 | ||
121 | def delete_all(): |
|
122 | global records |
|
123 | records = [] |
|
124 | ||
125 | monkeypatch.setattr(_db, 'read', lambda *args, **kwargs: records) |
|
126 | runner = CliRunner() |
|
127 | args = ['--dump', '/fakepath/', '--delete'] |
|
128 | result = runner.invoke(model_factories.insert_dashboards, args) |
|
129 | assert 'Saving db as fixtures to:' in result.output |
|
130 | assert result.exit_code == 0 |
|
131 | assert len(read()) == 0 |
|
132 | err_msg = "The following records could not be dumped: ['//fakepath/" |
|
133 | assert err_msg in result.output |
|
134 |