fix: avoid needlessly blocking import of session minutes (#3761)
Fixes #3558
This commit is contained in:
parent
fb41207227
commit
300f717c3d
ietf/meeting
|
@ -6109,17 +6109,47 @@ class ImportNotesTests(TestCase):
|
|||
kwargs={'num': self.meeting.number, 'session_id': self.session.pk})
|
||||
|
||||
self.client.login(username='secretary', password='secretary+password')
|
||||
r = self.client.post(url, {'markdown_text': 'original markdown text'}) # create a rev
|
||||
with requests_mock.Mocker() as mock:
|
||||
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/download', text='original markdown text')
|
||||
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/info',
|
||||
text=json.dumps({"title": "title", "updatetime": "2021-12-02T11:22:33z"}))
|
||||
# Create a revision. Run the original text through the preprocessing done when importing
|
||||
# from the notes site.
|
||||
r = self.client.get(url) # let GET do its preprocessing
|
||||
q = PyQuery(r.content)
|
||||
r = self.client.post(url, {'markdown_text': q('input[name="markdown_text"]').attr['value']})
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.client.get(url) # try to import the same text
|
||||
self.assertContains(r, "This document is identical", status_code=200)
|
||||
q = PyQuery(r.content)
|
||||
self.assertEqual(len(q('button:disabled[type="submit"]')), 1)
|
||||
self.assertEqual(len(q('button:enabled[type="submit"]')), 0)
|
||||
|
||||
def test_allows_import_on_existing_bad_unicode(self):
|
||||
"""Should not be able to import text identical to the current revision"""
|
||||
url = urlreverse('ietf.meeting.views.import_session_minutes',
|
||||
kwargs={'num': self.meeting.number, 'session_id': self.session.pk})
|
||||
|
||||
self.client.login(username='secretary', password='secretary+password')
|
||||
r = self.client.post(url, {'markdown_text': 'replaced below'}) # create a rev
|
||||
with open(
|
||||
self.session.sessionpresentation_set.filter(document__type="minutes").first().document.get_file_name(),
|
||||
'wb'
|
||||
) as f:
|
||||
# Replace existing content with an invalid Unicode byte string. The particular invalid
|
||||
# values here are accented characters in the MacRoman charset (see ticket #3756).
|
||||
f.write(b'invalid \x8e unicode \x99\n')
|
||||
self.assertEqual(r.status_code, 302)
|
||||
with requests_mock.Mocker() as mock:
|
||||
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/download', text='original markdown text')
|
||||
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/info',
|
||||
text=json.dumps({"title": "title", "updatetime": "2021-12-02T11:22:33z"}))
|
||||
r = self.client.get(url) # try to import the same text
|
||||
self.assertContains(r, "This document is identical", status_code=200)
|
||||
self.assertNotContains(r, "This document is identical", status_code=200)
|
||||
q = PyQuery(r.content)
|
||||
self.assertEqual(len(q('button:disabled[type="submit"]')), 1)
|
||||
self.assertEqual(len(q('button:not(:disabled)[type="submit"]')), 0)
|
||||
self.assertEqual(len(q('button:enabled[type="submit"]')), 1)
|
||||
self.assertEqual(len(q('button:disabled[type="submit"]')), 0)
|
||||
|
||||
def test_handles_missing_previous_revision_file(self):
|
||||
"""Should still allow import if the file for the previous revision is missing"""
|
||||
|
|
|
@ -4169,11 +4169,11 @@ def import_session_minutes(request, session_id, num):
|
|||
if current_minutes:
|
||||
try:
|
||||
with open(current_minutes.get_file_name()) as f:
|
||||
if import_contents == Note.preprocess_source(f.read()):
|
||||
if import_contents == f.read():
|
||||
contents_changed = False
|
||||
messages.warning(request, 'This document is identical to the current revision, no need to import.')
|
||||
except FileNotFoundError:
|
||||
pass # allow import if the file is missing
|
||||
except Exception:
|
||||
pass # Do not let a failure here prevent minutes from being updated.
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
|
Loading…
Reference in a new issue