# Coverage for api/tests/test_cli.py : 0%

## 385 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1# import os

2

3 import pytest

4 from click.testing import CliRunner

5

6 from shopyo.api.cli import cli

7 from shopyo.api.constants import SEP_CHAR

8 from shopyo.api.constants import SEP_NUM

9

10 pytestmark = pytest.mark.cli_unit

11

12

13@pytest.fixture(scope="session")

14 def cli_runner():

15 """Fixture that returns a helper function to run the shopyo cli."""

16 runner = CliRunner()

17

18 def cli_main(*cli_args, **cli_kwargs):

19 """Run shopyo cli main with the given args."""

20 return runner.invoke(cli, cli_args, **cli_kwargs)

21

22 return cli_main

23

24

25@pytest.mark.usefixtures("restore_cwd")

26 class TestCliCreateBox:

27 """test the create_box command line api function"""

28

29 def test_create_existing_box(self, tmpdir, cli_runner):

30 tmpdir.mkdir("modules").mkdir("box__foo")

31 os.chdir(tmpdir)

32 module_path = os.path.join("modules", "box__foo")

33 result = cli_runner("startbox", "box__foo")

34 expected = f"[ ] unable to create. Box {module_path} already exists!"

35

36 assert result.exit_code != 0

37 assert expected in result.output

38

39 @pytest.mark.parametrize("opt", ["-v", "--verbose"])

40 def test_create_unique_box(self, tmpdir, cli_runner, opt):

41 tmpdir.mkdir("modules")

42 os.chdir(tmpdir)

43 result = cli_runner("startbox", "box__foo", opt)

44 module_path = os.path.join("modules", "box__foo")

45 expected = f"[x] Successfully created dir {module_path}"

46

47 assert result.exit_code == 0

48 assert os.path.exists(os.path.join("modules", "box__foo"))

49 assert os.path.exists(os.path.join("modules", "box__foo", "box_info.json"))

50 assert expected in result.output

51

52

53@pytest.mark.usefixtures("restore_cwd")

54@pytest.mark.order("last")

55 class TestCliClean:

56 """tests the clean command line api function"""

57

58 def test_clean_pycache_present_only_in_cwd(self, tmpdir, flask_app):

59 """

60 run `shopyo clean2 -v` on the following test directory:

61

62 <some-unique-tmpdir>/

63 __pycache__/

64 file.pyc

65 """

66 fd = tmpdir.mkdir("__pycache__").join("file.pyc")

67 fd.write("content")

68 os.chdir(tmpdir)

69 runner = flask_app.test_cli_runner(mix_stderr=False)

70 result = runner.invoke(cli, ["clean", "-v"])

71 expected_out = "[x] all tables dropped\n[x] __pycache__ successfully deleted\n"

72 expected_err_shopyo_db = (

73 f"[ ] unable to delete {os.path.join(tmpdir, 'shopyo.db')}"

74 )

75 expected_err_migrations = (

76 f"[ ] unable to delete {os.path.join(tmpdir, 'migrations')}"

77 )

78

79 assert result.exit_code == 0

80 assert os.path.exists("__pycache__") is False

81 assert expected_out in result.output

82 assert expected_err_shopyo_db in result.stderr

83 assert expected_err_migrations in result.stderr

84

85 def test_clean_pycache_many_lvls_below_cwd(self, tmpdir, flask_app):

86 """

87 run `shopyo clean2 -v` on the following test directory:

88

89 <some-unique-tmpdir>/

90 shopyo/

91 shopyo/

92 mod/

93 box/

94 __pycache__/

95 file.pyc

96 """

97

98 path = tmpdir.mkdir("shopyo").mkdir("shopyo").mkdir("mod").mkdir("box")

99 pycache_path = path.mkdir("__pycache__")

100 pyc = pycache_path.join("file.pyc")

101 pyc.write("content")

102 os.chdir(tmpdir)

103 runner = flask_app.test_cli_runner()

104 result = runner.invoke(cli, ["clean", "-v"])

