tests: fix newsletters cell tests

This commit is contained in:
Serghei Mihai 2016-02-11 18:39:23 +01:00
parent a3f1ff3960
commit 538497f58f
2 changed files with 18 additions and 7 deletions

View File

@ -8,7 +8,7 @@ KNOWN_SERVICES = {
'secret': 'combo', 'orig': 'combo'},
},
'passerelle': {
'default': {'title': 'test', 'url': 'http://example.com',
'default': {'title': 'test', 'url': 'http://example.org',
'secret': 'combo', 'orig': 'combo'}
}
}

View File

@ -69,7 +69,7 @@ USER_EMAIL = 'foobar@example.com'
def cell():
page = Page()
page.save()
cell = NewslettersCell(title='Newsletter test', url='http://example.com/',
cell = NewslettersCell(title='Newsletter test', url='http://example.org/',
page=page, order=0)
cell.save()
return cell
@ -129,6 +129,17 @@ def mocked_requests_connection_error(*args, **kwargs):
@mock.patch('combo.apps.newsletters.models.requests.post',
side_effect=mocked_requests_connection_error)
def test_failed_set_subscriptions(mock_post, cell):
restrictions = ('sms', 'mail')
cell.transports_restrictions = ','.join(restrictions)
subscriptions = [{'id': '1', 'transports': [{'id': 'mail', 'text': 'mail'}]},
{'id': '7', 'transports': [{'id': 'sms', 'text': 'sms'}]},
{'id': '8', 'transports': [{'id': 'sms', 'text': 'sms'},
{'id': 'mail', 'text': 'mail'}]}]
with pytest.raises(SubscriptionsSaveError):
cell.set_subscriptions(subscriptions, email=USER_EMAIL)
@mock.patch('combo.apps.newsletters.models.requests.post')
def test_set_subscriptions(mock_post, cell):
restrictions = ('sms', 'mail')
cell.transports_restrictions = ','.join(restrictions)
@ -136,11 +147,11 @@ def test_set_subscriptions(mock_post, cell):
{'id': '7', 'transports': [{'id': 'sms', 'text': 'sms'}]},
{'id': '8', 'transports': [{'id': 'sms', 'text': 'sms'},
{'id': 'mail', 'text': 'mail'}]}]
try:
cell.set_subscriptions(subscriptions, email=USER_EMAIL)
except SubscriptionsSaveError:
pass
mock_json = mock.Mock()
mock_json.json.return_value = {'err': 0,
'data': True}
mock_post.return_value = mock_json
cell.set_subscriptions(subscriptions, email=USER_EMAIL)
def mocked_requests_get(*args, **kwargs):
url = args[0]