Hide keyboard shortcuts

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 

2 

3""" 

4camcops_server/cc_modules/tests/cc_config_tests.py 

5 

6=============================================================================== 

7 

8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com). 

9 

10 This file is part of CamCOPS. 

11 

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. 

16 

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. 

21 

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/>. 

24 

25=============================================================================== 

26""" 

27 

28import configparser 

29from unittest import TestCase 

30 

31from cardinal_pythonlib.sqlalchemy.logs import pre_disable_sqlalchemy_extra_echo_log # noqa 

32 

33from camcops_server.cc_modules.cc_config import CamcopsConfig, get_demo_config 

34 

35 

36# ============================================================================= 

37# Unit tests 

38# ============================================================================= 

39 

40class EmailConfigTests(TestCase): 

41 

42 def setUp(self): 

43 super().setUp() 

44 

45 from io import StringIO 

46 

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) 

51 

52 self.parser.set("export", "RECIPIENTS", "recipient_A") 

53 self.parser.set("recipient:recipient_A", "TRANSMISSION_METHOD", "email") 

54 

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>") 

66 

67 with StringIO() as buffer: 

68 self.parser.write(buffer) 

69 self.config = CamcopsConfig(config_filename="", 

70 config_text=buffer.getvalue()) 

71 

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") 

75 

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>")