105 expected_out = "[x] all tables dropped\n[x] __pycache__ successfully deleted\n"

106 expected_err_shopyo_db = (

107 f"[ ] unable to delete {os.path.join(tmpdir, 'shopyo.db')}"

108 )

109 expected_err_migrations = (

110 f"[ ] unable to delete {os.path.join(tmpdir, 'migrations')}"

111 )

112

113 assert result.exit_code == 0

114 assert os.path.exists(pycache_path) is False

115 assert expected_out in result.output

116 assert expected_err_shopyo_db in result.output

117 assert expected_err_migrations in result.output

118

119 def test_clean_many_pycache_in_nested_dirs(self, tmpdir, flask_app):

120 """

121 run `shopyo clean2 -v` on the following test directory:

122

123 <some-unique-tmpdir>/

124 __pycache__/

125 file.pyc

126 shopyo/

127 __pycache__

128 file.pyc

129 module/

130 __pycache__

131 file.pyc

132 """

133 pycache_path1 = tmpdir.mkdir("__pycache__")

134 pyc1 = pycache_path1.join("file.pyc")

135 pyc1.write("content")

136 shopyo_path = tmpdir.mkdir("shopyo")

137 pycache_path2 = shopyo_path.mkdir("__pycache__")

138 pyc2 = pycache_path2.join("file.pyc")

139 pyc2.write("content")

140 pycache_path3 = shopyo_path.mkdir("module").mkdir("__pycache__")

141 pyc3 = pycache_path3.join("file.pyc")

142 pyc3.write("content")

143 os.chdir(tmpdir)

144 runner = flask_app.test_cli_runner()

145 result = runner.invoke(cli, ["clean", "-v"])

146 expected_out = "[x] all tables dropped\n[x] __pycache__ successfully deleted\n"

147 expected_err_shopyo_db = (

148 f"[ ] unable to delete {os.path.join(tmpdir, 'shopyo.db')}"

149 )

150 expected_err_migrations = (

151 f"[ ] unable to delete {os.path.join(tmpdir, 'migrations')}"

152 )

153

154 assert result.exit_code == 0

155 assert os.path.exists(pycache_path1) is False

156 assert os.path.exists(pycache_path2) is False

157 assert os.path.exists(pycache_path3) is False

158 assert expected_out in result.output

159 assert expected_err_shopyo_db in result.output

160 assert expected_err_migrations in result.output

161

162 def test_no_clean_applied_on_multiple_pycache(self, tmpdir):

163 """

164 run no clean command on the following test directory:

165

166 <some-unique-tmpdir>/

167 __pycache__/

168 shopyo/

169 __pycache__/

170

171 """

172 path1 = tmpdir.mkdir("__pycache__")

173 path2 = tmpdir.mkdir("shopyo").mkdir("__pycache__")

174

175 assert os.path.exists(path1)

176 assert os.path.exists(path2)

177

178 def test_clean_on_skip_shopyo_db_file(self, tmpdir, flask_app):

179 """

180 run `shopyo clean2 -v` on the following test directory:

181

182 <some-unique-tmpdir>/

183 shopyo.db

184 """

185 shopyo_db = tmpdir.join("shopyo.db")

186 shopyo_db.write("content")

187 os.chdir(tmpdir)

188 runner = flask_app.test_cli_runner()

189 result = runner.invoke(cli, ["clean", "--no-clear-db", "-v"])

190 part_expected_out = "[ ] db clearing skipped"

191

192 assert result.exit_code == 0

193 assert os.path.exists(shopyo_db) is True

194 assert part_expected_out in result.output

195

196 def test_clean_on_shopyo_db_file(self, tmpdir, flask_app):

197 """

198 run `shopyo clean2 -v` on the following test directory:

199

200 <some-unique-tmpdir>/

201 shopyo.db

202 """

203 shopyo_db = tmpdir.join("shopyo.db")

204 shopyo_db.write("content")

205 os.chdir(tmpdir)

