Skip to content

Commit

Permalink
Enhance cups confs CupsBrowsedConf
Browse files Browse the repository at this point in the history
Signed-off-by: jiazhang <jiazhang@redhat.com>
  • Loading branch information
wushiqinlou committed Sep 28, 2024
1 parent 19e6afa commit a699136
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 3 additions & 7 deletions insights/parsers/cups_confs.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class CupsBrowsedConf(Parser, dict):
Examples:
>>> type(cups_browsed_conf)
<class 'insights.parsers.cups_confs.CupsBrowsedConf'>
>>> 'dnssd' in cups_browsed_conf['BrowseRemoteProtocols']
>>> 'dnssd cups' in cups_browsed_conf['BrowseRemoteProtocols']
True
>>> 'cups.example.com' in cups_browsed_conf['BrowseAllow']
True
Expand All @@ -117,13 +117,9 @@ def parse_content(self, content):
for line in get_active_lines(content):
k, v = [i.strip() for i in line.split(None, 1)]
if k not in self:
self[k] = v if len(v.split()) == 1 else v.split()
self[k] = [v]
else:
_v = self[k]
_v = [_v] if not isinstance(_v, list) else _v
if v not in _v:
_v.append(v)
self[k] = _v
self[k].append(v)


@parser(Specs.cups_files_conf)
Expand Down
5 changes: 3 additions & 2 deletions insights/tests/parsers/test_cups_confs.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
# Can use DNSSD and/or CUPS and/or LDAP, or 'none' for neither.
BrowseRemoteProtocols dnssd cups
BrowseRemoteProtocols none
BrowseAllow 192.168.0.1
BrowseAllow 192.168.0.255
BrowseAllow cups.example.com
Expand Down Expand Up @@ -176,8 +177,8 @@ def test_cups_browsed_files_conf():
result = CupsBrowsedConf(context_wrap(CUPS_BROWSED_CONF))
assert len(result) == 2
assert 'BrowseRemoteProtocols' in result
assert result['BrowseRemoteProtocols'] == ['dnssd', 'cups']
assert sorted(result['BrowseAllow']) == sorted(['192.168.0.1', '192.168.0.255', 'cups.example.com'])
assert result['BrowseRemoteProtocols'] == ['dnssd cups', 'none']
assert result['BrowseAllow'] == ['192.168.0.1', '192.168.0.255', 'cups.example.com', '192.168.0.255']


def test_cups_browsed_conf_empty():
Expand Down

0 comments on commit a699136

Please sign in to comment.