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
This commit is contained in:
Henrik Levkowetz 2020-01-28 22:37:50 +00:00
parent 293e505bbb
commit 32e9692f54
6 changed files with 35 additions and 24 deletions

View file

@ -1,8 +1,10 @@
#ad Copyright The IETF Trust 2013-2019, All Rights Reserved
# Copyright The IETF Trust 2013-2020, All Rights Reserved
# -*- coding: utf-8 -*-
import datetime
import mock
from pyquery import PyQuery
import debug # pyflakes:ignore
@ -617,7 +619,11 @@ class BallotWriteupsTests(TestCase):
verify_can_see(username, url)
class ApproveBallotTests(TestCase):
def test_approve_ballot(self):
@mock.patch('ietf.sync.rfceditor.urlopen', autospec=True)
def test_approve_ballot(self, mock_urlopen):
mock_urlopen.return_value.read = lambda :'OK'
mock_urlopen.return_value.getcode = lambda :200
#
ad = Person.objects.get(name="Areað Irector")
draft = IndividualDraftFactory(ad=ad, intended_std_level_id='ps')
draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="iesg-eva")) # make sure it's approvable
@ -651,7 +657,7 @@ class ApproveBallotTests(TestCase):
# approve
mailbox_before = len(outbox)
r = self.client.post(url, dict(skiprfceditorpost="1"))
r = self.client.post(url)
self.assertEqual(r.status_code, 302)
draft = Document.objects.get(name=draft.name)

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2011-2019, All Rights Reserved
# Copyright The IETF Trust 2011-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -8,8 +8,10 @@ import os
import shutil
import datetime
import io
from pyquery import PyQuery
import mock
from collections import Counter
from pyquery import PyQuery
from django.urls import reverse as urlreverse
from django.conf import settings
@ -1197,7 +1199,11 @@ class SubmitToIesgTests(TestCase):
class RequestPublicationTests(TestCase):
def test_request_publication(self):
@mock.patch('ietf.sync.rfceditor.urlopen', autospec=True)
def test_request_publication(self, mock_urlopen):
mock_urlopen.return_value.read = lambda :'OK'
mock_urlopen.return_value.getcode = lambda :200
#
draft = IndividualDraftFactory(stream_id='iab',group__acronym='iab',intended_std_level_id='inf',states=[('draft-stream-iab','approved')])
url = urlreverse('ietf.doc.views_draft.request_publication', kwargs=dict(name=draft.name))
@ -1216,7 +1222,7 @@ class RequestPublicationTests(TestCase):
# approve
mailbox_before = len(outbox)
r = self.client.post(url, dict(subject=subject, body=body, skiprfceditorpost="1"))
r = self.client.post(url, dict(subject=subject, body=body))
self.assertEqual(r.status_code, 302)
draft = Document.objects.get(name=draft.name)

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2010-2019, All Rights Reserved
# Copyright The IETF Trust 2010-2020, All Rights Reserved
# -*- coding: utf-8 -*-
# ballot management (voting, commenting, writeups, ...) for Area
# Directors and Secretariat
@ -851,7 +851,7 @@ def approve_ballot(request, name):
if ballot_writeup_event.pk == None:
ballot_writeup_event.save()
if new_state.slug == "ann" and new_state.slug != prev_state.slug and not request.POST.get("skiprfceditorpost"):
if new_state.slug == "ann" and new_state.slug != prev_state.slug:
# start by notifying the RFC Editor
import ietf.sync.rfceditor
response, error = ietf.sync.rfceditor.post_approved_draft(settings.RFC_EDITOR_SYNC_NOTIFICATION_URL, doc.name)

View file

@ -1282,15 +1282,14 @@ def request_publication(request, name):
if form.is_valid():
events = []
if not request.POST.get("skiprfceditorpost"):
# start by notifying the RFC Editor
import ietf.sync.rfceditor
response, error = ietf.sync.rfceditor.post_approved_draft(settings.RFC_EDITOR_SYNC_NOTIFICATION_URL, doc.name)
if error:
return render(request, 'doc/draft/rfceditor_post_approved_draft_failed.html',
dict(name=doc.name,
response=response,
error=error))
# start by notifying the RFC Editor
import ietf.sync.rfceditor
response, error = ietf.sync.rfceditor.post_approved_draft(settings.RFC_EDITOR_SYNC_NOTIFICATION_URL, doc.name)
if error:
return render(request, 'doc/draft/rfceditor_post_approved_draft_failed.html',
dict(name=doc.name,
response=response,
error=error))
m.subject = form.cleaned_data["subject"]
m.body = form.cleaned_data["body"]

View file

@ -35,7 +35,7 @@ warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="docu
warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="xml2rfc")
warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="site")
warnings.filterwarnings("ignore", message="Flags not at the start of the expression", module="genshi")
warnings.filterwarnings("ignore", message="encodestring\(\) is a deprecated alias since 3.1, use encodebytes\(\)")
try:
import syslog

View file

@ -546,13 +546,10 @@ def post_approved_draft(url, name):
password = settings.RFC_EDITOR_SYNC_PASSWORD
request.add_header("Authorization", "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""))
if settings.SERVER_MODE != "production":
return ("OK", "")
log("Posting RFC-Editor notifcation of approved draft '%s' to '%s'" % (name, url))
text = error = ""
try:
f = urlopen(request, data=urlencode({ 'draft': name }), timeout=20)
f = urlopen(request, data=smart_bytes(urlencode({ 'draft': name })), timeout=20)
text = f.read()
status_code = f.getcode()
f.close()
@ -567,7 +564,10 @@ def post_approved_draft(url, name):
except Exception as e:
# catch everything so we don't leak exceptions, convert them
# into string instead
log("Exception on RFC-Editor notification for draft '%s': '%s'" % (name, e))
msg = "Exception on RFC-Editor notification for draft '%s': '%s'" % (name, e)
log(msg)
if settings.SERVER_MODE == 'test':
debug.say(msg)
error = six.text_type(e)
return text, error