206 runner = flask_app.test_cli_runner()

207 result = runner.invoke(cli, ["clean", "-v"])

208 expected_out1 = "[x] all tables dropped"

209 expected_out2 = "[ ] __pycache__ doesn't exist"

210 expected_out3 = (

211 f"[x] file '{os.path.join(tmpdir, 'shopyo.db')}' successfully deleted"

212 )

213 expected_out4 = f"[ ] unable to delete {os.path.join(tmpdir, 'migrations')}"

214

215 assert result.exit_code == 0

216 assert os.path.exists(shopyo_db) is False

217 assert expected_out1 in result.output

218 assert expected_out2 in result.output

219 assert expected_out3 in result.output

220 assert expected_out4 in result.output

221

222 def test_clean_on_skip_migration_folder(self, tmpdir, flask_app):

223 """

224 run `shopyo clean2 -v` on the following test directory:

225

226 <some-unique-tmpdir>/

227 migrations/

228 env.py

229 alembic.ini

230 """

231 migrations_path = tmpdir.mkdir("migrations")

232 env = migrations_path.join("env.py")

233 alembic = migrations_path.join("alembic.ini")

234 env.write("content-env")

235 alembic.write("content-alembic")

236 os.chdir(tmpdir)

237 runner = flask_app.test_cli_runner(mix_stderr=False)

238 result = runner.invoke(cli, ["clean", "--no-clear-migration", "-v"])

239 part_expected_out = "[ ] migration folder delete skipped"

240

241 assert result.exit_code == 0

242 assert os.path.exists(migrations_path) is True

243 assert part_expected_out in result.stdout

244

245 def test_clean_on_migration_folder(self, tmpdir, flask_app):

246 """

247 run `shopyo clean2 -v` on the following test directory:

248

249 <some-unique-tmpdir>/

250 migrations/

251 env.py

252 alembic.ini

253 """

254 migrations_path = tmpdir.mkdir("migrations")

255 env = migrations_path.join("env.py")

256 alembic = migrations_path.join("alembic.ini")

257 env.write("content-env")

258 alembic.write("content-alembic")

259 os.chdir(tmpdir)

260 runner = flask_app.test_cli_runner(mix_stderr=False)

261 result = runner.invoke(cli, ["clean", "-v"])

262 expected_out = (

263 "[x] all tables dropped\n"

264 f"[x] folder '{os.path.join(tmpdir, 'migrations')}' "

265 "successfully deleted\n"

266 )

267 expected_err_pycache = "[ ] __pycache__ doesn't exist\n"

268 expected_err_shopyo_db = (

269 f"[ ] unable to delete {os.path.join(tmpdir, 'shopyo.db')}"

270 )

271

272 assert result.exit_code == 0

273 assert os.path.exists(migrations_path) is False

274 assert expected_out in result.stdout

275 assert expected_err_pycache in result.stderr

276 assert expected_err_shopyo_db in result.stderr

277

278 @pytest.mark.parametrize("option", ["-v", "--verbose"])

279 def test_clean_pycache_shopyo_migration(self, tmpdir, flask_app, option):

280 """

281 run `shopyo clean2 -v` on the following test directory

282

283 shopyo/

284 shopyo/

285 migrations/

286 alembic.ini

287 env.py

288 module1/

289 __pycache__/

290 file.pyc

291 module2/

292 __pycache__/

293 file.pyc

294 shopyo.db

295 """

296 shopyo_path = tmpdir.mkdir("shopyo").mkdir("shopyo")

297 migrations_path = shopyo_path.mkdir("migrations")

298 env = migrations_path.join("env.py")

299 env.write("content-env")

300 alembic = migrations_path.join("alembic.ini")

301 alembic.write("content-alembic")

302 pycache_path1 = shopyo_path.mkdir("module1").mkdir("__pycache__")

303 pycache_path2 = shopyo_path.mkdir("module2").mkdir("__pycache__")

304 pyc1 = pycache_path1.join("file.pyc")

