Coverage for cc_modules/tests/cc_config_tests.py : 22%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/tests/cc_config_tests.py
6===============================================================================
8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com).
10 This file is part of CamCOPS.
12 CamCOPS is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 CamCOPS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
25===============================================================================
26"""
28import configparser
29from unittest import TestCase
31from cardinal_pythonlib.sqlalchemy.logs import pre_disable_sqlalchemy_extra_echo_log # noqa
33from camcops_server.cc_modules.cc_config import CamcopsConfig, get_demo_config
36# =============================================================================
37# Unit tests
38# =============================================================================
40class EmailConfigTests(TestCase):
42 def setUp(self):
43 super().setUp()
45 from io import StringIO
47 # Start with a working config and just set the things we want to test
48 config_text = get_demo_config()
49 self.parser = configparser.ConfigParser()
50 self.parser.read_string(config_text)
52 self.parser.set("export", "RECIPIENTS", "recipient_A")
53 self.parser.set("recipient:recipient_A", "TRANSMISSION_METHOD", "email")
55 self.parser.set("site", "EMAIL_HOST", "smtp.example.com")
56 self.parser.set("site", "EMAIL_PORT", "587")
57 self.parser.set("site", "EMAIL_USE_TLS", "true")
58 self.parser.set("site", "EMAIL_HOST_USERNAME", "username")
59 self.parser.set("site", "EMAIL_HOST_PASSWORD", "mypassword")
60 self.parser.set("site", "EMAIL_FROM",
61 "CamCOPS computer <from@example.com>")
62 self.parser.set("site", "EMAIL_SENDER",
63 "CamCOPS computer <sender@example.com>")
64 self.parser.set("site", "EMAIL_REPLY_TO",
65 "CamCOPS clinical administrator <admin@example.com>")
67 with StringIO() as buffer:
68 self.parser.write(buffer)
69 self.config = CamcopsConfig(config_filename="",
70 config_text=buffer.getvalue())
72 def test_export_recipients_use_site_email_config(self) -> None:
73 recipient = self.config._export_recipients[0]
74 self.assertEqual(recipient.recipient_name, "recipient_A")
76 self.assertEqual(recipient.email_host, "smtp.example.com")
77 self.assertEqual(recipient.email_port, 587)
78 self.assertTrue(recipient.email_use_tls)
79 self.assertEqual(recipient.email_host_username, "username")
80 self.assertEqual(recipient.email_host_password, "mypassword")
81 self.assertEqual(recipient.email_from,
82 "CamCOPS computer <from@example.com>")
83 self.assertEqual(recipient.email_sender,
84 "CamCOPS computer <sender@example.com>")
85 self.assertEqual(recipient.email_reply_to,
86 "CamCOPS clinical administrator <admin@example.com>")