forked from linuxacademy/content-python3-sysadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
48 lines (38 loc) · 1.28 KB
/
Copy pathtest_cli.py
File metadata and controls
48 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pytest
from pgbackup import cli
url = "postgres://bob@example.com:5432/db_one"
@pytest.fixture
def parser():
return cli.create_parser()
def test_parser_without_driver(parser):
"""
Without a specified driver the parser will exit
"""
with pytest.raises(SystemExit):
parser.parse_args([url])
def test_parser_with_driver(parser):
"""
The parser will exit if it receives a driver without a destination
"""
with pytest.raises(SystemExit):
parser.parse_args([url, "--driver", "local"])
def test_parser_with_unknown_driver(parser):
"""
The parser will exit if the driver name is unknown.
"""
with pytest.raises(SystemExit):
parser.parse_args([url, '--driver', 'azure', 'destination'])
def test_parser_with_known_drivers(parser):
"""
The Parser will not exit if the driver name is known.
"""
for driver in ['local', 's3']:
assert parser.parse_args([url, '--driver', driver, 'destination'])
def test_parser_with_driver_and_destination(parser):
"""
The parser will not exit if it receives a driver and destination
"""
args = parser.parse_args([url, '--driver', 'local', '/some/path'])
assert args.url == url
assert args.driver == 'local'
assert args.destination == '/some/path'