305 pyc1.write("content")

306 pyc2 = pycache_path2.join("file.pyc")

307 pyc2.write("content")

308 shopyo_db = shopyo_path.join("shopyo.db")

309 shopyo_db.write("content")

310 os.chdir(shopyo_path)

311 runner = flask_app.test_cli_runner()

312 result = runner.invoke(cli, ["clean", option])

313 expected_out1 = "[x] all tables dropped"

314 expected_out2 = "[x] __pycache__ successfully deleted"

315 expected_out3 = (

316 f"[x] file '{os.path.join(shopyo_path, 'shopyo.db')}' successfully deleted"

317 )

318 expected_out4 = (

319 f"[x] folder '{os.path.join(shopyo_path, 'migrations')}' successfully"

320 " deleted\n"

321 )

322

323 assert result.exit_code == 0

324 assert expected_out1 in result.output

325 assert expected_out2 in result.output

326 assert expected_out3 in result.output

327 assert expected_out4 in result.output

328 assert os.path.exists(migrations_path) is False

329 assert os.path.exists(pycache_path1) is False

330 assert os.path.exists(pycache_path2) is False

331 assert os.path.exists(shopyo_db) is False

332

333 def test_no_clean_on_shopyo_and_migrations(self, tmpdir):

334 """

335 run test on the following test directory:

336

337 <some-unique-tmpdir>/

338 migrations/

339 shopyo.db

340 """

341 migrations_path = tmpdir.mkdir("migrations")

342 shopyo_db = tmpdir.join("shopyo.db")

343 shopyo_db.write("content")

344

345 assert os.path.exists(migrations_path)

346 assert os.path.exists(shopyo_db)

347

348 @pytest.mark.parametrize("option", ["-v", "--verbose"])

349 def test_clean_on_no_files_to_clean(self, tmpdir, flask_app, option):

350 os.chdir(tmpdir)

351 runner = flask_app.test_cli_runner(mix_stderr=False)

352 result = runner.invoke(cli, ["clean", option])

353 expected_out = "[x] all tables dropped\n"

354 expected_err_pycache = "[ ] __pycache__ doesn't exist\n"

355 expected_err_shopyo_db = (

356 f"[ ] unable to delete {os.path.join(tmpdir, 'shopyo.db')}"

357 )

358 expected_err_migrations = (

359 f"[ ] unable to delete {os.path.join(tmpdir, 'migrations')}"

360 )

361

362 assert result.exit_code == 0

363 assert expected_out in result.output

364 assert expected_err_pycache in result.stderr

365 assert expected_err_shopyo_db in result.stderr

366 assert expected_err_migrations in result.stderr

367

368 def test_clean_with_no_verbose_on_empty_dir(self, tmpdir, flask_app):

369 """

370 run `shopyo clean2` on empty directory

371 """

372 os.chdir(tmpdir)

373 runner = flask_app.test_cli_runner(mix_stderr=False)

374 result = runner.invoke(cli, ["clean"])

375 expect_out = "Cleaning...\n" + SEP_CHAR * SEP_NUM + "\n"

376

377 assert result.exit_code == 0

378 assert expect_out in result.output

379

380 def test_clean_with_no_verbose_on_all_files(self, tmpdir, flask_app):

381 """

382 run `shopyo clean2` in directory with all files(shopyo.db,

383 migrations/, __pycahce__/)

384 """

385 pycache_path = tmpdir.mkdir("__pycache__")

386 shopyo_path = tmpdir.join("shopyo.db")

387 shopyo_path.write("content")

388 migrations_path = tmpdir.mkdir("migrations")

389 os.chdir(tmpdir)

390 runner = flask_app.test_cli_runner(mix_stderr=False)

391 result = runner.invoke(cli, ["clean"])

392 expect_out1 = "Cleaning...\n" + SEP_CHAR * SEP_NUM + "\n"

393 expect_out2 = "[x] __pycache__ successfully deleted\n"

394 expect_out3 = "[ ] unable to delete"

