Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions jobs/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
from django.test import TestCase
import mock
from django.test import RequestFactory
from .views import ExpressYourInterestView, NotInterestedView

# Create your tests here.

class FormTests(TestCase):

def test_interest_signup_newsletter(self):
request = RequestFactory().post(
'/interested/', #
data={
"email":"test@example.com",
"name":"Test User",
"what_interests_you":"Not Much",
"sign_up_to_newsletter":True
}
)

view = ExpressYourInterestView.as_view()

with mock.patch('newsletters.mixins.signup_newsletter') as mock_signup:
response = view(request)
mock_signup.assert_called_with('test@example.com', 'Test User')

def test_not_interested_signs_up_to_spam(self):
request = RequestFactory().post(
'/not-interested/', #
data={
"email_address":"test@example.com",
"first_name":"Test",
"last_name":"User",
"reason_for_no_interest":"Not Much",
"telephone_number":"None of your beeswax",
"postal_address":"See above",
"signup_for_spam_emails":True
}
)

view = NotInterestedView.as_view()
with mock.patch('newsletters.mixins.signup_newsletter') as mock_signup:
response = view(request)
mock_signup.assert_called_with('test@example.com', 'Test User')


16 changes: 14 additions & 2 deletions jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
from django.views.generic.edit import FormView
from django.views.generic import TemplateView
from .forms import ExpressionOfInterestForm, ImNotInterestedForm
from newsletters.mixins import NewsletterSignupMixin

# Create your views here.

class ExpressYourInterestView(FormView):
class ExpressYourInterestView(NewsletterSignupMixin, FormView):
"""
Users interested in our company can let us know here
"""
template_name = 'express_interest.html'
form_class = ExpressionOfInterestForm
success_url = '/thanks/'

optin_field = 'sign_up_to_newsletter'

def form_valid(self, form):
print 'Sending email to the admins'
return super(ExpressYourInterestView, self).form_valid(form)



class NotInterestedView(FormView):
class NotInterestedView(NewsletterSignupMixin, FormView):
"""
Those absolutely NOT interested can let us know as well
"""
Expand All @@ -28,6 +31,15 @@ class NotInterestedView(FormView):
form_class = ImNotInterestedForm
success_url = '/thanks/?but=not_interested'

optin_field = 'signup_for_spam_emails'
email_field = 'email_address'

def get_subscriber_name(self, form):
return " ".join([
form.cleaned_data['first_name'],
form.cleaned_data['last_name']]
)

def form_valid(self, form):
print "Letting those admins know"
return super(NotInterestedView, self).form_valid(form)
Expand Down
17 changes: 17 additions & 0 deletions newsletters/mixins.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
from .utils import signup_newsletter

class NewsletterSignupMixin(object):

email_field = 'email'
name_field = 'name'
optin_field = 'optin_comms'

def get_subscriber_email(self, form):
return form.cleaned_data[self.email_field]

def get_subscriber_name(self, form):
return form.cleaned_data[self.name_field]

def form_valid(self, form):
if form.cleaned_data.get(self.optin_field) == True:
name = self.get_subscriber_name(form)
email = self.get_subscriber_email(form)
signup_newsletter(email, name)
2 changes: 2 additions & 0 deletions newsletters/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.test import TestCase

# Create your tests here.


7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
Django==1.9.12
Pygments==2.1.3
backports.shutil-get-terminal-size==1.0.0
colorama==0.3.7
decorator==4.0.10
Django==1.9.12
django-bootstrap3==7.1.0
enum34==1.1.6
funcsigs==1.0.2
ipython-genutils==0.1.0
mock==2.0.0
pathlib2==2.1.0
pbr==1.10.0
pickleshare==0.7.4
prompt-toolkit==1.0.9
Pygments==2.1.3
simplegeneric==0.8.1
six==1.10.0
traitlets==4.3.1
Expand Down