tests: make a fixture of EmailsMocking (#15555)
This commit is contained in:
parent
c56fada49e
commit
5c28912e91
|
@ -3,6 +3,8 @@ import ConfigParser
|
|||
|
||||
import pytest
|
||||
|
||||
from utilities import EmailsMocking
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption('--without-postgresql-tests', action='store_true',
|
||||
|
@ -49,3 +51,9 @@ def fargo_secret(request, pub):
|
|||
@pytest.fixture
|
||||
def welco_url(request, pub):
|
||||
return site_options(request, pub, 'options', 'welco_url', 'http://welco.example.net')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def emails():
|
||||
with EmailsMocking() as mock:
|
||||
yield mock
|
||||
|
|
|
@ -32,7 +32,8 @@ from wcs.formdef import FormDef
|
|||
from wcs import fields
|
||||
|
||||
from utilities import (get_app, login, create_temporary_pub,
|
||||
clean_temporary_pub, emails, sms_mocking)
|
||||
clean_temporary_pub, sms_mocking)
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
if 'pub' in metafunc.fixturenames:
|
||||
|
@ -2787,12 +2788,11 @@ def test_360_user_view(pub):
|
|||
resp = app.get('/backoffice/management/users/%s/' % user.id)
|
||||
assert resp.body.count('<li') == (count_li - 2)
|
||||
|
||||
def test_360_user_view_tracking_code(pub):
|
||||
def test_360_user_view_tracking_code(pub, emails):
|
||||
if not pub.is_using_postgresql():
|
||||
pytest.skip('this requires SQL')
|
||||
return
|
||||
|
||||
emails.empty()
|
||||
sms_mocking.empty()
|
||||
|
||||
user = create_user(pub)
|
||||
|
|
|
@ -32,7 +32,7 @@ from wcs.data_sources import NamedDataSource
|
|||
from wcs import fields
|
||||
from wcs.sessions import BasicSession
|
||||
|
||||
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub, emails
|
||||
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
||||
|
||||
|
||||
def assert_equal_zip(stream1, stream2):
|
||||
|
@ -809,7 +809,7 @@ def test_form_multi_page_post_conditions(pub):
|
|||
resp = resp.forms[0].submit('submit')
|
||||
assert 'Check values then click submit.' in resp.body
|
||||
|
||||
def test_form_submit_with_user(pub):
|
||||
def test_form_submit_with_user(pub, emails):
|
||||
create_user(pub)
|
||||
formdef = create_formdef()
|
||||
page = login(get_app(pub), username='foo', password='foo').get('/test/')
|
||||
|
@ -1053,8 +1053,7 @@ def test_form_empty_tracking_code(pub):
|
|||
assert resp.location == 'http://example.net/code/%s/load' % tracking_code
|
||||
resp = resp.follow(status=404)
|
||||
|
||||
def test_form_tracking_code_email(pub):
|
||||
emails.empty()
|
||||
def test_form_tracking_code_email(pub, emails):
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
formdef.fields = [fields.StringField(id='0', label='string')]
|
||||
|
|
|
@ -7,7 +7,7 @@ from quixote import cleanup
|
|||
from wcs.qommon.http_request import HTTPRequest
|
||||
from wcs.qommon.ident.password_accounts import PasswordAccount
|
||||
|
||||
from utilities import get_app, create_temporary_pub, clean_temporary_pub, emails
|
||||
from utilities import get_app, create_temporary_pub, clean_temporary_pub
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
if 'pub' in metafunc.fixturenames:
|
||||
|
@ -117,7 +117,7 @@ def test_user_password_accents(pub):
|
|||
account = PasswordAccount.get('foo')
|
||||
assert account.password == password
|
||||
|
||||
def test_admin_notification(pub):
|
||||
def test_admin_notification(pub, emails):
|
||||
pub.cfg['identities'] = {'creation': 'self', 'notify-on-register': True}
|
||||
pub.write_cfg()
|
||||
pub.user_class.wipe()
|
||||
|
@ -134,7 +134,7 @@ def test_admin_notification(pub):
|
|||
assert emails.get('New Registration')
|
||||
assert emails.get('New Registration').get('email_rcpt') == ['admin@localhost']
|
||||
|
||||
def test_user_notification(pub):
|
||||
def test_user_notification(pub, emails):
|
||||
pub.cfg['identities'] = {'creation': 'self', 'notify-on-register': False,
|
||||
'email-as-username': True}
|
||||
pub.write_cfg()
|
||||
|
@ -179,7 +179,7 @@ def test_user_login(pub):
|
|||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/'
|
||||
|
||||
def test_forgotten(pub):
|
||||
def test_forgotten(pub, emails):
|
||||
pub.cfg['identities'] = {'creation': 'self', 'notify-on-register': False}
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
|
|
|
@ -37,9 +37,10 @@ from wcs.wf.geolocate import GeolocateWorkflowStatusItem
|
|||
from wcs.wf.backoffice_fields import SetBackofficeFieldsWorkflowStatusItem
|
||||
from wcs.wf.redirect_to_url import RedirectToUrlWorkflowStatusItem
|
||||
|
||||
from utilities import (create_temporary_pub, MockSubstitutionVariables, emails,
|
||||
from utilities import (create_temporary_pub, MockSubstitutionVariables,
|
||||
http_requests, clean_temporary_pub, sms_mocking)
|
||||
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
|
||||
|
@ -558,7 +559,7 @@ def test_register_comment_attachment(pub):
|
|||
assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments'))) == 1
|
||||
assert url1 == url2
|
||||
|
||||
def test_email(pub):
|
||||
def test_email(pub, emails):
|
||||
pub.substitutions.feed(MockSubstitutionVariables())
|
||||
|
||||
formdef = FormDef()
|
||||
|
@ -583,7 +584,6 @@ def test_email(pub):
|
|||
role2.emails = ['bar@localhost', 'baz@localhost']
|
||||
role2.store()
|
||||
|
||||
emails.empty()
|
||||
# send using an uncompleted element
|
||||
item = SendmailWorkflowStatusItem()
|
||||
item.perform(formdata) # nothing
|
||||
|
@ -1492,7 +1492,7 @@ def test_workflow_display_message_to(pub):
|
|||
assert 'd1' in formdata.get_workflow_messages()
|
||||
assert 'd2' in formdata.get_workflow_messages()
|
||||
|
||||
def test_workflow_roles(pub):
|
||||
def test_workflow_roles(pub, emails):
|
||||
pub.substitutions.feed(MockSubstitutionVariables())
|
||||
|
||||
user = pub.user_class(name='foo')
|
||||
|
|
|
@ -175,14 +175,8 @@ def login(app, username='admin', password='admin'):
|
|||
assert resp.status_int == 302
|
||||
return app
|
||||
|
||||
class EmailsMocking(object):
|
||||
def __init__(self):
|
||||
self.emails = {}
|
||||
import wcs.qommon.emails
|
||||
import qommon.emails
|
||||
wcs.qommon.emails.create_smtp_server = self.create_smtp_server
|
||||
qommon.emails.create_smtp_server = self.create_smtp_server
|
||||
|
||||
class EmailsMocking(object):
|
||||
def create_smtp_server(self, *args, **kwargs):
|
||||
class MockSmtplibSMTP(object):
|
||||
def __init__(self, emails):
|
||||
|
@ -216,7 +210,22 @@ class EmailsMocking(object):
|
|||
def count(self):
|
||||
return len(self.emails)
|
||||
|
||||
emails = EmailsMocking()
|
||||
def __enter__(self):
|
||||
import wcs.qommon.emails
|
||||
import qommon.emails
|
||||
self.wcs_create_smtp_server = wcs.qommon.emails.create_smtp_server
|
||||
self.qommon_create_smtp_server = qommon.emails.create_smtp_server
|
||||
|
||||
wcs.qommon.emails.create_smtp_server = self.create_smtp_server
|
||||
qommon.emails.create_smtp_server = self.create_smtp_server
|
||||
|
||||
self.emails = {}
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, tb):
|
||||
del self.emails
|
||||
wcs.qommon.emails.create_smtp_server = self.wcs_create_smtp_server
|
||||
qommon.emails.create_smtp_server = self.qommon_create_smtp_server
|
||||
|
||||
|
||||
class MockSubstitutionVariables(object):
|
||||
|
|
Loading…
Reference in New Issue