import os import tempfile import unittest from patchbay_web.conf import Config class ConfTest(unittest.TestCase): def test_update_preserves_layout(self): with tempfile.TemporaryDirectory() as d: p = os.path.join(d, "patchbay.conf") with open(p, "w") as f: f.write("# head\nRole = target\nmailhost = old\nMailHost = dup\n") os.chmod(p, 0o600) c = Config(p) self.assertEqual(c.get("MailHost"), "dup") c.update({"MailHost": "smtp.example.org", "MailPort": 465}) with open(p) as f: text = f.read() self.assertEqual(text, "# head\nRole = target\nmailhost = smtp.example.org\nMailPort = 465\n") self.assertEqual(os.stat(p).st_mode & 0o777, 0o600) with self.assertRaises(ValueError): c.update({"MailHost": "a\nRole = client"}) if __name__ == "__main__": unittest.main()