syncthing-monitor/test/test_config.py

36 lines
1.0 KiB
Python
Raw Normal View History

2021-01-28 13:31:25 +00:00
import io
import os
2021-01-28 10:56:11 +00:00
import unittest
2021-01-28 13:31:25 +00:00
from os import path
2021-01-28 10:56:11 +00:00
2021-01-28 13:31:25 +00:00
from syncthing_monitor.config_xml import parse_api_key, set_listen_ip_to_any
SYNCTHING_TEST_CONFIG_XML = 'test/test-syncthing-config.xml'
EXPECTED_API_KEY = "dFoLNEaqEZFSP62EFVGC2Ds5juuTmvH2"
SYNCTHING_EXPECTED_ANY_IP_CONFIG_XML = 'test/test-syncthing-config-any-ip.xml'
TEST_OUT_XML = 'test/out.xml'
def read_file(filename=TEST_OUT_XML):
with open(filename, 'r') as file:
return file.read()
2021-01-28 10:56:11 +00:00
class ConfigTests(unittest.TestCase):
def test_can_parse_api_key(self):
# noinspection SpellCheckingInspection
2021-01-28 13:31:25 +00:00
self.assertEqual(parse_api_key(SYNCTHING_TEST_CONFIG_XML), EXPECTED_API_KEY)
def test_can_set_listen_ip_to_any(self):
set_listen_ip_to_any(SYNCTHING_TEST_CONFIG_XML, TEST_OUT_XML)
self.assertListEqual(
list(io.open(TEST_OUT_XML)),
list(io.open(SYNCTHING_EXPECTED_ANY_IP_CONFIG_XML)))
def tearDown(self):
if path.exists(TEST_OUT_XML):
os.remove(TEST_OUT_XML)