1+ import getpass
2+ import pytest
13from typer .testing import CliRunner
24
35from cli .website import app
46
57runner = CliRunner ()
68
9+ @pytest .fixture
10+ def domain_name ():
11+ return "foo.bar.com"
12+
13+
14+ @pytest .fixture
15+ def command ():
16+ return "/usr/local/bin/uvicorn --uds $DOMAIN_SOCKET main:app"
17+
18+
19+ @pytest .fixture
20+ def website_info (domain_name , command ):
21+ return {
22+ "domain_name" : domain_name ,
23+ "enabled" : True ,
24+ "id" : 42 ,
25+ "user" : getpass .getuser (),
26+ "webapp" : {
27+ "command" : command ,
28+ "domains" : [
29+ {
30+ "domain_name" : domain_name ,
31+ "enabled" : True
32+ }
33+ ],
34+ "id" : 42
35+ }
36+ }
37+
738
839def test_main_subcommand_without_args_prints_help ():
940 result = runner .invoke (
@@ -40,7 +71,8 @@ def test_create_without_command_barfs():
4071 assert "Missing option" in result .stdout
4172
4273
43- def test_create_with_domain_and_command_creates_it ():
74+ def test_create_with_domain_and_command_creates_it (mocker ):
75+ mock_website = mocker .patch ("cli.website.Website" )
4476 result = runner .invoke (
4577 app ,
4678 [
@@ -52,18 +84,27 @@ def test_create_with_domain_and_command_creates_it():
5284 ],
5385 )
5486 assert result .exit_code == 0
55- assert False , "TODO"
87+ mock_website .return_value .create .assert_called_once_with (
88+ domain_name = "www.something.com" ,
89+ command = "some kind of server"
90+ )
91+ assert "All done!" in result .stdout
5692
5793
58- def test_get_with_no_domain_lists_websites ():
94+ def test_get_with_no_domain_lists_websites (mocker , website_info ):
95+ mock_website = mocker .patch ("cli.website.Website" )
96+ mock_website .return_value .get .return_value = [website_info ]
97+
5998 result = runner .invoke (
6099 app ,
61100 [
62101 "get" ,
63102 ],
64103 )
65104 assert result .exit_code == 0
66- assert False , "TODO"
105+ mock_website .return_value .get .assert_called_once ()
106+ assert "You have 1 website(s). " in result .stdout
107+ assert "foo.bar.com" in result .stdout
67108
68109
69110def test_get_with_domain_gives_details_for_domain ():
0 commit comments