Skip to content

Commit

Permalink
Merge 7af4fd1 into e34443e
Browse files Browse the repository at this point in the history
  • Loading branch information
lfalvarez committed May 7, 2020
2 parents e34443e + 7af4fd1 commit de6b9f7
Show file tree
Hide file tree
Showing 25 changed files with 24 additions and 192 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -25,3 +25,4 @@ preguntales/tests/testing_mails/attachments/hello.pd_*.pdf
.ropeproject
.idea/
glenv/
whoosh_index/
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -17,15 +17,11 @@ addons:
- python-pgmagick
- postgresql-client
install:
- wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.1/elasticsearch-2.4.1.tar.gz
- tar -xzf elasticsearch-2.4.1.tar.gz
- ./elasticsearch-2.4.1/bin/elasticsearch &
- pip install -r requirements.txt
- pip install coveralls
- pip install psycopg2
# command to run tests
script:
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
- coverage run manage.py test --noinput
- coverage report -m
after_script:
Expand Down
10 changes: 10 additions & 0 deletions backend_candidate/tests/candidacy_tests.py
Expand Up @@ -73,6 +73,16 @@ def test_instanciate_candidacy(self):
self.assertTrue(candidacy.created)
self.assertTrue(candidacy.updated)

def test_candidate_is_with_us(self):
candidate = Candidate.objects.get(id=1)
user = User.objects.create_user(username='user', password='password')
Candidacy.objects.create(user=user, candidate=candidate)
self.assertFalse(candidate.has_joined())
self.client.login(username=user.username, password='password')
user = User.objects.get(id=user.id)
self.assertTrue(user.last_login)
self.assertTrue(candidate.has_joined())

def test_candidacy_has_logged_in(self):
user = User.objects.create_user(username='user', password='password')
candidacy = Candidacy.objects.create(user=user,
Expand Down
1 change: 0 additions & 1 deletion backend_candidate/tests/ranking_tests.py
Expand Up @@ -129,7 +129,6 @@ def test_ordering_according_to_commitment(self):
commited=False)
ordered_candidates = Candidate.ranking.all()
self.assertEquals(ordered_candidates.count(), Candidate.objects.all().count())
print ordered_candidates[1].elections.first().area.proposals.count()
self.assertEquals(ordered_candidates[1].num_proposals, 3)
self.assertEquals(ordered_candidates[1].num_commitments, 2)

Expand Down
2 changes: 1 addition & 1 deletion elections/management/commands/elections_tags_loader.py
Expand Up @@ -24,5 +24,5 @@ def handle(self, *args, **options):
tag = tag.decode('utf8').strip().lower()
election.tags.add(tag)
except Exception:
print u'excepción con la elección ' + election_name
print(u'excepción con la elección ' + election_name)
pass
2 changes: 1 addition & 1 deletion elections/migrations/0001_initial.py
Expand Up @@ -18,7 +18,7 @@ class Migration(migrations.Migration):
dependencies = [
('popolo', '0002_update_models_from_upstream'),
('taggit', '0002_auto_20150616_2121'),
('candidator', '0005_auto_20200502_2354'),
('candidator', '0004_auto_20150714_1756'),
]

