Skip to content
Extraits de code Groupes Projets
Valider 22067420 rédigé par Jamesie Pic's avatar Jamesie Pic
Parcourir les fichiers

Test positions

parent a9d59b66
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -13,6 +13,7 @@ script:
- ! lesscpy -N static/less/base.less 2>&1 | grep Error
- pep8 . --exclude '*/migrations,docs,static' --ignore E128
- flake8 . --exclude '*/migrations,docs,static' --ignore E128
- django-admin test positions votes core legislature
- django-admin migrate
- django-admin update_score
deploy:
......
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from django.conf.urls import include, patterns, url
from django.contrib import admin
......
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from django.db import models
from django.template.defaultfilters import truncatewords
from django.core.urlresolvers import reverse
from taggit.managers import TaggableManager
from legislature.models import MemopolRepresentative
......@@ -55,3 +37,6 @@ class Position(models.Model):
def unpublish(self):
self.published = False
def get_absolute_url(self):
return reverse('positions:position-detail', args=(self.pk,))
......@@ -7,7 +7,7 @@
.quote
%p.quote-header
{{object.datetime|naturalday:"The d/m/Y"}}, {{object.representative.full_name}} declared :
{{object.datetime|naturalday}}, {{object.representative.full_name}} declared :
.long-quote
= object.text|linebreaks
......
import datetime
import copy
# Create your tests here.
from django.test import TestCase, Client
from legislature.models import MemopolRepresentative
from positions.models import Position
class PositionTest(TestCase):
def setUp(self):
self.client = Client()
self.tags = [u'foo', u'bar']
self.mep = MemopolRepresentative.objects.create(
full_name='%sfull' % self.id(), slug='slug')
self.fixture = {
'tags': ','.join(self.tags),
'datetime': '2015-12-11',
'text': '%stext' % self.id(),
'link': 'http://example.com/%slink' % self.id(),
'representative': self.mep.pk,
}
def test_create_position(self):
response = self.client.post('/positions/create', self.fixture)
expected = 'http://testserver/legislature/slug'
assert response['Location'] == expected
result = Position.objects.get(text='%stext' % self.id())
assert list(result.tags.values_list('name', flat=True)) == self.tags
assert result.datetime == datetime.date(2015, 12, 11)
assert result.link == self.fixture['link']
assert result.representative.representative_ptr_id == self.mep.pk
assert result.published is False
def test_position_publishing(self):
self.client.post('/positions/create', self.fixture)
position = Position.objects.get(text='%stext' % self.id())
get_response = self.client.get(position.get_absolute_url())
assert get_response.status_code == 404
position.published = True
position.save()
get_response = self.client.get(position.get_absolute_url())
assert get_response.status_code == 200
def test_create_position_without_field(self):
for key in self.fixture.keys():
fixture = copy.copy(self.fixture)
fixture.pop(key)
response = self.client.post('/positions/create', fixture)
assert response.context['form'].is_valid() is False
def test_position_detail(self):
fixture = copy.copy(self.fixture)
fixture['representative'] = self.mep
fixture.pop('tags')
position = Position.objects.create(published=True, **fixture)
position.tags.add('%stag' % self.id())
response = self.client.get(position.get_absolute_url())
assert 'Dec. 11, 2015' in response.content
assert '%stag' % self.id() in response.content
assert fixture['link'] in response.content
assert fixture['text'] in response.content
assert self.mep.full_name in response.content
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from django.conf.urls import url
from views import PositionCreate, PositionDetail
urlpatterns = [
# Create a Position
url(
r'^create',
PositionCreate.as_view(),
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter