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

## 31 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 import subprocess

3 import sys

4 from shutil import copytree

5

6 import pytest

7

8 from shopyo import __version__

9

10 pytestmark = pytest.mark.cli_integration

11

12

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

14 def test_initialise_after_new(tmp_path):

15 """run shopyo new inside a tmp directory foo, create a venv, install the

16 shopyo.tar.gz dependencies, then run `shopyo initialise`.

17 """

18 # go one level up to the cwd so we are are the root where

19 # setup.py exits

20 os.chdir("../")

21 # create the dist folder with shoypo-<version>.tar.gz file

22 subprocess.check_call([sys.executable, "setup.py", "sdist"])

23 # store all path names to be used later

24 dist_path = os.path.join(os.getcwd(), "dist")

25 shopyo_dist_name = f"shopyo-{__version__}.tar.gz"

26 project_path = tmp_path / "foo"

27 print(project_path)

28 # copy the shopyo dist to the test project path

29 copytree(dist_path, os.path.join(project_path, "dist"))

30 # change cwd to that of test project

31 os.chdir(project_path)

32 # create a new virtual environment(venv)

33 subprocess.check_call([sys.executable, "-m", "venv", "env"])

34 # store path for python and shopyo executable of venv for the case when OS

35 # is Unix

36 python_env = os.path.join(os.getcwd(), "env", "bin", "python")

37 shopyo_env = os.path.join(os.getcwd(), "env", "bin", "shopyo")

38 # if OS is Windows, update the python and shopyo executable

39 if sys.platform == "win32":

40 python_env = os.path.join(os.getcwd(), "env", "Scripts", "python")

41 shopyo_env = os.path.join(os.getcwd(), "env", "Scripts", "shopyo")

42 # update pip of venv

43 subprocess.check_call([python_env, "-m", "pip", "install", "--upgrade", "pip"])

44 # install the shopyo package from dist added earlier

45 subprocess.check_call(

46 [python_env, "-m", "pip", "install", os.path.join("dist", shopyo_dist_name)]

47 )

48 # run shopyo help command followed by new command

49 subprocess.check_call(["shopyo", "--help"])

50 subprocess.check_call([shopyo_env, "new"])

51 # change the cwd to the newly created shopyo project

52 os.chdir(os.path.join(project_path, "foo"))

53 # initialise the project

54 subprocess.check_call([shopyo_env, "initialise"])

55 assert os.path.exists("shopyo.db")

56 assert os.path.exists("migrations")