Coverage for api/tests/conftest.py: 21%

# Coverage for api/tests/conftest.py : 21%

## 47 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"""

2 file: api/tests/conftest.py

3 All pytest fixtures local only to the api/tests are placed here

4"""

5 import os

6 import shutil

7 import tempfile

8

9 import pytest

10

11

12@pytest.fixture

13 def cleandir():

14 old_cwd = os.getcwd()

15 newpath = tempfile.mkdtemp()

16 os.chdir(newpath)

17 yield

18 os.chdir(old_cwd)

19 shutil.rmtree(newpath)

20

21

22@pytest.fixture

23 def restore_cwd():

24 old = os.getcwd()

25 yield

26 os.chdir(old)

27

28

29@pytest.fixture

30 def fake_foo_proj(tmp_path):

31 """creates a fake shopyo like directory structure as shown below

32

33 foo/

34 foo/

35 modules/

36 bar/

37 static/

38 bar.css

39 baz/

40 static/

41 baz.css

42 box__bizhelp/

43 demo/

44 demo.py

45 box__default/

46 foo/

47 static/

48 foo.css

49 foozoo/

50 foozoo.py

51 zoo/

52 static/

53 zoo.css

54 static/

55

56 Parameters

57 ----------

58 tmp_path : pathlib.Path

59 built in pytest fixture which will provide a temporary directory unique

60 to the test invocation, created in the base temporary directory.

61 """

62 # create the tmp_path/foo/foo

63 project_path = tmp_path / "foo" / "foo"

64 project_path.mkdir(parents=True)

65 # create the static and modules inside foo/foo

66 static_path = project_path / "static"

67 module_path = project_path / "modules"

68 static_path.mkdir()

69 module_path.mkdir()

70 # create the dummy boxes and modules

71 demo_path = module_path / "box__bizhelp/demo/demo.py"

72 foo_path = module_path / "box__default/foo/static/foo.css"

73 zoo_path = module_path / "box__default/zoo/static/zoo.css"

74 foozoo_path = module_path / "box__default/foozoo/foozoo.py"

75 bar_path = module_path / "bar/static/bar.css"

76 baz_path = module_path / "baz/model/baz.py"

77 demo_path.parent.mkdir(parents=True)

78 foo_path.parent.mkdir(parents=True)

79 zoo_path.parent.mkdir(parents=True)

80 foozoo_path.parent.mkdir(parents=True)

81 bar_path.parent.mkdir(parents=True)

82 baz_path.parent.mkdir(parents=True)

83 demo_path.write_text("demo")

84 foo_path.write_text("foo")

85 zoo_path.write_text("zoo")

86 foozoo_path.write_text("foozoo")

87 bar_path.write_text("bar")

88 baz_path.write_text("baz")

89 # save cwd and chage to test project directory

90 old = os.getcwd()

91 os.chdir(project_path)

92 yield project_path

93 # restore old cwd directory

94 os.chdir(old)