395

396 assert result.exit_code == 0

397 assert expect_out1 in result.output

398 assert expect_out2 not in result.output

399 assert expect_out3 not in result.output

400 assert os.path.exists(pycache_path) is False

401 assert os.path.exists(shopyo_path) is False

402 assert os.path.exists(migrations_path) is False

403

404 # TODO: add test_clean for MySQL to see if tables dropped @rehmanis

405

406

407@pytest.mark.usefixtures("restore_cwd")

408 class TestCliNew:

409 @pytest.mark.parametrize("proj,parent", [("", "foo"), ("bar", "")])

410 def test_new_projname_already_exists(self, cli_runner, proj, parent, tmp_path):

411 name = proj or parent

412 parent_path = tmp_path / parent

413 proj_path = parent_path / name

414 proj_path.mkdir(parents=True)

415 os.chdir(parent_path)

416 result = cli_runner("new", proj)

417 expected_out = (

418 f"[ ] Error: Unable to create new project. Path {proj_path} exits"

419 )

420

421 assert result.exit_code == 1

422 assert expected_out in result.output

423

424 def test_new_project_invvalid_projname(self, cli_runner):

425 result = cli_runner("new", ")foo?")

426 expected_out = (

427 "[ ] Error: PROJNAME is not valid, please use alphanumeric "

428 "and underscore only"

429 )

430

431 assert result.exit_code == 1

432 assert expected_out in result.output

433

434 @pytest.mark.parametrize("proj,parent", [("", "foo"), ("bar", "")])

435 def test_new_project_valid_name(self, cli_runner, tmp_path, proj, parent):

436

437 # create the parent folder for foo and none for bar proj

438 temp_proj = tmp_path / parent

439 # print(temp_proj)

440 temp_proj.mkdir(exist_ok=True)

441 # change to the parent folder (in case of bar it tmp_path while for foo

442 # it is tmp_path/foo) and run the new command. For foo, there is no

443 # argument for proj provided so it will create a foo/ project inside

444 # tmp_path/foo while for bar it will create bar/bar/ inside tmp_path

445 os.chdir(temp_proj)

446 result = cli_runner("new", proj)

447 # change back to tmp_path so that for easier comparision

448 os.chdir(tmp_path)

449 # use this for the name of the project that was created in tmp_path

450 name = parent or proj

451

452 assert result.exit_code == 0

453 assert os.path.exists(os.path.join(name, name))

454 assert os.path.exists(os.path.join(name, "requirements.txt"))

455 assert os.path.exists(os.path.join(name, "dev_requirements.txt"))

456 assert os.path.exists(os.path.join(name, "tox.ini"))

457 assert os.path.exists(os.path.join(name, "MANIFEST.in"))

458 assert os.path.exists(os.path.join(name, "README.md"))

459 assert os.path.exists(os.path.join(name, ".gitignore"))

460 assert os.path.exists(os.path.join(name, "pytest.ini"))

461 assert os.path.exists(os.path.join(name, "setup.py"))

462 assert os.path.exists(os.path.join(name, name, "__init__.py"))

463 assert os.path.exists(os.path.join(name, name, "cli.py"))

464 assert os.path.exists(os.path.join(name, "docs"))

465 assert os.path.exists(os.path.join(name, "docs", "conf.py"))

466 assert os.path.exists(os.path.join(name, "docs", "_static"))

467 assert os.path.exists(os.path.join(name, "docs", "_static", "custom.css"))

468 assert os.path.exists(os.path.join(name, "docs", "Makefile"))

469 assert os.path.exists(os.path.join(name, "docs", "index.rst"))

470 assert os.path.exists(os.path.join(name, "docs", "docs.rst"))

471 assert not os.path.exists(os.path.join(name, name, "__main__.py"))

472 assert not os.path.exists(os.path.join(name, name, "api"))

473 assert not os.path.exists(os.path.join(name, name, ".tox"))

474 assert not os.path.exists(os.path.join(name, name, ".coverage"))

