11from click .testing import CliRunner
22from datasette import cli
33from unittest import mock
4+ import subprocess
45
56
67@mock .patch ("shutil.which" )
@@ -24,20 +25,20 @@ def test_publish_now_invalid_database(mock_which):
2425
2526
2627@mock .patch ("shutil.which" )
27- @mock .patch ("datasette.publish.now.call " )
28- def test_publish_now (mock_call , mock_which ):
28+ @mock .patch ("datasette.publish.now.run " )
29+ def test_publish_now (mock_run , mock_which ):
2930 mock_which .return_value = True
3031 runner = CliRunner ()
3132 with runner .isolated_filesystem ():
3233 open ("test.db" , "w" ).write ("data" )
3334 result = runner .invoke (cli .cli , ["publish" , "now" , "test.db" ])
3435 assert 0 == result .exit_code
35- mock_call .assert_called_once_with ("now" )
36+ mock_run .assert_called_once_with ("now" , stdout = subprocess . PIPE )
3637
3738
3839@mock .patch ("shutil.which" )
39- @mock .patch ("datasette.publish.now.call " )
40- def test_publish_now_force_token (mock_call , mock_which ):
40+ @mock .patch ("datasette.publish.now.run " )
41+ def test_publish_now_force_token (mock_run , mock_which ):
4142 mock_which .return_value = True
4243 runner = CliRunner ()
4344 with runner .isolated_filesystem ():
@@ -46,4 +47,28 @@ def test_publish_now_force_token(mock_call, mock_which):
4647 cli .cli , ["publish" , "now" , "test.db" , "--force" , "--token=X" ]
4748 )
4849 assert 0 == result .exit_code
49- mock_call .assert_called_once_with (["now" , "--force" , "--token=X" ])
50+ mock_run .assert_called_once_with (
51+ ["now" , "--force" , "--token=X" ], stdout = subprocess .PIPE
52+ )
53+
54+
55+ @mock .patch ("shutil.which" )
56+ @mock .patch ("datasette.publish.now.run" )
57+ def test_publish_now_multiple_aliases (mock_run , mock_which ):
58+ mock_which .return_value = True
59+ mock_run .return_value = mock .Mock (0 )
60+ mock_run .return_value .stdout = b"https://demo.example.com/"
61+ runner = CliRunner ()
62+ with runner .isolated_filesystem ():
63+ open ("test.db" , "w" ).write ("data" )
64+ runner .invoke (
65+ cli .cli ,
66+ ["publish" , "now" , "test.db" , "--alias" , "alias1" , "--alias" , "alias2" ],
67+ )
68+ mock_run .assert_has_calls (
69+ [
70+ mock .call ("now" , stdout = subprocess .PIPE ),
71+ mock .call (["now" , "alias" , b"https://demo.example.com/" , "alias1" ]),
72+ mock .call (["now" , "alias" , b"https://demo.example.com/" , "alias2" ]),
73+ ]
74+ )
0 commit comments