2024-02-19 19:08:05 +00:00
|
|
|
import sys
|
2024-04-17 20:49:08 +00:00
|
|
|
sys.path.append('freedata-server')
|
2023-11-06 10:30:37 +00:00
|
|
|
import unittest
|
2023-12-06 10:32:59 +00:00
|
|
|
import config
|
2023-11-06 10:30:37 +00:00
|
|
|
|
|
|
|
class TestConfigMethods(unittest.TestCase):
|
|
|
|
|
2023-11-06 18:04:35 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2024-04-17 20:49:08 +00:00
|
|
|
cls.config = config.CONFIG('freedata-server/config.ini.example')
|
2023-11-06 18:04:35 +00:00
|
|
|
|
2023-11-06 10:30:37 +00:00
|
|
|
def test_config_exists(self):
|
2024-04-17 20:49:08 +00:00
|
|
|
c = config.CONFIG('freedata-server/config.ini.example')
|
2023-11-06 10:30:37 +00:00
|
|
|
self.assertTrue(c.config_exists())
|
|
|
|
|
2024-04-17 20:49:08 +00:00
|
|
|
#c = config.CONFIG('freedata-server/nonexistant')
|
2024-02-19 19:08:05 +00:00
|
|
|
#self.assertFalse(c.config_exists())
|
2023-11-06 10:30:37 +00:00
|
|
|
|
2023-11-06 18:04:35 +00:00
|
|
|
def test_read(self):
|
|
|
|
data = self.config.read()
|
|
|
|
self.assertIsInstance(data, dict)
|
|
|
|
|
|
|
|
self.assertIn('STATION', data.keys())
|
|
|
|
self.assertIn('AUDIO', data.keys())
|
|
|
|
self.assertIn('RADIO', data.keys())
|
|
|
|
|
|
|
|
def test_write(self):
|
|
|
|
c = self.config.read()
|
|
|
|
oldcall = c['STATION']['mycall']
|
|
|
|
newcall = 'T1CALL'
|
|
|
|
self.assertNotEqual(oldcall, newcall)
|
|
|
|
|
|
|
|
c['STATION']['mycall'] = newcall
|
|
|
|
new_conf = self.config.write(c)
|
|
|
|
self.assertEqual(new_conf['STATION']['mycall'], newcall)
|
|
|
|
c = self.config.read()
|
|
|
|
self.assertEqual(c['STATION']['mycall'], newcall)
|
|
|
|
|
|
|
|
# put it back as it was
|
|
|
|
c['STATION']['mycall'] = oldcall
|
|
|
|
last_conf = self.config.write(c)
|
|
|
|
self.assertEqual(last_conf['STATION']['mycall'], oldcall)
|
2023-11-06 10:30:37 +00:00
|
|
|
|
|
|
|
def test_validate_data(self):
|
2023-11-15 15:49:16 +00:00
|
|
|
data = {'STATION': {'ssid_list': "abc"}}
|
2023-11-06 10:30:37 +00:00
|
|
|
with self.assertRaises(ValueError):
|
2024-02-19 19:08:05 +00:00
|
|
|
self.config.validate_data(data)
|
2023-11-06 10:30:37 +00:00
|
|
|
|
2023-11-15 15:49:16 +00:00
|
|
|
data = {'STATION': {'ssid_list': [1, 2, 3]}}
|
2024-02-19 19:08:05 +00:00
|
|
|
self.assertIsNone(self.config.validate_data(data))
|
2023-11-15 15:49:16 +00:00
|
|
|
|
2023-11-06 10:30:37 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|