475 assert not os.path.exists(os.path.join(name, name, "shopyo.db"))

476 assert not os.path.exists(os.path.join(name, name, "testing.db"))

477 assert not os.path.exists(os.path.join(name, name, "coverage.xml"))

478 assert not os.path.exists(os.path.join(name, name, "setup.cfg"))

479 assert not os.path.exists(os.path.join(name, name, "instance"))

480 assert not os.path.exists(os.path.join(name, name, "migrations"))

481 assert not os.path.exists(os.path.join(name, name, "__pycache__"))

482 assert not os.path.exists(os.path.join(name, name, "config.json"))

483

484

485 class TestCliInitialise:

486 pass

487

488

489@pytest.mark.usefixtures("fake_foo_proj")

490 class TestCliStartapp:

491 @pytest.mark.parametrize("mod", ["box_bar", "box__foo"])

492 def test_create_invalid_modulename_with_box_prefix(self, cli_runner, mod):

493 result = cli_runner("startapp", mod)

494 expected_out = (

495 f"[ ] Invalid MODULENAME '{mod}'. MODULENAME cannot start"

496 " with box_ prefix\n"

497 )

498

499 assert result.exit_code != 0

500 assert expected_out in result.output

501

502 @pytest.mark.parametrize("box", ["box_bar", "boxfoo", "foo"])

503 def test_create_module_with_invalid_box_name(self, cli_runner, box):

504 result = cli_runner("startapp", "demo", box)

505 expected_out = (

506 f"[ ] Invalid BOXNAME '{box}'. BOXNAME should start with 'box__' prefix\n"

507 )

508

509 assert result.exit_code != 0

510 assert expected_out in result.output

511

512 @pytest.mark.parametrize(

513 "mod,box",

514 [

515 ("bar", ""),

516 ("foo", "box__default"),

517 ("foo", ""),

518 ("baz", "box__default"),

519 ("demo", "box__default"),

520 ],

521 )

522 def test_create_existing_module(self, cli_runner, mod, box, tmpdir):

523 result = cli_runner("startapp", mod, box)

524 expected_out = (

525 f"[ ] Unable to create module '{mod}'. "

526 "MODULENAME already exists inside modules/ at"

527 )

528

529 assert result.exit_code != 0

530 assert expected_out in result.output

531

532 def test_create_modulename_not_alphanumeric(self, cli_runner):

533 result = cli_runner("startapp", "my(demo)mod")

534 expected_out = (

535 "[ ] Error: MODULENAME is not valid, please use alphanumeric "

536 "and underscore only\n"

537 )

538

539 assert result.exit_code != 0

540 assert expected_out in result.output

541

542 def test_create_boxname_not_alphanumeric(self, cli_runner):

543 result = cli_runner("startapp", "mod", "box__?.game")

544 expected_out = (

545 "[ ] Error: BOXNAME is not valid, please use alphanumeric "

546 "and underscore only\n"

547 )

548

549 assert result.exit_code != 0

550 assert expected_out in result.output

551

552 @pytest.mark.parametrize(

553 "mod,box",

554 [

555 ("store", ""), # create module

556 ("store", "box__ecommerce"), # create submodule and also box

557 ("marketplace", "box__default"), # create submodule but not box

558 ],

559 )

560 def test_create_valid_modules(self, cli_runner, fake_foo_proj, mod, box):

561 result = cli_runner("startapp", mod, box)

562 module_path = os.path.join(fake_foo_proj, "modules", box, mod)

563

564 assert result.exit_code == 0

565 assert os.path.exists(module_path)

566 assert os.path.exists(os.path.join(module_path, "templates"))

567 assert os.path.exists(os.path.join(module_path, "templates", mod))

568 assert os.path.exists(

569 os.path.join(module_path, "templates", mod, "blocks", "sidebar.html")

570 )

571 assert os.path.exists(

572 os.path.join(module_path, "templates", mod, "dashboard.html")

573 )

