Coverage for .tox/coverage/lib/python3.11/site-packages/wuttamess/wutta.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-15 07:00 -0600

1# -*- coding: utf-8; -*- 

2################################################################################ 

3# 

4# WuttaMess -- Fabric Automation Helpers 

5# Copyright © 2024-2025 Lance Edgar 

6# 

7# This file is part of Wutta Framework. 

8# 

9# Wutta Framework is free software: you can redistribute it and/or modify it 

10# under the terms of the GNU General Public License as published by the Free 

11# Software Foundation, either version 3 of the License, or (at your option) any 

12# later version. 

13# 

14# Wutta Framework is distributed in the hope that it will be useful, but 

15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

16# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 

17# more details. 

18# 

19# You should have received a copy of the GNU General Public License along with 

20# Wutta Framework. If not, see <http://www.gnu.org/licenses/>. 

21# 

22################################################################################ 

23""" 

24Utilities for Wutta Framework 

25""" 

26 

27from wuttamess import postgres 

28 

29 

30def purge_email_settings(c, dbname, appname='wutta'): 

31 """ 

32 Purge production email settings for a database. 

33 

34 This can be used when cloning a production app DB to a test 

35 server. The general pattern is: 

36 

37 * setup test app on test server 

38 * config file should specify test email settings 

39 * clone the production DB to test server 

40 * call this function to purge email settings from test DB 

41 

42 So the end result should be, the test server app can run and send 

43 emails safely using only what is specified in config file(s), 

44 since none of the production email settings remain in the test DB. 

45 

46 :param dbname: Name of the database to be updated. 

47 

48 :param appname: The ``appname`` used to determine setting names. 

49 """ 

50 postgres.sql(c, f"delete from setting where name like '{appname}.email.%.sender';", 

51 database=dbname) 

52 postgres.sql(c, f"delete from setting where name like '{appname}.email.%.to';", 

53 database=dbname) 

54 postgres.sql(c, f"delete from setting where name like '{appname}.email.%.cc';", 

55 database=dbname) 

56 postgres.sql(c, f"delete from setting where name like '{appname}.email.%.bcc';", 

57 database=dbname)