Skip to content

Commit 32e9692

Browse files
committed
Fixed a py2/py3 issue in sync.rfceditor.post_approved_draft(), and enhanced tests to execute the failing code (with Mock functions) instead of skipping the code.
- Legacy-Id: 17265
1 parent 293e505 commit 32e9692

6 files changed

Lines changed: 35 additions & 24 deletions

File tree

ietf/doc/tests_ballot.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#ad Copyright The IETF Trust 2013-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2013-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

55
import datetime
6+
import mock
7+
68
from pyquery import PyQuery
79

810
import debug # pyflakes:ignore
@@ -617,7 +619,11 @@ def verify_can_see(username, url):
617619
verify_can_see(username, url)
618620

619621
class ApproveBallotTests(TestCase):
620-
def test_approve_ballot(self):
622+
@mock.patch('ietf.sync.rfceditor.urlopen', autospec=True)
623+
def test_approve_ballot(self, mock_urlopen):
624+
mock_urlopen.return_value.read = lambda :'OK'
625+
mock_urlopen.return_value.getcode = lambda :200
626+
#
621627
ad = Person.objects.get(name="Areað Irector")
622628
draft = IndividualDraftFactory(ad=ad, intended_std_level_id='ps')
623629
draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="iesg-eva")) # make sure it's approvable
@@ -651,7 +657,7 @@ def test_approve_ballot(self):
651657
# approve
652658
mailbox_before = len(outbox)
653659

654-
r = self.client.post(url, dict(skiprfceditorpost="1"))
660+
r = self.client.post(url)
655661
self.assertEqual(r.status_code, 302)
656662

657663
draft = Document.objects.get(name=draft.name)

ietf/doc/tests_draft.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2011-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2011-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -8,8 +8,10 @@
88
import shutil
99
import datetime
1010
import io
11-
from pyquery import PyQuery
11+
import mock
12+
1213
from collections import Counter
14+
from pyquery import PyQuery
1315

1416
from django.urls import reverse as urlreverse
1517
from django.conf import settings
@@ -1197,7 +1199,11 @@ def test_confirm_submission(self):
11971199

11981200

11991201
class RequestPublicationTests(TestCase):
1200-
def test_request_publication(self):
1202+
@mock.patch('ietf.sync.rfceditor.urlopen', autospec=True)
1203+
def test_request_publication(self, mock_urlopen):
1204+
mock_urlopen.return_value.read = lambda :'OK'
1205+
mock_urlopen.return_value.getcode = lambda :200
1206+
#
12011207
draft = IndividualDraftFactory(stream_id='iab',group__acronym='iab',intended_std_level_id='inf',states=[('draft-stream-iab','approved')])
12021208

12031209
url = urlreverse('ietf.doc.views_draft.request_publication', kwargs=dict(name=draft.name))
@@ -1216,7 +1222,7 @@ def test_request_publication(self):
12161222
# approve
12171223
mailbox_before = len(outbox)
12181224

1219-
r = self.client.post(url, dict(subject=subject, body=body, skiprfceditorpost="1"))
1225+
r = self.client.post(url, dict(subject=subject, body=body))
12201226
self.assertEqual(r.status_code, 302)
12211227

12221228
draft = Document.objects.get(name=draft.name)

ietf/doc/views_ballot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2010-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2010-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33
# ballot management (voting, commenting, writeups, ...) for Area
44
# Directors and Secretariat
@@ -851,7 +851,7 @@ def approve_ballot(request, name):
851851
if ballot_writeup_event.pk == None:
852852
ballot_writeup_event.save()
853853

854-
if new_state.slug == "ann" and new_state.slug != prev_state.slug and not request.POST.get("skiprfceditorpost"):
854+
if new_state.slug == "ann" and new_state.slug != prev_state.slug:
855855
# start by notifying the RFC Editor
856856
import ietf.sync.rfceditor
857857
response, error = ietf.sync.rfceditor.post_approved_draft(settings.RFC_EDITOR_SYNC_NOTIFICATION_URL, doc.name)

ietf/doc/views_draft.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,15 +1282,14 @@ class PublicationForm(forms.Form):
12821282
if form.is_valid():
12831283
events = []
12841284

1285-
if not request.POST.get("skiprfceditorpost"):
1286-
# start by notifying the RFC Editor
1287-
import ietf.sync.rfceditor
1288-
response, error = ietf.sync.rfceditor.post_approved_draft(settings.RFC_EDITOR_SYNC_NOTIFICATION_URL, doc.name)
1289-
if error:
1290-
return render(request, 'doc/draft/rfceditor_post_approved_draft_failed.html',
1291-
dict(name=doc.name,
1292-
response=response,
1293-
error=error))
1285+
# start by notifying the RFC Editor
1286+
import ietf.sync.rfceditor
1287+
response, error = ietf.sync.rfceditor.post_approved_draft(settings.RFC_EDITOR_SYNC_NOTIFICATION_URL, doc.name)
1288+
if error:
1289+
return render(request, 'doc/draft/rfceditor_post_approved_draft_failed.html',
1290+
dict(name=doc.name,
1291+
response=response,
1292+
error=error))
12941293

12951294
m.subject = form.cleaned_data["subject"]
12961295
m.body = form.cleaned_data["body"]

ietf/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="xml2rfc")
3636
warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="site")
3737
warnings.filterwarnings("ignore", message="Flags not at the start of the expression", module="genshi")
38-
38+
warnings.filterwarnings("ignore", message="encodestring\(\) is a deprecated alias since 3.1, use encodebytes\(\)")
3939

4040
try:
4141
import syslog

ietf/sync/rfceditor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,10 @@ def post_approved_draft(url, name):
546546
password = settings.RFC_EDITOR_SYNC_PASSWORD
547547
request.add_header("Authorization", "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""))
548548

549-
if settings.SERVER_MODE != "production":
550-
return ("OK", "")
551-
552549
log("Posting RFC-Editor notifcation of approved draft '%s' to '%s'" % (name, url))
553550
text = error = ""
554551
try:
555-
f = urlopen(request, data=urlencode({ 'draft': name }), timeout=20)
552+
f = urlopen(request, data=smart_bytes(urlencode({ 'draft': name })), timeout=20)
556553
text = f.read()
557554
status_code = f.getcode()
558555
f.close()
@@ -567,7 +564,10 @@ def post_approved_draft(url, name):
567564
except Exception as e:
568565
# catch everything so we don't leak exceptions, convert them
569566
# into string instead
570-
log("Exception on RFC-Editor notification for draft '%s': '%s'" % (name, e))
567+
msg = "Exception on RFC-Editor notification for draft '%s': '%s'" % (name, e)
568+
log(msg)
569+
if settings.SERVER_MODE == 'test':
570+
debug.say(msg)
571571
error = six.text_type(e)
572572

573573
return text, error

0 commit comments

Comments
 (0)