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
20 changed files
with
477 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.9 on 2018-07-31 16:04 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('elections', '0033_auto_20180717_2345'), | ||
('merepresenta', '0009_candidate_facebook_contacted'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='VolunteerProfile', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('area', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='volunteers', to='elections.Area')), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='volunteer_profile', to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.9 on 2018-07-31 16:04 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('merepresenta', '0010_volunteerprofile'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='volunteergetscandidateemaillog', | ||
name='contact', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='backend_candidate.CandidacyContact'), | ||
), | ||
] |
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,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.9 on 2018-07-31 17:49 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('merepresenta', '0011_auto_20180731_1604'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelTable( | ||
name='volunteerprofile', | ||
table='voluntarios_profile', | ||
), | ||
] |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# 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, Election, Area | ||
from django.core.urlresolvers import reverse | ||
from django.contrib.auth.models import User | ||
from social_django.models import UserSocialAuth | ||
from merepresenta.models import VolunteerInCandidate, VolunteerGetsCandidateEmailLog | ||
from django.core import mail | ||
from merepresenta.voluntarios.filters import CandidateFilter | ||
|
||
|
||
PASSWORD="admin123" | ||
ESTADO_IDENTIFIER = 'TO' | ||
|
||
|
||
@override_settings(FILTERABLE_AREAS_TYPE=['state',]) | ||
class CandidateFilterTests(VolunteersTestCaseBase): | ||
def setUp(self): | ||
super(CandidateFilterTests, self).setUp() | ||
self.volunteer = User.objects.create_user(username="voluntario", | ||
password=PASSWORD, | ||
is_staff=True) | ||
self.area = Area.objects.get(identifier=ESTADO_IDENTIFIER) | ||
self.election = Election.objects.create(name="Deputado Estadual") | ||
self.election.area = self.area | ||
self.election.save() | ||
self.candidate = Candidate.objects.get(id=5) | ||
self.election.candidates.add(self.candidate) | ||
self.candidate2 = Candidate.objects.get(id=4) | ||
|
||
|
||
def test_filter(self): | ||
data = {'elections__area': '',} | ||
_filter = CandidateFilter(data=data) | ||
form = _filter.form | ||
self.assertTrue(form.is_valid()) | ||
qs = _filter.qs | ||
self.assertIn(self.candidate, qs) | ||
self.assertIn(self.candidate2, qs) | ||
|
||
data = {'elections__area': self.area.id} | ||
_filter = CandidateFilter(data=data) | ||
qs = _filter.qs | ||
self.assertIn(self.candidate, qs) | ||
self.assertNotIn(self.candidate2, qs) | ||
|
||
|
||
|
||
@override_settings(ROOT_URLCONF='merepresenta.stand_alone_urls') | ||
class VolunteersIndexViewWithFilterTests(VolunteersTestCaseBase): | ||
def setUp(self): | ||
super(VolunteersIndexViewWithFilterTests, self).setUp() | ||
|
||
def create_ordered_candidates(self): | ||
Candidate.objects.filter(id__in=[4, 5]).update(gender=NON_MALE_KEY) | ||
cs = Candidate.objects.filter(id__in=[4,5]) | ||
self.assertEquals(cs[0].is_women, 1) | ||
self.assertEquals(cs[1].is_women, 1) | ||
c = Candidate.objects.get(id=5) | ||
c.race = NON_WHITE_KEY["possible_values"][0] | ||
c.save() | ||
|
||
def test_get_index(self): | ||
url = reverse('volunteer_index') | ||
|
||
u = User.objects.create_user(username="new_user", password="abc", is_staff=True) | ||
self.client.login(username=u.username, password="abc") | ||
response = self.client.get(url) | ||
|
||
self.create_ordered_candidates() | ||
response = self.client.get(url) | ||
self.assertEquals(response.status_code, 200) | ||
self.assertTrue(response.context['filter']) |
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 django.test import TestCase, override_settings | ||
from merepresenta.voluntarios.forms import UpdateAreaForm | ||
from elections.models import Area | ||
from django.contrib.auth.models import User | ||
from merepresenta.voluntarios.models import VolunteerProfile | ||
|
||
|
||
class UpdateAreaForVolunteerForm(TestCase): | ||
def setUp(self): | ||
super(UpdateAreaForVolunteerForm, self).setUp() | ||
self.area = Area.objects.create(name='area') | ||
self.volunteer = User.objects.create_user(username='volunteer', is_staff=True) | ||
self.profile = VolunteerProfile.objects.create(user=self.volunteer) | ||
|
||
|
||
def test_instanciate_and_save(self): | ||
data = { | ||
'area': self.area.id | ||
} | ||
form = UpdateAreaForm(data=data, instance=self.profile) | ||
self.assertTrue(form.is_valid()) | ||
profile = form.save() | ||
|
||
self.assertEquals(profile.area, self.area) | ||
|
Oops, something went wrong.