From 7e3a6a3cffc91d984720a9e3fadc285c2519cc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Jim=C3=A9nez?= Date: Thu, 3 Jan 2013 17:31:34 +0000 Subject: [PATCH] * Add nominate test * If nomcom doesn't have public key, community users wont can nominate. See #913 - Legacy-Id: 5166 --- ietf/nomcom/tests.py | 51 +++++++++++++++++++++++++++-- ietf/nomcom/views.py | 13 +++++++- ietf/templates/nomcom/nominate.html | 35 +++++++++++--------- 3 files changed, 80 insertions(+), 19 deletions(-) diff --git a/ietf/nomcom/tests.py b/ietf/nomcom/tests.py index 5bcc30d86..ecc49c857 100644 --- a/ietf/nomcom/tests.py +++ b/ietf/nomcom/tests.py @@ -11,11 +11,15 @@ from django.contrib.formtools.preview import security_hash from ietf.utils.test_utils import login_testing_unauthorized from ietf.utils.pipe import pipe +from ietf.person.models import Email, Person + from ietf.nomcom.test_data import nomcom_test_data, COMMUNITY_USER, CHAIR_USER, \ MEMBER_USER, SECRETARIAT_USER, EMAIL_DOMAIN from ietf.nomcom.models import NomineePosition, Position, Nominee, \ - NomineePositionState, Feedback, FeedbackType + NomineePositionState, Feedback, FeedbackType, \ + Nomination from ietf.nomcom.forms import EditChairForm, EditMembersForm +from ietf.nomcom.utils import get_nomcom_by_year class NomcomViewsTest(TestCase): @@ -161,9 +165,50 @@ class NomcomViewsTest(TestCase): def test_nominate_view(self): """Verify nominate view""" - # TODO: complete to do a nomination login_testing_unauthorized(self, COMMUNITY_USER, self.nominate_url) - self.check_url_status(self.nominate_url, 200) + response = self.client.get(self.nominate_url) + self.assertEqual(response.status_code, 200) + nomcom = get_nomcom_by_year(self.year) + has_publickey = nomcom.public_key and True or False + self.assertEqual(response.context['has_publickey'], has_publickey) + + if not has_publickey: + return + + position = Position.objects.get(name='IAOC') + candidate_email = 'nominee@example.com', + candidate_name = 'nominee' + comments = 'test nominate view' + candidate_phone = '123456' + + test_data = {'candidate_name': candidate_name, + 'candidate_email': candidate_email, + 'candidate_phone': candidate_phone, + 'position': position.id, + 'comments': comments} + + response = self.client.post(self.nominate_url, test_data) + self.assertEqual(response.status_code, 200) + + # check objects + email = Email.objects.get(address=candidate_email) + Person.objects.get(name=candidate_name, address=candidate_email) + nominee = Nominee.objects.get(email=email) + NomineePosition.objects.get(position=position, nominee=nominee) + feedback = Feedback.objects.get(position=position, + nominee=nominee, + type=FeedbackType.objects.get(slug='nomina'), + author__person__name=COMMUNITY_USER) + # to check feedback comments are saved like enrypted data + self.assertNotEqual(feedback.comments, comments) + + Nomination.objects.get(position=position, + candidate_name=candidate_name, + candidate_mail=candidate_email, + candidate_phone=candidate_phone, + nominee=nominee, + comments=feedback, + nominator_email="%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN)) self.client.logout() diff --git a/ietf/nomcom/views.py b/ietf/nomcom/views.py index f83a96ab7..9c87e5cdb 100644 --- a/ietf/nomcom/views.py +++ b/ietf/nomcom/views.py @@ -68,6 +68,16 @@ def questionnaires(request, year): @login_required def nominate(request, year): nomcom = get_nomcom_by_year(year) + has_publickey = nomcom.public_key and True or False + if not has_publickey: + message = ('warning', "Nomcom don't have public key to ecrypt data, please contact with nomcom chair") + return render_to_response('nomcom/nominate.html', + {'has_publickey': has_publickey, + 'message': message, + 'nomcom': nomcom, + 'year': year, + 'selected': 'nominate'}, RequestContext(request)) + message = None if request.method == 'POST': form = NominateForm(data=request.POST, nomcom=nomcom, user=request.user) @@ -78,7 +88,8 @@ def nominate(request, year): form = NominateForm(nomcom=nomcom, user=request.user) return render_to_response('nomcom/nominate.html', - {'form': form, + {'has_publickey': has_publickey, + 'form': form, 'message': message, 'nomcom': nomcom, 'year': year, diff --git a/ietf/templates/nomcom/nominate.html b/ietf/templates/nomcom/nominate.html index 1021aa754..f8b45518b 100644 --- a/ietf/templates/nomcom/nominate.html +++ b/ietf/templates/nomcom/nominate.html @@ -7,29 +7,34 @@ {% endblock %} {% block nomcom_content %} -
-Your browser has Javascript disabled. Please enable javascript and reload the page. - -
{% if message %}
{{ message.1 }}
{% endif %} -{% if form.errors %}
Please correct the following errors
{% endif %} +{% if has_publickey %} -
{% csrf_token %} - {{ form }} +
+ Your browser has Javascript disabled. Please enable javascript and reload the page. + +
-
- -
-
+ {% if form.errors %}
Please correct the following errors
{% endif %} + +
{% csrf_token %} + {{ form }} + +
+ +
+ +
+{% endif %} {% endblock %} \ No newline at end of file