Skip to content

Commit 7e3a6a3

Browse files
committed
* Add nominate test
* If nomcom doesn't have public key, community users wont can nominate. See ietf-tools#913 - Legacy-Id: 5166
1 parent 9f9c795 commit 7e3a6a3

3 files changed

Lines changed: 80 additions & 19 deletions

File tree

ietf/nomcom/tests.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
from ietf.utils.test_utils import login_testing_unauthorized
1212
from ietf.utils.pipe import pipe
1313

14+
from ietf.person.models import Email, Person
15+
1416
from ietf.nomcom.test_data import nomcom_test_data, COMMUNITY_USER, CHAIR_USER, \
1517
MEMBER_USER, SECRETARIAT_USER, EMAIL_DOMAIN
1618
from ietf.nomcom.models import NomineePosition, Position, Nominee, \
17-
NomineePositionState, Feedback, FeedbackType
19+
NomineePositionState, Feedback, FeedbackType, \
20+
Nomination
1821
from ietf.nomcom.forms import EditChairForm, EditMembersForm
22+
from ietf.nomcom.utils import get_nomcom_by_year
1923

2024

2125
class NomcomViewsTest(TestCase):
@@ -161,9 +165,50 @@ def test_comments_view(self):
161165

162166
def test_nominate_view(self):
163167
"""Verify nominate view"""
164-
# TODO: complete to do a nomination
165168
login_testing_unauthorized(self, COMMUNITY_USER, self.nominate_url)
166-
self.check_url_status(self.nominate_url, 200)
169+
response = self.client.get(self.nominate_url)
170+
self.assertEqual(response.status_code, 200)
171+
nomcom = get_nomcom_by_year(self.year)
172+
has_publickey = nomcom.public_key and True or False
173+
self.assertEqual(response.context['has_publickey'], has_publickey)
174+
175+
if not has_publickey:
176+
return
177+
178+
position = Position.objects.get(name='IAOC')
179+
candidate_email = 'nominee@example.com',
180+
candidate_name = 'nominee'
181+
comments = 'test nominate view'
182+
candidate_phone = '123456'
183+
184+
test_data = {'candidate_name': candidate_name,
185+
'candidate_email': candidate_email,
186+
'candidate_phone': candidate_phone,
187+
'position': position.id,
188+
'comments': comments}
189+
190+
response = self.client.post(self.nominate_url, test_data)
191+
self.assertEqual(response.status_code, 200)
192+
193+
# check objects
194+
email = Email.objects.get(address=candidate_email)
195+
Person.objects.get(name=candidate_name, address=candidate_email)
196+
nominee = Nominee.objects.get(email=email)
197+
NomineePosition.objects.get(position=position, nominee=nominee)
198+
feedback = Feedback.objects.get(position=position,
199+
nominee=nominee,
200+
type=FeedbackType.objects.get(slug='nomina'),
201+
author__person__name=COMMUNITY_USER)
202+
# to check feedback comments are saved like enrypted data
203+
self.assertNotEqual(feedback.comments, comments)
204+
205+
Nomination.objects.get(position=position,
206+
candidate_name=candidate_name,
207+
candidate_mail=candidate_email,
208+
candidate_phone=candidate_phone,
209+
nominee=nominee,
210+
comments=feedback,
211+
nominator_email="%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))
167212
self.client.logout()
168213

169214

ietf/nomcom/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ def questionnaires(request, year):
6868
@login_required
6969
def nominate(request, year):
7070
nomcom = get_nomcom_by_year(year)
71+
has_publickey = nomcom.public_key and True or False
72+
if not has_publickey:
73+
message = ('warning', "Nomcom don't have public key to ecrypt data, please contact with nomcom chair")
74+
return render_to_response('nomcom/nominate.html',
75+
{'has_publickey': has_publickey,
76+
'message': message,
77+
'nomcom': nomcom,
78+
'year': year,
79+
'selected': 'nominate'}, RequestContext(request))
80+
7181
message = None
7282
if request.method == 'POST':
7383
form = NominateForm(data=request.POST, nomcom=nomcom, user=request.user)
@@ -78,7 +88,8 @@ def nominate(request, year):
7888
form = NominateForm(nomcom=nomcom, user=request.user)
7989

8090
return render_to_response('nomcom/nominate.html',
81-
{'form': form,
91+
{'has_publickey': has_publickey,
92+
'form': form,
8293
'message': message,
8394
'nomcom': nomcom,
8495
'year': year,

ietf/templates/nomcom/nominate.html

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,34 @@
77
{% endblock %}
88

99
{% block nomcom_content %}
10-
<div class="js-info">
11-
Your browser has Javascript disabled. Please enable javascript and reload the page.
12-
<script type="text/javascript">
13-
(function ($) {
14-
$(".js-info").hide();
15-
})(jQuery);
16-
</script>
17-
</div>
1810

1911

2012
{% if message %}
2113
<div class="info-message-{{ message.0 }}">{{ message.1 }}</div>
2214
{% endif %}
2315

24-
{% if form.errors %}<div class="info-message-error">Please correct the following errors</div>{% endif %}
16+
{% if has_publickey %}
2517

26-
<form id="nominateform" action="" method="post">{% csrf_token %}
27-
{{ form }}
18+
<div class="js-info">
19+
Your browser has Javascript disabled. Please enable javascript and reload the page.
20+
<script type="text/javascript">
21+
(function ($) {
22+
$(".js-info").hide();
23+
})(jQuery);
24+
</script>
25+
</div>
2826

29-
<div class="submitrow">
30-
<input type="submit" value="Save" name="save" />
31-
</div>
3227

33-
</form>
28+
{% if form.errors %}<div class="info-message-error">Please correct the following errors</div>{% endif %}
29+
30+
<form id="nominateform" action="" method="post">{% csrf_token %}
31+
{{ form }}
32+
33+
<div class="submitrow">
34+
<input type="submit" value="Save" name="save" />
35+
</div>
36+
37+
</form>
38+
{% endif %}
3439

3540
{% endblock %}

0 commit comments

Comments
 (0)