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
14 changes: 11 additions & 3 deletions jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
from django.views.generic.edit import FormView
from django.views.generic import TemplateView
from .forms import ExpressionOfInterestForm, ImNotInterestedForm
from newsletters.mixins import NewsletterSubscriberMixin

# Create your views here.

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

def form_valid(self, form):
print 'Sending email to the admins'
super(ExpressYourInterestView, self).signup_newsletter(form.cleaned_data['sign_up_to_newsletter'],
form.cleaned_data['email'],
form.cleaned_data['name']) #I have to call this method here because the form fields names are
#different on both the forms. Otherwise I would have used in built mixins of django.
return super(ExpressYourInterestView, self).form_valid(form)



class NotInterestedView(FormView):
class NotInterestedView(FormView,NewsletterSubscriberMixin):
"""
Those absolutely NOT interested can let us know as well
"""
Expand All @@ -30,6 +35,9 @@ class NotInterestedView(FormView):

def form_valid(self, form):
print "Letting those admins know"
super(ExpressYourInterestView, self).signup_newsletter(form.cleaned_data['signup_for_spam_emails'],
form.cleaned_data['email_address'],
form.cleaned_data['first_name'])
return super(NotInterestedView, self).form_valid(form)

class ThanksView(TemplateView):
Expand Down
13 changes: 13 additions & 0 deletions newsletters/mixins.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
from .utils import signup_newsletter

class NewsletterSubscriberMixin(object):
"""
View mixin which requires boolean subscribe, email id, name of user.
"""
def signup_newsletter(self,subscribe,email,name):
print "mixin called"
is_subscribed=False
if subscribe:
signup_newsletter(email,name)
is_subscribed=True
return is_subscribed


43 changes: 43 additions & 0 deletions newsletters/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
from django.test import TestCase

# Create your tests here.

from django.test import TestCase
from newsletters.mixins import NewsletterSubscriberMixin

class NewsletterSubscriberTestCase(TestCase):
'''
Tests signup_newsletter mixin
'''

class DummyView(NewsletterSubscriberMixin):
'''
To test signup_newsletter we need validated form data
'''
pass

def setUp(self):

super(NewsletterSubscriberTestCase, self).setUp()
self.view = self.DummyView()

def test_with_subscription_enabled(self):

# Prepare initial params
subscribe = True
email_id = 'abc@pqr.com'
name = 'abc'
# Launch Mixin's get_context_data
is_subscribed = self.view.signup_newsletter(subscribe,email_id, name)
print "Test with subscription enabled"
# Your checkings here
self.assertTrue(is_subscribed)

def test_with_subscription_disabled(self):

# Prepare initial params
subscribe = False
email_id = 'abc@pqr.com'
name = 'abc'
# Launch Mixin's get_context_data
is_subscribed = self.view.signup_newsletter(subscribe,email_id, name)
print "Test with subscription disabled"
# Your checkings here
self.assertFalse(is_subscribed)