import io import os import unittest from os import path 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() class ConfigTests(unittest.TestCase): def test_can_parse_api_key(self): # noinspection SpellCheckingInspection 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)