def test_button_html_success(self): """Test we can render button.html""" new_campaign = Campaign(campaign_url='test.com') new_campaign.save() response = self.client.get('/button/?campaign_id=%s' % (new_campaign.id)) #import ipdb; ipdb.set_trace() self.assertEqual('button.html', response.templates[0].name)
def test_take_action_template(self): """ tests we can server take_action_template """ new_campaign = Campaign(campaign_url='test.com') new_campaign.save() response = self.client.get('/takeaction/?campaign_id=%s' % (new_campaign.id)) self.assertEqual('takeaction.html', response.templates[0].name)
def test_post_response_success(self): """Tests we can successfull post a rsponse as a dm""" new_campaign = Campaign(campaign_url='test.com') new_campaign.save() new_dm = DecisionMaker(name='barak', title='pres') new_dm.save() new_campaign.decision_maker.add(new_dm) post_params = { 'campaign_ids': new_campaign.id, 'response_url': 'test.com', } response = self.client.post('/post_response/', post_params) #import ipdb; ipdb.set_trace() self.assertTrue('POST SUCCESSFUL' in response.content)
def test_proccess_takeaction_success(self): """ Tests that we can successfull process a take action. """ new_campaign = Campaign(campaign_url='test.com') new_campaign.save() post_params = { 'email': '*****@*****.**', 'campaign_id': new_campaign.id, } response = self.client.post('/process_takeaction/', post_params) activists = Activist.objects.all() self.assertEqual(activists.count(), 1) responses = ActivistResponse.objects.filter(activist=activists[0]) self.assertEqual(responses.count(), 1)
def save_campaign(request): """Creates a new campaign""" required_fields_list = [ 'campaign_url', 'decision_makers', 'email', ] for field in required_fields_list: if field not in request.POST: return HttpResponse('Missing %s param in request' % (field)) email = request.POST.get('email', None) name = request.POST.get('name', None) new_organizer = None if email is not None: try: new_organizer = Organizer.objects.get(email=email) except Organizer.DoesNotExist: new_organizer = Organizer(email=email) new_organizer.save() try: campaign = Campaign.objects.get(campaign_url=request.POST['campaign_url']) return HttpResponse('Campaign Already Exists with that url') except Campaign.DoesNotExist: new_campaign_params = { 'campaign_url': request.POST['campaign_url'], 'organizer': new_organizer, 'name': name, } campaign = Campaign(**new_campaign_params) campaign.save() decision_makers = request.POST['decision_makers'].split(',') # this will be a list of ids from the form for dm_id in decision_makers: try: dm = DecisionMaker.objects.get(pk=dm_id) except DecisionMaker.DoesNotExist: continue campaign.decision_maker.add(dm) response_iframe = '<iframe src="%sresponses/?campaign_id=%s" height="200" height="200" scrolling="no" frameborder="0"></iframe>' % (settings.URL_ROOT, campaign.id) takeaction_iframe = '<iframe src="%sbutton/?campaign_id=%s" height="90" width="150" scrolling="no" frameborder="0"></iframe>' % (settings.URL_ROOT, campaign.id) return render_to_response('create_campaign.html', {'takeaction_iframe': takeaction_iframe, 'response_iframe': response_iframe}, context_instance=RequestContext(request))