2018-07-09 23:22:26 +02:00
|
|
|
import pytest
|
2015-03-29 15:49:37 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
2019-04-26 13:25:45 +02:00
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
2018-07-09 23:22:26 +02:00
|
|
|
from django.urls import reverse
|
2016-02-09 21:04:29 +01:00
|
|
|
from rest_framework import status
|
2015-03-29 15:49:37 +02:00
|
|
|
from rest_framework.test import APIClient
|
|
|
|
|
|
|
|
from openslides.assignments.models import Assignment
|
2019-04-26 13:25:45 +02:00
|
|
|
from openslides.core.models import Tag
|
|
|
|
from openslides.mediafiles.models import Mediafile
|
2018-09-01 08:00:00 +02:00
|
|
|
from openslides.utils.autoupdate import inform_changed_data
|
2019-10-18 14:18:49 +02:00
|
|
|
from tests.test_case import TestCase
|
2015-03-29 15:49:37 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
from ..helpers import count_queries
|
2015-03-29 15:49:37 +02:00
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=False)
|
|
|
|
def test_assignment_db_queries():
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2018-07-09 23:22:26 +02:00
|
|
|
Tests that only the following db queries are done:
|
|
|
|
* 1 requests to get the list of all assignments,
|
|
|
|
* 1 request to get all related users,
|
|
|
|
* 1 request to get the agenda item,
|
2019-04-23 16:57:35 +02:00
|
|
|
* 1 request to get the list of speakers,
|
2018-07-09 23:22:26 +02:00
|
|
|
* 1 request to get the polls,
|
2019-04-26 13:25:45 +02:00
|
|
|
* 1 request to get the tags,
|
|
|
|
* 1 request to get the attachments and
|
2018-07-09 23:22:26 +02:00
|
|
|
|
|
|
|
* 10 request to fetch each related user again.
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2019-04-26 13:25:45 +02:00
|
|
|
TODO: The last requests are a bug.
|
2016-09-18 16:00:31 +02:00
|
|
|
"""
|
2018-07-09 23:22:26 +02:00
|
|
|
for index in range(10):
|
2019-01-12 23:01:42 +01:00
|
|
|
Assignment.objects.create(title=f"assignment{index}", open_posts=1)
|
2016-09-18 16:00:31 +02:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
assert count_queries(Assignment.get_elements) == 17
|
2019-04-26 13:25:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CreateAssignment(TestCase):
|
|
|
|
"""
|
|
|
|
Tests basic creation of assignments.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("assignment-list"),
|
|
|
|
{"title": "test_title_ef3jpF)M329f30m)f82", "open_posts": 1},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
assignment = Assignment.objects.get()
|
|
|
|
self.assertEqual(assignment.title, "test_title_ef3jpF)M329f30m)f82")
|
|
|
|
|
|
|
|
def test_with_tags_and_mediafiles(self):
|
|
|
|
Tag.objects.create(name="test_tag")
|
|
|
|
Mediafile.objects.create(
|
|
|
|
title="test_file", mediafile=SimpleUploadedFile("title.txt", b"content")
|
|
|
|
)
|
|
|
|
response = self.client.post(
|
|
|
|
reverse("assignment-list"),
|
|
|
|
{
|
|
|
|
"title": "test_title_ef3jpF)M329f30m)f82",
|
|
|
|
"open_posts": 1,
|
|
|
|
"tags_id": [1],
|
|
|
|
"attachments_id": [1],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
assignment = Assignment.objects.get()
|
|
|
|
self.assertEqual(assignment.title, "test_title_ef3jpF)M329f30m)f82")
|
|
|
|
self.assertTrue(assignment.tags.exists())
|
|
|
|
self.assertTrue(assignment.attachments.exists())
|
2016-09-18 16:00:31 +02:00
|
|
|
|
|
|
|
|
2019-10-18 14:18:49 +02:00
|
|
|
class CandidatureSelf(TestCase):
|
2015-03-29 15:49:37 +02:00
|
|
|
"""
|
|
|
|
Tests self candidation view.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-03-29 15:49:37 +02:00
|
|
|
def setUp(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
self.assignment = Assignment.objects.create(
|
|
|
|
title="test_assignment_oikaengeijieh3ughiX7", open_posts=1
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_nominate_self(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.candidates.filter(username="admin")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_nominate_self_twice(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(get_user_model().objects.get(username="admin"))
|
2015-03-29 15:49:37 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.candidates.filter(username="admin")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_nominate_self_when_finished(self):
|
|
|
|
self.assignment.set_phase(Assignment.PHASE_FINISHED)
|
|
|
|
self.assignment.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_nominate_self_during_voting(self):
|
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk).candidates.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_nominate_self_during_voting_non_admin(self):
|
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
admin = get_user_model().objects.get(username="admin")
|
|
|
|
group_admin = admin.groups.get(name="Admin")
|
|
|
|
group_delegates = type(group_admin).objects.get(name="Delegates")
|
2015-03-29 15:49:37 +02:00
|
|
|
admin.groups.add(group_delegates)
|
2018-02-23 13:00:47 +01:00
|
|
|
admin.groups.remove(group_admin)
|
2018-09-01 08:00:00 +02:00
|
|
|
inform_changed_data(admin)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.post(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_withdraw_self(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(get_user_model().objects.get(username="admin"))
|
2015-03-29 15:49:37 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertFalse(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.candidates.filter(username="admin")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_withdraw_self_twice(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_withdraw_self_when_finished(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(get_user_model().objects.get(username="admin"))
|
2015-03-29 15:49:37 +02:00
|
|
|
self.assignment.set_phase(Assignment.PHASE_FINISHED)
|
|
|
|
self.assignment.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_withdraw_self_during_voting(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(get_user_model().objects.get(username="admin"))
|
2015-03-29 15:49:37 +02:00
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertFalse(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk).candidates.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_withdraw_self_during_voting_non_admin(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(get_user_model().objects.get(username="admin"))
|
2015-03-29 15:49:37 +02:00
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
admin = get_user_model().objects.get(username="admin")
|
|
|
|
group_admin = admin.groups.get(name="Admin")
|
|
|
|
group_delegates = type(group_admin).objects.get(name="Delegates")
|
2015-03-29 15:49:37 +02:00
|
|
|
admin.groups.add(group_delegates)
|
2018-02-23 13:00:47 +01:00
|
|
|
admin.groups.remove(group_admin)
|
2018-09-01 08:00:00 +02:00
|
|
|
inform_changed_data(admin)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
response = self.client.delete(
|
|
|
|
reverse("assignment-candidature-self", args=[self.assignment.pk])
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
|
|
|
|
class CandidatureOther(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
self.assignment = Assignment.objects.create(
|
|
|
|
title="test_assignment_leiD6tiojigh1vei1ait", open_posts=1
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
self.user = get_user_model().objects.create_user(
|
2019-01-06 16:22:33 +01:00
|
|
|
username="test_user_eeheekai4Phue6cahtho",
|
|
|
|
password="test_password_ThahXazeiV8veipeePh6",
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_invalid_data_empty_dict(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]), {}
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_invalid_data_string_instead_of_integer(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": "string_instead_of_integer"},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_invalid_data_user_does_not_exist(self):
|
|
|
|
# ID of a user that does not exist.
|
|
|
|
# Be careful: Here we do not test that the user does not exist.
|
|
|
|
inexistent_user_pk = self.user.pk + 1000
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": inexistent_user_pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_nominate_other(self):
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.candidates.filter(username="test_user_eeheekai4Phue6cahtho")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_nominate_other_twice(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(
|
2019-01-06 16:22:33 +01:00
|
|
|
get_user_model().objects.get(username="test_user_eeheekai4Phue6cahtho")
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
2015-11-28 21:23:21 +01:00
|
|
|
self.assertEqual(response.status_code, 400)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_nominate_other_when_finished(self):
|
|
|
|
self.assignment.set_phase(Assignment.PHASE_FINISHED)
|
|
|
|
self.assignment.save()
|
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_nominate_other_during_voting(self):
|
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.candidates.filter(username="test_user_eeheekai4Phue6cahtho")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_nominate_other_during_voting_non_admin(self):
|
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
admin = get_user_model().objects.get(username="admin")
|
|
|
|
group_admin = admin.groups.get(name="Admin")
|
|
|
|
group_delegates = type(group_admin).objects.get(name="Delegates")
|
2015-03-29 15:49:37 +02:00
|
|
|
admin.groups.add(group_delegates)
|
2018-02-23 13:00:47 +01:00
|
|
|
admin.groups.remove(group_admin)
|
2018-09-01 08:00:00 +02:00
|
|
|
inform_changed_data(admin)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_delete_other(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(self.user)
|
2015-03-29 15:49:37 +02:00
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertFalse(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.candidates.filter(username="test_user_eeheekai4Phue6cahtho")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_delete_other_twice(self):
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_delete_other_when_finished(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(self.user)
|
2015-03-29 15:49:37 +02:00
|
|
|
self.assignment.set_phase(Assignment.PHASE_FINISHED)
|
|
|
|
self.assignment.save()
|
|
|
|
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
def test_delete_other_during_voting(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(self.user)
|
2015-03-29 15:49:37 +02:00
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
|
|
|
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertFalse(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.candidates.filter(username="test_user_eeheekai4Phue6cahtho")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_delete_other_during_voting_non_admin(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(self.user)
|
2015-03-29 15:49:37 +02:00
|
|
|
self.assignment.set_phase(Assignment.PHASE_VOTING)
|
|
|
|
self.assignment.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
admin = get_user_model().objects.get(username="admin")
|
|
|
|
group_admin = admin.groups.get(name="Admin")
|
|
|
|
group_delegates = type(group_admin).objects.get(name="Delegates")
|
2015-03-29 15:49:37 +02:00
|
|
|
admin.groups.add(group_delegates)
|
2018-02-23 13:00:47 +01:00
|
|
|
admin.groups.remove(group_admin)
|
2018-09-01 08:00:00 +02:00
|
|
|
inform_changed_data(admin)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-candidature-other", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
|
|
|
|
class MarkElectedOtherUser(TestCase):
|
|
|
|
"""
|
|
|
|
Tests marking an elected user. We use an extra user here to show that
|
|
|
|
admin can not only mark himself but also other users.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
2015-03-29 15:49:37 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = APIClient()
|
2019-01-06 16:22:33 +01:00
|
|
|
self.client.login(username="admin", password="admin")
|
|
|
|
self.assignment = Assignment.objects.create(
|
|
|
|
title="test_assignment_Ierohsh8rahshofiejai", open_posts=1
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
self.user = get_user_model().objects.create_user(
|
2019-01-06 16:22:33 +01:00
|
|
|
username="test_user_Oonei3rahji5jugh1eev",
|
|
|
|
password="test_password_aiphahb5Nah0cie4iP7o",
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_mark_elected(self):
|
2019-10-18 14:18:49 +02:00
|
|
|
self.assignment.add_candidate(
|
2019-01-06 16:22:33 +01:00
|
|
|
get_user_model().objects.get(username="test_user_Oonei3rahji5jugh1eev")
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
response = self.client.post(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-mark-elected", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertTrue(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.elected.filter(username="test_user_Oonei3rahji5jugh1eev")
|
|
|
|
.exists()
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
def test_mark_unelected(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
user = get_user_model().objects.get(username="test_user_Oonei3rahji5jugh1eev")
|
2015-06-30 02:37:57 +02:00
|
|
|
self.assignment.set_elected(user)
|
2015-03-29 15:49:37 +02:00
|
|
|
response = self.client.delete(
|
2019-01-06 16:22:33 +01:00
|
|
|
reverse("assignment-mark-elected", args=[self.assignment.pk]),
|
|
|
|
{"user": self.user.pk},
|
|
|
|
)
|
2015-03-29 15:49:37 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertFalse(
|
|
|
|
Assignment.objects.get(pk=self.assignment.pk)
|
|
|
|
.elected.filter(username="test_user_Oonei3rahji5jugh1eev")
|
|
|
|
.exists()
|
|
|
|
)
|