Skip to content

Commit

Permalink
Agregando inciios del backend_de candidatos de #MeRepresenta
Browse files Browse the repository at this point in the history
  • Loading branch information
lfalvarez committed Jul 31, 2018
1 parent e22cb7c commit cba3a11
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 3 deletions.
Empty file.
10 changes: 10 additions & 0 deletions merepresenta/candidates_backend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

from django.conf.urls import url, include
from django.views.generic.base import TemplateView


urlpatterns = [
url(r'^$',
TemplateView.as_view(template_name="merepresenta/index.html"),
name='candidate_cpf'),
]
Empty file.
20 changes: 20 additions & 0 deletions merepresenta/migrations/0013_candidate_data_de_nascimento.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-07-31 19:35
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('merepresenta', '0012_auto_20180731_1749'),
]

operations = [
migrations.AddField(
model_name='candidate',
name='data_de_nascimento',
field=models.DateField(null=True),
),
]
3 changes: 2 additions & 1 deletion merepresenta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Candidate(OriginalCandidate):
email_repeated = models.NullBooleanField()
is_ghost = models.BooleanField(default=False)
facebook_contacted = models.BooleanField(default=False)
data_de_nascimento = models.DateField(null=True)

partido = models.ForeignKey("Partido", null=True)

Expand Down Expand Up @@ -125,4 +126,4 @@ class Partido(models.Model):
## But as I'm coding it I am becoming aware that this could be a good feature to have in the feature, this is why I'm keeping this in
## an inner module, so when I have more time and the need from another NGO to have the volunteers backend
## I can grab it and move it to another application
from merepresenta.voluntarios.models import VolunteerProfile
# from merepresenta.voluntarios.models import VolunteerProfile
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# coding=utf-8
from django.test import TestCase, override_settings
from merepresenta.models import Candidate, NON_WHITE_KEY, NON_MALE_KEY
from merepresenta.tests.volunteers import VolunteersTestCaseBase
from backend_candidate.models import CandidacyContact
from elections.models import PersonalData, Area
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from social_django.models import UserSocialAuth
import mock
from django.views.generic.edit import FormView
from django.core import mail
from merepresenta.models import VolunteerInCandidate, VolunteerGetsCandidateEmailLog, Candidate
from merepresenta.voluntarios.models import VolunteerProfile
from elections.models import Election, Area
from django.conf import settings
import datetime

PASSWORD = 'candidato123'

@override_settings(ROOT_URLCONF='merepresenta.stand_alone_urls')
class CandidateLoginView(VolunteersTestCaseBase):
def setUp(self):
super(CandidateLoginView, self).setUp()
session = self.client.session
session['facebook_state'] = '1'
session.save()

# def test_get_login(self):
# url = reverse('candidate_login')
# response = self.client.get(url)
# self.assertEquals(response.status_code, 200)


@override_settings(ROOT_URLCONF='merepresenta.stand_alone_urls')
class CPFChoosingView(VolunteersTestCaseBase):
def setUp(self):
super(CPFChoosingView, self).setUp()


def test_ask_for_cpf_view(self):
url = reverse('candidate_cpf')
user = User.objects.create_user(username="candidato", password=PASSWORD)
self.client.login(username=user.username, password=PASSWORD)
response = self.client.get(url)
self.assertEquals(response.status_code, 200)

# def test_post_to_the_view(self):
# d = datetime.datetime(2009, 10, 5, 18, 00)
# c = Candidate.objects.create(name='THE candidate', cpf='1234', )
# data = {

# }
# # self.assertTrue(response.context['form'])

# @override_settings(SOCIAL_AUTH_FACEBOOK_KEY='1',
# SOCIAL_AUTH_FACEBOOK_SECRET='2')
# @mock.patch('social_core.backends.base.BaseAuth.request')
# def test_complete_with_facebook(self, mock_request):
# volunteer_index_url = reverse('volunteer_index')
# url = reverse('candidate_social_complete', kwargs={'backend': 'facebook'})
# url += '?code=2&state=1'
# mock_request.return_value.json.return_value = {'access_token': '123'}
# with mock.patch('django.contrib.sessions.backends.base.SessionBase.set_expiry', side_effect=[OverflowError, None]):
# response = self.client.get(url)

# self.assertEqual(response.status_code, 302)
# self.assertEqual(response.url, volunteer_index_url)
# social_user = UserSocialAuth.objects.get()
# created_user = social_user.user
# self.assertTrue(created_user.is_staff)
# self.assertTrue(created_user.volunteer_profile)
# self.assertIsNone(created_user.volunteer_profile.area)
5 changes: 4 additions & 1 deletion merepresenta/tests/management_command_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class JustForNowProcessor(TSEProcessorMixin):
processor = JustForNowProcessor()
result = processor.do_something(self.data)
area = result['area']
print rj_area.id, area.id
self.assertEquals(area.id, rj_area.id)
election = result['election']
self.assertEquals(election.name, 'DEPUTADO FEDERAL')
Expand All @@ -54,6 +53,10 @@ class JustForNowProcessor(TSEProcessorMixin):
self.assertEquals(candidato.original_email, 'candidato@partido.com')
self.assertFalse(candidato.email_repeated)
self.assertEquals(candidato.partido, partido)
d = candidato.data_de_nascimento
self.assertEquals(d.year, 1958)
self.assertEquals(d.month, 7)
self.assertEquals(d.day, 21)


def test_calling_command(self):
Expand Down
7 changes: 6 additions & 1 deletion merepresenta/tse_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tse_data_importer.csv_reader import CsvReader
from tse_data_importer.importer import RowsReaderAdapter
from django.conf import settings
from datetime import datetime

def output_logger(self, msg):
print msg
Expand All @@ -20,11 +21,15 @@ def gender_definer(self, gender):

def process_candidate(self, candidate_dict, election, partido):
gender = self.gender_definer(candidate_dict['gender'])

try:
data_de_nascimento = datetime.strptime(candidate_dict['date_of_birth'], "%d/%m/%Y").date()
except:
data_de_nascimento = None
candidate, created = Candidate.objects.get_or_create(name=candidate_dict['nome'],
nome_completo=candidate_dict['nome_completo'],
numero=candidate_dict['number'],
cpf=candidate_dict['cpf'],
data_de_nascimento=data_de_nascimento,
race=candidate_dict['race'],
original_email=candidate_dict['mail'],
email_repeated=candidate_dict['email_repeated'],
Expand Down
1 change: 1 addition & 0 deletions merepresenta/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get_form_class(self):
url(r'^answers/?$',
MeRepresentaMeiaLaranjaQuestionsWizardForm.as_view(),
name='questions'),
url(r'^candidatos/', include('merepresenta.candidates_backend.urls')),
url(r'^eleccion/(?P<election_slug>[-\w]+)/(?P<slug>[-\w]+)/?$',
CandidateDetailView.as_view(template_name='merepresenta/candidate_detail.html'),
name='candidate_detail_view'
Expand Down

0 comments on commit cba3a11

Please sign in to comment.