Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjonbrazil committed Nov 23, 2023
1 parent 82ee4d7 commit 1cd723b
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
64 changes: 64 additions & 0 deletions docs/parsers/debconf_show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.debconf_show"></a>

# jc.parsers.debconf\_show

jc - JSON Convert `debconf-show` command output parser

Usage (cli):

$ debconf-show | jc --debconf-show

or

$ jc debconf-show

Usage (module):

import jc
result = jc.parse('debconf_show', debconf_show_command_output)

Schema:

[
{
"debconf-show": string,
"bar": boolean,
"baz": integer
}
]

Examples:

$ debconf-show | jc --debconf-show -p
[]

$ debconf-show | jc --debconf-show -p -r
[]

<a id="jc.parsers.debconf_show.parse"></a>

### parse

```python
def parse(data: str,
raw: bool = False,
quiet: bool = False) -> List[JSONDictType]
```

Main text parsing function

Parameters:

data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True

Returns:

List of Dictionaries. Raw or processed structured data.

### Parser Information
Compatibility: linux

Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
1 change: 1 addition & 0 deletions tests/fixtures/generic/debconf-show.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"asked":true,"packagename":"onlyoffice","name":"jwt_secret","value":"aL8ei2iereuzee7cuJ6Cahjah1ixee2ah"},{"asked":false,"packagename":"onlyoffice","name":"db_pwd","value":"(password omitted)"},{"asked":true,"packagename":"onlyoffice","name":"rabbitmq_pwd","value":"(password omitted)"},{"asked":true,"packagename":"onlyoffice","name":"ds_port","value":"80"},{"asked":true,"packagename":"onlyoffice","name":"docservice_port","value":"8000"},{"asked":true,"packagename":"onlyoffice","name":"jwt_enabled","value":"true"},{"asked":true,"packagename":"onlyoffice","name":"remove_db","value":"false"},{"asked":true,"packagename":"onlyoffice","name":"jwt_header","value":"Authorization"},{"asked":true,"packagename":"onlyoffice","name":"db_port","value":"5432"},{"asked":true,"packagename":"onlyoffice","name":"rabbitmq_user","value":"onlyoffice"},{"asked":true,"packagename":"onlyoffice","name":"example_port","value":"3000"},{"asked":true,"packagename":"onlyoffice","name":"db_name","value":"onlyoffice"},{"asked":true,"packagename":"onlyoffice","name":"db_host","value":"localhost"},{"asked":true,"packagename":"onlyoffice","name":"db_type","value":"postgres"},{"asked":true,"packagename":"onlyoffice","name":"rabbitmq_host","value":"localhost"},{"asked":true,"packagename":"onlyoffice","name":"db_user","value":"onlyoffice"},{"asked":true,"packagename":"onlyoffice","name":"rabbitmq_proto","value":"amqp"},{"asked":true,"packagename":"onlyoffice","name":"cluster_mode","value":"false"}]
47 changes: 47 additions & 0 deletions tests/test_debconf_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import unittest
import json
from typing import Dict
from jc.parsers.debconf_show import parse

THIS_DIR = os.path.dirname(os.path.abspath(__file__))


class MyTests(unittest.TestCase):
f_in: Dict = {}
f_json: Dict = {}

@classmethod
def setUpClass(cls):
fixtures = {
'debconf_show': (
'fixtures/generic/debconf-show.out',
'fixtures/generic/debconf-show.json')
}

for file, filepaths in fixtures.items():
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
cls.f_in[file] = a.read()
cls.f_json[file] = json.loads(b.read())


def test_debconf_show_nodata(self):
"""
Test 'debconf_show' with no data
"""
self.assertEqual(parse('', quiet=True), [])


def test_debconf_show_centos_7_7(self):
"""
Test 'debconf_show onlyoffice-documentserver'
"""
self.assertEqual(
parse(self.f_in['debconf_show'], quiet=True),
self.f_json['debconf_show']
)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1cd723b

Please sign in to comment.