fix: add wutta.purge_email_settings()
for cloning prod DB to test
This commit is contained in:
parent
34459c008f
commit
8c512e33ce
6
docs/api/wuttamess.wutta.rst
Normal file
6
docs/api/wuttamess.wutta.rst
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
``wuttamess.wutta``
|
||||||
|
===================
|
||||||
|
|
||||||
|
.. automodule:: wuttamess.wutta
|
||||||
|
:members:
|
|
@ -36,3 +36,4 @@ project.
|
||||||
api/wuttamess.ssh
|
api/wuttamess.ssh
|
||||||
api/wuttamess.sync
|
api/wuttamess.sync
|
||||||
api/wuttamess.util
|
api/wuttamess.util
|
||||||
|
api/wuttamess.wutta
|
||||||
|
|
57
src/wuttamess/wutta.py
Normal file
57
src/wuttamess/wutta.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# WuttaMess -- Fabric Automation Helpers
|
||||||
|
# Copyright © 2024-2025 Lance Edgar
|
||||||
|
#
|
||||||
|
# This file is part of Wutta Framework.
|
||||||
|
#
|
||||||
|
# Wutta Framework is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
# later version.
|
||||||
|
#
|
||||||
|
# Wutta Framework is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
Utilities for Wutta Framework
|
||||||
|
"""
|
||||||
|
|
||||||
|
from wuttamess import postgres
|
||||||
|
|
||||||
|
|
||||||
|
def purge_email_settings(c, dbname, appname='wutta'):
|
||||||
|
"""
|
||||||
|
Purge production email settings for a database.
|
||||||
|
|
||||||
|
This can be used when cloning a production app DB to a test
|
||||||
|
server. The general pattern is:
|
||||||
|
|
||||||
|
* setup test app on test server
|
||||||
|
* config file should specify test email settings
|
||||||
|
* clone the production DB to test server
|
||||||
|
* call this function to purge email settings from test DB
|
||||||
|
|
||||||
|
So the end result should be, the test server app can run and send
|
||||||
|
emails safely using only what is specified in config file(s),
|
||||||
|
since none of the production email settings remain in the test DB.
|
||||||
|
|
||||||
|
:param dbname: Name of the database to be updated.
|
||||||
|
|
||||||
|
:param appname: The ``appname`` used to determine setting names.
|
||||||
|
"""
|
||||||
|
postgres.sql(c, f"delete from setting where name like '{appname}.email.%.sender';",
|
||||||
|
database=dbname)
|
||||||
|
postgres.sql(c, f"delete from setting where name like '{appname}.email.%.to';",
|
||||||
|
database=dbname)
|
||||||
|
postgres.sql(c, f"delete from setting where name like '{appname}.email.%.cc';",
|
||||||
|
database=dbname)
|
||||||
|
postgres.sql(c, f"delete from setting where name like '{appname}.email.%.bcc';",
|
||||||
|
database=dbname)
|
26
tests/test_wutta.py
Normal file
26
tests/test_wutta.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
from unittest.mock import MagicMock, patch, call
|
||||||
|
|
||||||
|
from wuttamess import wutta as mod
|
||||||
|
|
||||||
|
|
||||||
|
class TestPurgeEmailSettings(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
c = MagicMock()
|
||||||
|
sql = MagicMock()
|
||||||
|
postgres = MagicMock(sql=sql)
|
||||||
|
with patch.object(mod, 'postgres', new=postgres):
|
||||||
|
mod.purge_email_settings(c, 'testy', appname='wuttatest')
|
||||||
|
sql.assert_has_calls([
|
||||||
|
call(c, "delete from setting where name like 'wuttatest.email.%.sender';",
|
||||||
|
database='testy'),
|
||||||
|
call(c, "delete from setting where name like 'wuttatest.email.%.to';",
|
||||||
|
database='testy'),
|
||||||
|
call(c, "delete from setting where name like 'wuttatest.email.%.cc';",
|
||||||
|
database='testy'),
|
||||||
|
call(c, "delete from setting where name like 'wuttatest.email.%.bcc';",
|
||||||
|
database='testy'),
|
||||||
|
])
|
Loading…
Reference in a new issue