2013-06-13 16:24:57 +02:00
|
|
|
from django.test.client import Client
|
|
|
|
|
2015-03-26 05:36:10 +01:00
|
|
|
from openslides.assignments.models import Assignment, AssignmentPoll
|
2014-05-12 17:56:07 +02:00
|
|
|
from openslides.config.api import config
|
2014-10-11 14:34:49 +02:00
|
|
|
from openslides.users.models import Group, User
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.utils.test import TestCase
|
2013-06-13 16:24:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AssignmentViewTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
# Admin
|
2013-06-16 12:00:57 +02:00
|
|
|
self.admin = User.objects.get(pk=1)
|
2013-06-13 16:24:57 +02:00
|
|
|
self.admin_client = Client()
|
|
|
|
self.admin_client.login(username='admin', password='admin')
|
|
|
|
|
|
|
|
# Staff
|
2014-10-11 14:34:49 +02:00
|
|
|
self.staff = User.objects.create_user('staff', 'staff')
|
2013-06-13 16:24:57 +02:00
|
|
|
staff_group = Group.objects.get(name='Staff')
|
|
|
|
self.staff.groups.add(staff_group)
|
|
|
|
self.staff.save()
|
|
|
|
self.staff_client = Client()
|
|
|
|
self.staff_client.login(username='staff', password='staff')
|
|
|
|
|
|
|
|
# Delegate
|
2014-10-11 14:34:49 +02:00
|
|
|
self.delegate = User.objects.create_user(username='delegate', password='delegate')
|
2013-06-13 16:24:57 +02:00
|
|
|
delegate_group = Group.objects.get(name='Delegates')
|
|
|
|
self.delegate.groups.add(delegate_group)
|
|
|
|
self.delegate.save()
|
|
|
|
self.delegate_client = Client()
|
|
|
|
self.delegate_client.login(username='delegate', password='delegate')
|
|
|
|
|
|
|
|
# Registered
|
2014-10-11 14:34:49 +02:00
|
|
|
self.registered = User.objects.create_user(username='registered', password='registered')
|
2013-06-13 16:24:57 +02:00
|
|
|
self.registered_client = Client()
|
|
|
|
self.registered_client.login(username='registered', password='registered')
|
|
|
|
|
2015-01-25 15:10:34 +01:00
|
|
|
self.assignment1 = Assignment.objects.create(title='test', open_posts=2)
|
2013-06-13 16:24:57 +02:00
|
|
|
|
|
|
|
def check_url(self, url, test_client, response_cose):
|
|
|
|
response = test_client.get(url)
|
|
|
|
self.assertEqual(response.status_code, response_cose)
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
class TestAssignmentPollDelete(AssignmentViewTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestAssignmentPollDelete, self).setUp()
|
2015-01-25 15:10:34 +01:00
|
|
|
self.assignment1.create_poll()
|
2013-06-13 16:24:57 +02:00
|
|
|
|
|
|
|
def test_get(self):
|
2015-03-26 05:36:10 +01:00
|
|
|
response = self.check_url('/assignments/poll/1/del/', self.admin_client, 302)
|
|
|
|
self.assertRedirects(response, 'assignments/1/')
|
2013-06-13 16:24:57 +02:00
|
|
|
|
|
|
|
def test_post(self):
|
2015-03-26 05:36:10 +01:00
|
|
|
response = self.admin_client.post('/assignments/poll/1/del/', {'yes': 1})
|
|
|
|
self.assertRedirects(response, '/assignments/1/')
|
2013-07-04 15:01:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestAssignmentDetailView(AssignmentViewTestCase):
|
|
|
|
def test_blocked_candidates_view(self):
|
|
|
|
"""
|
|
|
|
Tests that a delegate runs for a vote and then withdraws himself.
|
|
|
|
"""
|
2015-03-26 05:36:10 +01:00
|
|
|
response = self.staff_client.get('/assignments/1/')
|
2013-07-04 15:01:08 +02:00
|
|
|
self.assertContains(response, 'No candidates available.')
|
|
|
|
self.assertNotContains(response, 'Blocked Candidates')
|
|
|
|
|
2015-03-26 05:36:10 +01:00
|
|
|
response = self.delegate_client.get('/assignments/1/candidate/')
|
2013-07-04 15:01:08 +02:00
|
|
|
self.assertTrue(self.assignment1.is_candidate(self.delegate))
|
|
|
|
self.assertFalse(self.assignment1.is_blocked(self.delegate))
|
|
|
|
|
2015-03-26 05:36:10 +01:00
|
|
|
response = self.staff_client.get('/assignments/1/')
|
2013-07-04 15:01:08 +02:00
|
|
|
self.assertNotContains(response, 'No candidates available.')
|
|
|
|
self.assertNotContains(response, 'Blocked Candidates')
|
|
|
|
|
2015-03-26 05:36:10 +01:00
|
|
|
response = self.delegate_client.get('/assignments/1/delete_candidate/')
|
2013-07-04 15:01:08 +02:00
|
|
|
self.assertFalse(self.assignment1.is_candidate(self.delegate))
|
|
|
|
self.assertTrue(self.assignment1.is_blocked(self.delegate))
|
|
|
|
|
2015-03-26 05:36:10 +01:00
|
|
|
response = self.staff_client.get('/assignments/1/')
|
2013-07-04 15:01:08 +02:00
|
|
|
self.assertContains(response, 'No candidates available.')
|
|
|
|
self.assertContains(response, 'Blocked Candidates')
|
2014-05-12 17:56:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestAssignmentPollCreateView(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the creation of assignment polls.
|
|
|
|
"""
|
|
|
|
def test_assignment_add_candidate(self):
|
|
|
|
admin = User.objects.get(pk=1)
|
|
|
|
self.assignment = Assignment.objects.create(
|
2015-01-25 15:10:34 +01:00
|
|
|
title='test_assignment_oiL2heerookiegeirai0',
|
|
|
|
open_posts=1)
|
|
|
|
self.assignment.set_candidate(admin)
|
2014-05-12 17:56:07 +02:00
|
|
|
self.assertEqual(len(Assignment.objects.get(pk=self.assignment.pk).candidates), 1)
|
|
|
|
|
|
|
|
def test_assignment_poll_creation(self):
|
|
|
|
self.test_assignment_add_candidate()
|
2015-01-25 15:10:34 +01:00
|
|
|
self.assignment.set_phase(self.assignment.PHASE_VOTING)
|
2014-05-12 17:56:07 +02:00
|
|
|
admin_client = Client()
|
|
|
|
admin_client.login(username='admin', password='admin')
|
|
|
|
self.assertFalse(AssignmentPoll.objects.exists())
|
|
|
|
self.assertEqual(config['assignment_poll_vote_values'], 'auto')
|
2015-03-26 05:36:10 +01:00
|
|
|
response = admin_client.get('/assignments/1/create_poll/')
|
|
|
|
self.assertRedirects(response, '/assignments/1/')
|
2014-05-12 17:56:07 +02:00
|
|
|
poll = AssignmentPoll.objects.get()
|
|
|
|
self.assertEqual(poll.assignment, self.assignment)
|
|
|
|
self.assertEqual(poll.assignmentoption_set.count(), 1)
|
|
|
|
self.assertTrue(poll.yesnoabstain)
|
2014-08-16 09:25:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestAssignmentPollPdfView(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the creation of the assignment poll pdf
|
|
|
|
"""
|
|
|
|
|
|
|
|
def test_assignment_create_poll_pdf(self):
|
|
|
|
# Create a assignment with a poll
|
|
|
|
admin = User.objects.get(pk=1)
|
2015-01-25 15:10:34 +01:00
|
|
|
assignment = Assignment.objects.create(title='assignment1', open_posts=1)
|
|
|
|
assignment.set_candidate(admin)
|
|
|
|
assignment.set_phase(assignment.PHASE_VOTING)
|
|
|
|
assignment.create_poll()
|
2014-08-16 09:25:18 +02:00
|
|
|
client = Client()
|
|
|
|
client.login(username='admin', password='admin')
|
|
|
|
|
|
|
|
# request the pdf
|
2015-03-26 05:36:10 +01:00
|
|
|
response = client.get('/assignments/poll/1/print/')
|
2014-08-16 09:25:18 +02:00
|
|
|
|
|
|
|
# test the response
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2014-10-18 08:53:51 +02:00
|
|
|
|
|
|
|
|
2014-10-16 18:04:30 +02:00
|
|
|
class TestPollUpdateView(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.admin_client = Client()
|
|
|
|
self.admin_client.login(username='admin', password='admin')
|
|
|
|
|
|
|
|
def test_not_existing_poll(self):
|
|
|
|
"""
|
|
|
|
Tests that a 404 is returned, when a non existing poll is requested.
|
|
|
|
"""
|
2015-01-25 15:10:34 +01:00
|
|
|
Assignment.objects.create(title='test assignment', open_posts=1)
|
2015-03-26 05:36:10 +01:00
|
|
|
url = '/assignments/poll/1/edit/'
|
2014-10-16 18:04:30 +02:00
|
|
|
|
|
|
|
response = self.admin_client.get(url)
|
|
|
|
|
|
|
|
self.assertTrue(response.status_code, '404')
|