Skip to content

Commit dbc3a48

Browse files
test: add tests for cli (#948)
* test: add tests for cli * tests: add tests for cli * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b5797a8 commit dbc3a48

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

integration_tests/test_cli.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
from robyn.cli import create_robyn_app, docs, run, start_app_normally, start_dev_server
4+
5+
6+
# Unit tests
7+
def test_create_robyn_app():
8+
with patch("robyn.cli.prompt") as mock_prompt:
9+
mock_prompt.return_value = {
10+
"directory": "test_dir",
11+
"docker": "N",
12+
"project_type": "no-db",
13+
}
14+
with patch("robyn.cli.os.makedirs") as mock_makedirs:
15+
with patch("robyn.cli.shutil.copytree") as mock_copytree, patch("robyn.os.remove") as _mock_remove:
16+
create_robyn_app()
17+
mock_makedirs.assert_called_once()
18+
mock_copytree.assert_called_once()
19+
20+
21+
def test_docs():
22+
with patch("robyn.cli.webbrowser.open") as mock_open:
23+
docs()
24+
mock_open.assert_called_once_with("https://robyn.tech")
25+
26+
27+
def test_start_dev_server():
28+
config = MagicMock()
29+
config.dev = True
30+
with patch("robyn.cli.setup_reloader") as mock_setup_reloader:
31+
start_dev_server(config, "test_file.py")
32+
mock_setup_reloader.assert_called_once()
33+
34+
35+
def test_start_app_normally():
36+
config = MagicMock()
37+
config.dev = False
38+
config.parser.parse_known_args.return_value = (MagicMock(), [])
39+
with patch("robyn.cli.subprocess.run") as mock_run:
40+
start_app_normally(config)
41+
mock_run.assert_called_once()
42+
43+
44+
# Integration tests
45+
def test_run_create():
46+
with patch("robyn.cli.Config") as mock_config:
47+
mock_config.return_value.create = True
48+
with patch("robyn.cli.create_robyn_app") as mock_create:
49+
run()
50+
mock_create.assert_called_once()

0 commit comments

Comments
 (0)