operations = [
Expand Down
58 changes: 0 additions & 58 deletions elections/tests/home_tests.py
Expand Up @@ -4,16 +4,9 @@
from elections.views import HomeView
from elections.forms import ElectionSearchByTagsForm
from elections.models import Election, Candidate
from django.contrib.auth.forms import AuthenticationForm
from backend_citizen.forms import (UserCreationForm as RegistrationForm,
GroupCreationForm)
from popular_proposal.models import (ProposalTemporaryData,
PopularProposal)
from elections.models import Area
from django.contrib.auth.models import User
import datetime
from django.test import override_settings
from django.utils import timezone


class HomeTestCase(TestCase):
Expand Down Expand Up @@ -43,60 +36,9 @@ def test_get_home(self):
self.assertIn('form', response.context)
self.assertIsInstance(response.context['form'], ElectionSearchByTagsForm)

def test_home_view(self):
view = HomeView()
context = view.get_context_data()

self.assertIn('form', context)
self.assertIn('featured_elections', context)
self.assertIsInstance(context['form'], ElectionSearchByTagsForm)
self.assertIn('register_new_form', context)
self.assertIn('login_form', context)
self.assertIn('group_login_form', context)
self.assertIsInstance(context['register_new_form'], RegistrationForm)
self.assertIsInstance(context['login_form'], AuthenticationForm)
self.assertIsInstance(context['group_login_form'], GroupCreationForm)

@override_settings(IMPORTANT_CANDIDATE_IN_LANDING=1)
def test_if_candidate_in_settings_then_bring_it(self):
view = HomeView()
context = view.get_context_data()
expected_candidate = Candidate.objects.get(id=1)
self.assertEquals(context['important_candidate'], expected_candidate)

def test_counter_of_proposals(self):
a_day_ago = timezone.now() - datetime.timedelta(days=1)
ProposalTemporaryData.objects.create(proposer=self.fiera,
area=self.arica,
created=a_day_ago,
data=self.data)
ProposalTemporaryData.objects.create(proposer=self.fiera,
area=self.arica,
created=a_day_ago,
data=self.data)
PopularProposal.objects.create(proposer=self.fiera,
area=self.arica,
data=self.data,
created=a_day_ago,
title=u'This is a title',
clasification=u'education'
)
eight_days_ago = timezone.now() - datetime.timedelta(days=8)
p1 = PopularProposal.objects.create(proposer=self.fiera,
area=self.arica,
data=self.data,
title=u'This is a title',
clasification=u'education',
created=eight_days_ago
)
p1.created = eight_days_ago
p1.save()
p2 = ProposalTemporaryData.objects.create(proposer=self.fiera,
area=self.arica,
data=self.data,
created=eight_days_ago)
p2.created = eight_days_ago
p2.save()
view = HomeView()
context = view.get_context_data()
self.assertEquals(context['total_proposals'], 2)
12 changes: 0 additions & 12 deletions elections/tests/version2/models_tests.py
Expand Up @@ -7,8 +7,6 @@
from django.template import Context, Template
from django.test import override_settings
from elections.models import Topic
from django.contrib.auth.models import User
from backend_candidate.models import Candidacy
import datetime
from django.utils import timezone
from agenda.models import Activity
Expand Down Expand Up @@ -163,16 +161,6 @@ def test_force_has_answer_false(self):
self.election.candidates.add(candidate)
self.assertFalse(candidate.force_has_answer)

def test_candidate_is_with_us(self):
candidate = Candidate.objects.get(id=1)
user = User.objects.create_user(username='user', password='password')
Candidacy.objects.create(user=user, candidate=candidate)
self.assertFalse(candidate.has_joined())
self.client.login(username=user.username, password='password')
user = User.objects.get(id=user.id)
self.assertTrue(user.last_login)
self.assertTrue(candidate.has_joined())

def test_candidate_ordering(self):
TakenPosition.objects.all().delete()
c1 = Candidate.objects.get(id=1)
Expand Down
26 changes: 0 additions & 26 deletions elections/views.py
Expand Up @@ -8,13 +8,8 @@
from elections.models import Candidate, QuestionCategory
from votai_utils.views import HomeViewBase
import logging
from backend_citizen.forms import GroupCreationForm
from candidator.models import Topic, TakenPosition
from django.shortcuts import get_object_or_404
from django.contrib.auth.forms import AuthenticationForm
from backend_citizen.forms import UserCreationForm as RegistrationForm
from popular_proposal.models import PopularProposal
from popular_proposal.filters import ProposalWithoutAreaFilter
from django_filters.views import FilterMixin
from django.core.cache import cache
from django.conf import settings
Expand Down Expand Up @@ -70,24 +65,7 @@ def get_context_data(self, **kwargs):
context['featured_elections'] = featured_elections

context['searchable_elections_enabled'] = True
context['register_new_form'] = RegistrationForm()
context['login_form'] = AuthenticationForm()
context['group_login_form'] = GroupCreationForm()
total_proposals = cache.get('total_proposals')
if total_proposals is None:
total_proposals = PopularProposal.objects.count()
cache.set('total_proposals', total_proposals, 600)
context['total_proposals'] = total_proposals
proposals_with_likers = cache.get('proposals_with_likers')
if proposals_with_likers is None:
proposals_with_likers = PopularProposal.ordered.by_likers()[:9]
cache.set('proposals_with_likers', proposals_with_likers, 600)
context['proposals_with_likers'] = proposals_with_likers
featured_proposals = cache.get('featured_proposals')
if featured_proposals is None:
featured_proposals = PopularProposal.objects.filter(featured=True).filter(content_type__app_label="popular_proposal")
cache.set('featured_proposals', featured_proposals, 600)
context['featured_proposals'] = featured_proposals
featured_candidates = cache.get('featured_candidates')
if featured_candidates is None:
featured_candidates = Candidate.objects.filter(commitments__isnull=False).filter(elections__name="Presidencia")
Expand Down Expand Up @@ -221,10 +199,6 @@ def get_context_data(self, **kwargs):
kwargs = {'data': initial or None,
'area': self.object
}
filterset = ProposalWithoutAreaFilter(**kwargs)
context['proposal_filter_form'] = filterset.form

context['popular_proposals'] = filterset.qs
return context

def get_queryset(self, *args, **kwargs):
Expand Down
Expand Up @@ -19,7 +19,7 @@ def handle(self, *args, **options):
o_m = OrganizationMatrixCreator()
o_m.set_cache(time)
shape = o_m.main_matrix.shape
print shape
print(shape)
# self.stdout.write("Saved matrix of organizations and interactions of dimensions (%d, %d) for %d minutes" % (shape[0], shape[1], time/60))
for e in Election.objects.all():
CandidateGetterFromElectionMixin.get_candidates_from_election_as_list(e, time=time)
1 change: 0 additions & 1 deletion medianaranja2/proposals_getter.py
Expand Up @@ -53,7 +53,6 @@ def get_proposals_from_election(self, elections):
def _get_all_proposals(self, area):
elections = self.get_elections(area)
proposals = self.get_proposals_from_election(elections)
print proposals, elections
return proposals

def get_cache_key(self, area):
Expand Down
2 changes: 1 addition & 1 deletion popular_proposal/reporter.py
Expand Up @@ -39,7 +39,7 @@ def get_mail_context(self):
context['proposals'] = self.get_proposals_dict()
if self.user.profile.is_organization:
context['new_proposals'] = self.get_new_proposals()
print context['new_proposals']
print(context['new_proposals'])
return context

def send_mail(self):
Expand Down
29 changes: 0 additions & 29 deletions popular_proposal/tests/popular_proposal_model_tests.py
Expand Up @@ -125,35 +125,6 @@ def test_featured_proposals_are_first(self):
proposals = PopularProposal.objects.all()
self.assertEquals(p2, proposals.first())

def test_home_view_brings_featured_first(self):
p1 = PopularProposal.objects.create(proposer=self.fiera,
area=self.arica,
data=self.data,
title=u'This is a title1',
clasification=u'education'
)
p2 = PopularProposal.objects.create(proposer=self.fiera,
area=self.arica,
data=self.data,
title=u'This is a title2',
clasification=u'education',
featured=True
)
p3 = PopularProposal.objects.create(proposer=self.fiera,
area=self.arica,
data=self.data,
title=u'This is a title3',
clasification=u'education',
featured=True
)
url = reverse('home')
response = self.client.get(url)
featured_proposals = response.context['featured_proposals']
# this proposal has 4 likes
self.assertIn(p2, featured_proposals)
self.assertIn(p3, featured_proposals)
self.assertNotIn(p1, featured_proposals)

def test_get_ribbon_text(self):
p1 = PopularProposal.objects.create(proposer=self.fiera,
area=self.arica,
Expand Down
11 changes: 0 additions & 11 deletions popular_proposal/tests/subscription_tests.py
Expand Up @@ -363,14 +363,3 @@ def test_manager_order_by_likes(self):
self.assertEquals(ps.all()[2], self.proposal1)
# this proposal has 4 likes
self.assertEquals(ps.all()[3], self.proposal3)

def test_get_home_with_the_proposals(self):
url = reverse('home')
response = self.client.get(url)
ps = response.context['proposals_with_likers']
# this proposal has 4 likes
self.assertEquals(ps.all()[0], self.proposal2)
# this proposal has 4 likes
self.assertEquals(ps.all()[1], self.proposal4)
# this proposal has 4 likes
self.assertEquals(ps.all()[2], self.proposal1)
29 changes: 0 additions & 29 deletions popular_proposal/tests/views_tests.py
Expand Up @@ -163,35 +163,6 @@ def test_filtering_form_by_area(self):
form = filterset.form
self.assertTrue(form.is_valid())

def test_area_detail_view_brings_proposals(self):
url = self.algarrobo.get_absolute_url()
response = self.client.get(url)
self.assertIn(self.popular_proposal1,
response.context['popular_proposals'])
self.assertIn(self.popular_proposal2,
response.context['popular_proposals'])

def test_get_area_with_form(self):
url = self.algarrobo.get_absolute_url()
response = self.client.get(url)
self.assertIsInstance(response.context['proposal_filter_form'],
Form)
self.assertIn(self.popular_proposal1,
response.context['popular_proposals'])

self.assertIn(self.popular_proposal2,
response.context['popular_proposals'])
clasification_id = TOPIC_CHOICES[2][0]
response = self.client.get(url, {'clasification': clasification_id})
form = response.context['proposal_filter_form']
self.assertEquals(form.fields['clasification'].initial,
clasification_id)
self.assertNotIn(self.popular_proposal1,
response.context['popular_proposals'])

self.assertIn(self.popular_proposal2,
response.context['popular_proposals'])


class ProposalFilterTestsCase(PopularProposalTestCaseBase):
def setUp(self):
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Expand Up @@ -5,7 +5,7 @@ django-taggit==0.21.3
loremipsum==1.0.5
elasticsearch==2.4
django-haystack==2.7.0
-e git+https://github.com/lfalvarez/django-candidator.git#egg=django-candidator
-e git+https://github.com/lfalvarez/django-candidator.git@django2#egg=django-candidator
pyyaml>=4.2b1
django-markdown-deux==1.0.4
django-extensions==1.7.5
Expand All @@ -22,7 +22,6 @@ python-memcached==1.58
-e git+https://github.com/mysociety/django-popolo.git#egg=django-popolo
django-mathfilters==0.4.0
django-picklefield==0.3.2
-e git+https://github.com/dokterbob/django-newsletter#egg=django_newsletter
djangorestframework==3.6.2
slumber==0.7.1
-e git+https://github.com/liberation/django-ogp.git#egg=django_ogp
Expand Down
2 changes: 1 addition & 1 deletion scripts_and_data/load_photo_into_disk.py
Expand Up @@ -16,7 +16,7 @@ def save_candidate_image_locally(c, url):
try:
downloaded_image = urllib2.urlopen(url)
except:
print c.name, c.election
print(c.name, c.election)
# c.image = None
# c.save()
return
Expand Down
2 changes: 1 addition & 1 deletion scripts_and_data/stats_compromisos_por_pacto.py
Expand Up @@ -11,4 +11,4 @@

for p in PersonalData.objects.filter(label="Pacto").distinct("value"):
ps = Commitment.objects.filter(candidate__personal_datas__label="Pacto", candidate__personal_datas__value=p.value).count()
print p.value + "|" + str(ps)
print(p.value + "|" + str(ps))
2 changes: 1 addition & 1 deletion scripts_and_data/stats_per_pacto.py
Expand Up @@ -13,4 +13,4 @@
ps = PopularProposal.objects.filter(commitments__candidate__personal_datas__label="Pacto", commitments__candidate__personal_datas__value=p.value).distinct()
stats[p.value] = [proposal.title for proposal in ps ]
for proposal in ps:
print p.value + "|" + proposal.title
print(p.value + "|" + proposal.title)
2 changes: 1 addition & 1 deletion scripts_and_data/stats_pp_por_regiones.py
Expand Up @@ -10,4 +10,4 @@
regiones = {}
for p in PopularProposal.objects.filter(generated_at__classification="Comuna"):
region = p.generated_at.parent.parent.parent
print region.id + u"|" + unicode(p.id) + u"|" + p.title
print(region.id + u"|" + unicode(p.id) + u"|" + p.title)
2 changes: 1 addition & 1 deletion scripts_and_data/stats_propuestas_con_compromisos.py
Expand Up @@ -8,4 +8,4 @@
from elections.models import Election
for p in PopularProposal.objects.exclude(commitments__isnull=True):
c = p.commitments.count()
print unicode(p.id) + u"|" +p.get_classification()+ u"|" + p.title + u"|" + unicode(c)
print(unicode(p.id) + u"|" +p.get_classification()+ u"|" + p.title + u"|" + unicode(c))
Expand Up @@ -18,8 +18,6 @@
from popular_proposal.models import PopularProposal, Commitment
from popular_proposal.forms.form_texts import TOPIC_CHOICES
from django.test import override_settings
from django.shortcuts import render
from constance import config
from constance.test import override_config

class TemplateTagsTestCase(TestCase):
Expand Down

0 comments on commit de6b9f7

Please sign in to comment.