1import io
2import sys
3import unittest
4
5from opnsense_cli.formats.base import Format
6
7
8class FormatTestCase(unittest.TestCase):
9    def setUp(self):
10        self._api_data_json_empty = []
11        self._api_data_json_array = [
12            {
13                "name": "os-acme-client",
14                "version": "2.4",
15                "comment": "Let's Encrypt client",
16                "flatsize": "575KiB",
17                "locked": "N/A",
18                "license": "BSD2CLAUSE",
19                "repository": "OPNsense",
20                "origin": "opnsense/os-acme-client",
21                "provided": "1",
22                "installed": "0",
23                "path": "OPNsense/opnsense/os-acme-client",
24                "configured": "0"
25            },
26            {
27                "name": "os-virtualbox",
28                "version": "1.0_1",
29                "comment": "VirtualBox guest additions",
30                "flatsize": "525B",
31                "locked": "N/A",
32                "automatic": "N/A",
33                "license": "BSD2CLAUSE",
34                "repository": "OPNsense",
35                "origin": "opnsense/os-virtualbox",
36                "provided": "1",
37                "installed": "1",
38                "path": "OPNsense/opnsense/os-virtualbox",
39                "configured": "1"
40            }
41        ]
42
43        self._api_data_json_nested = {
44            "ArchiveOpenVPN": {"name": "Archive", "supportedOptions": ["plain_config", "p12_password"]},
45            "PlainOpenVPN": {"name": "File Only", "supportedOptions": ["auth_nocache", "cryptoapi"]},
46            "TheGreenBow": {"name": "TheGreenBow", "supportedOptions": []},
47            "ViscosityVisz": {"name": "Viscosity (visz)", "supportedOptions": ["plain_config", "random_local_port"]}
48        }
49
50        self._api_data_json_obj = {
51            "enabled": "1",
52            "name": "zabbix_host",
53            "type": "host",
54            "proto": "IPv4",
55            "counters": "0",
56            "updatefreq": "0.5",
57            "content": "www.example.com,www.heise.de",
58            "description": "Test",
59            "uuid": "24948d07-8525-4276-b497-108a0c55fcc2"
60        }
61
62    def _get_format_output(self, format: Format):
63        capturedOutput = io.StringIO()
64        sys.stdout = capturedOutput
65        format.echo()
66        sys.stdout = sys.__stdout__
67        result = capturedOutput.getvalue()
68
69        return result
70