Seed policysync container code
[dcaegen2/deployments.git] / dcae-services-policy-sync / tests / test_cmd.py
1 # ============LICENSE_START=======================================================
2 # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=========================================================
16
17 import pytest, json, sys, logging, logging.config
18 from policysync.cmd import Config, main, parsecmd
19 import policysync.coroutines
20
21
22 class TestConfig:
23     def test_parse_args(self):
24         args = [
25             "--out",
26             "out",
27             "--pdp-user",
28             "chris",
29             "--pdp-pass",
30             "notapassword",
31             "--pdp-url",
32             "blah",
33             "--duration",
34             "60",
35             "--filters",
36             "[blah]",
37         ]
38
39         c = parsecmd(args)
40
41         assert c.filters == ["blah"]
42         assert c.check_period == 60
43         assert c.out_file == "out"
44
45     def test_parse_args_no_auth(self):
46         c = parsecmd(
47             ["--out", "out", "--pdp-url", "blah", "--duration", "60", "--filters", "[blah]"]
48         )
49
50         assert c.client.pdp_url == "blah"
51         assert c.filters == ["blah"]
52         assert c.check_period == 60
53         assert c.out_file == "out"
54
55     def test_parse_args_no_pdp(self):
56         args = []
57         with pytest.raises(ValueError):
58             parsecmd(args)
59
60     def test_parse_bad_bind(self):
61         args = [
62             "--out",
63             "out",
64             "--pdp-user",
65             "chris",
66             "--pdp-pass",
67             "notapassword",
68             "--pdp-url",
69             "blah",
70             "--duration",
71             "60",
72             "--filters",
73             "[blah]",
74             "--http-bind",
75             "l[ocalhost:100",
76         ]
77
78         with pytest.raises(ValueError):
79             parsecmd(args)