0001-prefix-unsubscription-link-with-url-read-from-settin.patch
corbo/models.py | ||
---|---|---|
1 | 1 |
from datetime import datetime |
2 | 2 |
import logging |
3 |
import urlparse |
|
3 | 4 |
from html2text import HTML2Text |
4 | 5 |
from emails.django import Message |
5 | 6 |
from lxml.etree import HTML as HTMLTree |
... | ... | |
91 | 92 |
continue |
92 | 93 |
unsubscribe_token = signing.dumps({'category': self.announce.category.pk, |
93 | 94 |
'identifier': s.identifier}) |
94 |
unsubscribe_link = reverse('unsubscribe', kwargs={'unsubscription_token': unsubscribe_token}) |
|
95 |
unsubscribe_link = urlparse.urljoin(settings.SITE_BASE_URL, reverse('unsubscribe', |
|
96 |
kwargs={'unsubscription_token': unsubscribe_token})) |
|
95 | 97 |
message = template.render(Context({'unsubscribe_link': unsubscribe_link, |
96 | 98 |
'content': self.announce.text})) |
97 | 99 |
m.html = message |
corbo/settings.py | ||
---|---|---|
138 | 138 | |
139 | 139 |
MELLON_IDENTITY_PROVIDERS = [] |
140 | 140 | |
141 |
# default site |
|
142 |
SITE_BASE_URL = 'http://localhost' |
|
143 | ||
141 | 144 |
local_settings_file = os.environ.get('CORBO_SETTINGS_FILE', |
142 | 145 |
os.path.join(os.path.dirname(__file__), 'local_settings.py')) |
143 | 146 |
if os.path.exists(local_settings_file): |
tests/test_emailing.py | ||
---|---|---|
1 |
import urlparse |
|
1 | 2 |
import pytest |
2 | 3 |
import json |
3 | 4 |
from uuid import uuid4 |
... | ... | |
9 | 10 |
from django.utils import timezone |
10 | 11 |
from django.core.files.storage import DefaultStorage |
11 | 12 |
from django.core.urlresolvers import reverse |
13 |
from django.conf import settings |
|
12 | 14 | |
13 | 15 |
from corbo.models import Category, Announce, Subscription, Broadcast |
14 | 16 |
from corbo.models import channel_choices |
... | ... | |
110 | 112 |
assert mail.outbox |
111 | 113 |
signature = signing.dumps({'category': announce.category.pk, |
112 | 114 |
'identifier': uri}) |
113 |
unsubscription_link = reverse('unsubscribe', kwargs={'unsubscription_token': signature}) |
|
115 |
unsubscription_path = reverse('unsubscribe', kwargs={'unsubscription_token': signature}) |
|
116 |
unsubscription_link = urlparse.urljoin(settings.SITE_BASE_URL, unsubscription_path) |
|
114 | 117 |
assert mail.outbox[0].subject == announce.title |
115 | 118 |
assert unsubscription_link in mail.outbox[0].html |
116 | 119 |
assert unsubscription_link in mail.outbox[0].text |
117 | 120 |
mail.outbox = [] |
118 | 121 |
# make sure the uri schema is not in the page |
119 |
resp = app.get(unsubscription_link)
|
|
122 |
resp = app.get(unsubscription_path)
|
|
120 | 123 |
assert scheme not in resp.content |
121 |
- |