574 assert os.path.exists(os.path.join(module_path, "tests"))

575 assert os.path.exists(os.path.join(module_path, "static"))

576 assert os.path.exists(

577 os.path.join(module_path, "tests", f"test_{mod}_functional.py")

578 )

579 assert os.path.exists(

580 os.path.join(module_path, "tests", f"test_{mod}_models.py")

581 )

582 assert os.path.exists(os.path.join(module_path, "view.py"))

583 assert os.path.exists(os.path.join(module_path, "forms.py"))

584 assert os.path.exists(os.path.join(module_path, "models.py"))

585 assert os.path.exists(os.path.join(module_path, "info.json"))

586 assert os.path.exists(os.path.join(module_path, "global.py"))

587

588 @pytest.mark.parametrize("opt", ["-v", "--verbose"])

589 def test_create_valid_module_with_verbose(self, cli_runner, fake_foo_proj, opt):

590 result = cli_runner("startapp", "store", opt)

591 module_path = os.path.join(fake_foo_proj, "modules", "store")

592 expected_out1 = "[x] Successfully created"

593 expected_out2 = "created with content"

594

595 assert result.exit_code == 0

596 assert os.path.exists(module_path)

597 assert expected_out1 in result.output

598 assert expected_out2 in result.output

599

600

601@pytest.mark.usefixtures("fake_foo_proj")

602 class TestCliCollectstatic:

603 def test_collectstatic_with_default_src(self, cli_runner):

604 result = cli_runner("collectstatic")

605 expected_out1 = "Collecting static...\n" + SEP_CHAR * SEP_NUM + "\n\n"

606 expected_out2 = "[x] done copying"

607

608 assert result.exit_code == 0

609 assert expected_out1 in result.output

610 assert expected_out2 not in result.output

611 assert os.path.exists("static/modules/bar/bar.css")

612 assert os.path.exists("static/modules/box__default/foo/foo.css")

613 assert len(os.listdir("static/modules")) == 2

614 assert len(os.listdir("static/modules/box__default")) == 2

615

616 @pytest.mark.parametrize(

617 "src,expected",

618 [

619 ("box__default", "box__default/foo/foo.css"),

620 ("box__default", "box__default/zoo/zoo.css"),

621 ("box__default/foo", "box__default/foo/foo.css"),

622 ("bar", "bar/bar.css"),

623 ("box__default\\foo", "box__default/foo/foo.css"),

624 ("modules/bar", "bar/bar.css"),

625 ("modules\\box__default/foo", "box__default/foo/foo.css"),

626 ],

627 )

628 def test_collectstatic_with_valid_arg(self, src, expected, cli_runner):

629 result = cli_runner("collectstatic", src)

630 expected_out1 = "Collecting static...\n" + SEP_CHAR * SEP_NUM + "\n\n"

631 expected_out2 = "[x] done copying"

632

633 assert result.exit_code == 0

634 assert expected_out1 in result.output

635 assert expected_out2 not in result.output

636 assert os.path.exists(f"static/modules/{expected}")

637 assert len(os.listdir("static/modules")) == 1

638

639 def test_collectstatic_with_invalid_arg(self, cli_runner):

640

641 result = cli_runner("collectstatic", "foobar")

642 modules_path = os.path.join("modules", "foobar")

643 modules_path = os.path.join(os.getcwd(), modules_path)

644 expected_out = f"[ ] path: {modules_path} does not exist"

645

646 assert result.exit_code != 0

647 assert expected_out in result.output

648 assert not os.path.exists("static/modules")

649

650 @pytest.mark.parametrize("option", ["-v", "--verbose"])

651 def test_collectstatic_with_verbose(self, cli_runner, option):

652

653 result = cli_runner("collectstatic", option)

654 expected_out1 = "Collecting static...\n" + SEP_CHAR * SEP_NUM + "\n"

655 expected_out2 = "[x] done copying"

656

657 assert result.exit_code == 0

658 assert expected_out1 in result.output

659 assert expected_out2 in result.output