Coverage for cc_modules/tests/cc_config_tests.py: 20%
35 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/tests/cc_config_tests.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
13 CamCOPS is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 CamCOPS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
26===============================================================================
27"""
29import configparser
30from unittest import TestCase
32from camcops_server.cc_modules.cc_config import CamcopsConfig, get_demo_config
35# =============================================================================
36# Unit tests
37# =============================================================================
40class EmailConfigTests(TestCase):
41 def setUp(self):
42 super().setUp()
44 from io import StringIO
46 # Start with a working config and just set the things we want to test
47 config_text = get_demo_config()
48 self.parser = configparser.ConfigParser()
49 self.parser.read_string(config_text)
51 self.parser.set("export", "RECIPIENTS", "recipient_A")
52 self.parser.set(
53 "recipient:recipient_A", "TRANSMISSION_METHOD", "email"
54 )
56 self.parser.set("site", "EMAIL_HOST", "smtp.example.com")
57 self.parser.set("site", "EMAIL_PORT", "587")
58 self.parser.set("site", "EMAIL_USE_TLS", "true")
59 self.parser.set("site", "EMAIL_HOST_USERNAME", "username")
60 self.parser.set("site", "EMAIL_HOST_PASSWORD", "mypassword")
61 self.parser.set(
62 "site", "EMAIL_FROM", "CamCOPS computer <from@example.com>"
63 )
64 self.parser.set(
65 "site", "EMAIL_SENDER", "CamCOPS computer <sender@example.com>"
66 )
67 self.parser.set(
68 "site",
69 "EMAIL_REPLY_TO",
70 "CamCOPS clinical administrator <admin@example.com>",
71 )
73 with StringIO() as buffer:
74 self.parser.write(buffer)
75 self.config = CamcopsConfig(
76 config_filename="", config_text=buffer.getvalue()
77 )
79 def test_export_recipients_use_site_email_config(self) -> None:
80 recipient = self.config._export_recipients[0]
81 self.assertEqual(recipient.recipient_name, "recipient_A")
83 self.assertEqual(recipient.email_host, "smtp.example.com")
84 self.assertEqual(recipient.email_port, 587)
85 self.assertTrue(recipient.email_use_tls)
86 self.assertEqual(recipient.email_host_username, "username")
87 self.assertEqual(recipient.email_host_password, "mypassword")
88 self.assertEqual(
89 recipient.email_from, "CamCOPS computer <from@example.com>"
90 )
91 self.assertEqual(
92 recipient.email_sender, "CamCOPS computer <sender@example.com>"
93 )
94 self.assertEqual(
95 recipient.email_reply_to,
96 "CamCOPS clinical administrator <admin@example.com>",
97 )