forked from mparisot-wescale/memopol2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,15 @@ | |
DEBUG = True | ||
TEMPLATE_DEBUG = DEBUG | ||
|
||
# those emails are used as the contact form recipient | ||
ADMINS = ( | ||
('Admin Istrator', '[email protected]'), | ||
('memopol', '[email protected]'), | ||
) | ||
|
||
MANAGERS = ADMINS | ||
|
||
DEFAULT_FROM_EMAIL='[email protected]' | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
|
@@ -110,6 +113,7 @@ | |
# 3rd party | ||
'south', | ||
'flatblocks', | ||
'contact_form', | ||
|
||
# memopol | ||
'reps', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>{% trans "Contact form" %}</h1> | ||
<form method="POST" id="contact"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<p class="submit"> | ||
<input name="ok" type="submit" value="{% trans 'Send' %}" /> | ||
</p> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{{name}} - {{email}} | ||
=============================================================================== | ||
|
||
{{body}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Memopol Contact] from {{name}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' | ||
import unittest | ||
import logging | ||
from webtest import TestApp | ||
from webtest import TestApp, TestResponse | ||
from pyquery import PyQuery as pq | ||
import django.core.handlers.wsgi | ||
|
||
|
@@ -16,7 +16,9 @@ | |
settings.AUTHENTICATION_BACKENDS = ( | ||
'django.contrib.auth.backends.RemoteUserBackend', | ||
) | ||
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' | ||
|
||
from django.core import mail | ||
from django.contrib.auth.models import User, Permission | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
|
@@ -27,6 +29,7 @@ class TestCase(unittest.TestCase): | |
visited = set() | ||
|
||
def setUp(self): | ||
mail.outbox = [] | ||
self.app = TestApp(django_app) | ||
|
||
def visit_links(self, links): | ||
|
@@ -42,12 +45,27 @@ def visit_links(self, links): | |
except Exception, e: | ||
log.warn('seems that %r is not a valid url. cant be encoded', l) | ||
|
||
@property | ||
def mails(self): | ||
out = [] | ||
for m in mail.outbox: | ||
r = TestResponse() | ||
r.content_type = 'text/email' | ||
r.unicode_body = u'From: %s\nTo: %s\nSubject: %s\n\n%s' % (m.from_email, ', '.join(m.to), m.subject, m.body) | ||
out.append(r) | ||
return out | ||
|
||
@property | ||
def mail(self): | ||
return self.mails[0] | ||
|
||
class UserTestCase(TestCase): | ||
|
||
user = None | ||
user_data = dict(id=99, username='garage1', email='[email protected]') | ||
|
||
def setUp(self): | ||
mail.outbox = [] | ||
self.set_user() | ||
|
||
def set_anonymous(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from tests import * | ||
|
||
class TestContact(TestCase): | ||
|
||
def test_contact(self): | ||
"""test comments""" | ||
resp = self.app.get('/contact/') | ||
form = resp.forms['contact'] | ||
form['name'] = 'Un Garage' | ||
form['email'] = '[email protected]' | ||
resp = form.submit() | ||
resp.mustcontain('<li>This field is required.</li>') | ||
|
||
form = resp.forms['contact'] | ||
form['body'] = 'ACTA sucks' | ||
resp = form.submit() | ||
|
||
self.mail.mustcontain( | ||
'From: [email protected]', | ||
'To: [email protected]', | ||
'Subject: [Memopol Contact] from Un Garage', | ||
'Un Garage - [email protected]', | ||
'==========', | ||
'ACTA sucks', | ||
) |