|
33 | 33 | from ietf.doc.factories import ( DocumentFactory, DocEventFactory, CharterFactory, |
34 | 34 | ConflictReviewFactory, WgDraftFactory, IndividualDraftFactory, WgRfcFactory, |
35 | 35 | IndividualRfcFactory, StateDocEventFactory, BallotPositionDocEventFactory, |
36 | | - BallotDocEventFactory, DocumentAuthorFactory ) |
| 36 | + BallotDocEventFactory, DocumentAuthorFactory, NewRevisionDocEventFactory) |
37 | 37 | from ietf.doc.fields import SearchableDocumentsField |
38 | 38 | from ietf.doc.utils import create_ballot_if_not_open, uppercase_std_abbreviated_name |
39 | 39 | from ietf.group.models import Group |
40 | 40 | from ietf.group.factories import GroupFactory, RoleFactory |
41 | 41 | from ietf.ipr.factories import HolderIprDisclosureFactory |
42 | 42 | from ietf.meeting.models import Meeting, Session, SessionPresentation, SchedulingEvent |
43 | | -from ietf.meeting.factories import MeetingFactory, SessionFactory |
| 43 | +from ietf.meeting.factories import MeetingFactory, SessionFactory, SessionPresentationFactory |
| 44 | + |
44 | 45 | from ietf.name.models import SessionStatusName, BallotPositionName |
45 | 46 | from ietf.person.models import Person |
46 | 47 | from ietf.person.factories import PersonFactory, EmailFactory |
@@ -2314,3 +2315,65 @@ class _TestForm(Form): |
2314 | 2315 | dict(id=doc.pk, text=escape(uppercase_std_abbreviated_name(doc.name))), |
2315 | 2316 | decoded[str(doc.pk)], |
2316 | 2317 | ) |
| 2318 | + |
| 2319 | +class MaterialsTests(TestCase): |
| 2320 | + |
| 2321 | + def setUp(self): |
| 2322 | + self.id_dir = self.tempdir('id') |
| 2323 | + self.saved_agenda_path = settings.AGENDA_PATH |
| 2324 | + settings.AGENDA_PATH = self.id_dir |
| 2325 | + |
| 2326 | + meeting_number='111' |
| 2327 | + meeting_dir = os.path.join(f'{settings.AGENDA_PATH}',f'{meeting_number}') |
| 2328 | + os.mkdir(meeting_dir) |
| 2329 | + agenda_dir = os.path.join(meeting_dir,'agenda') |
| 2330 | + os.mkdir(agenda_dir) |
| 2331 | + |
| 2332 | + group_acronym='bogons' |
| 2333 | + |
| 2334 | + # This is too much work - the factory should |
| 2335 | + # * build the DocumentHistory correctly |
| 2336 | + # * maybe do something by default with uploaded_filename |
| 2337 | + # and there should be a more usable unit to save bits to disk (handle_file_upload isn't quite right) that tests can leverage |
| 2338 | + try: |
| 2339 | + uploaded_filename_00 = f'agenda-{meeting_number}-{group_acronym}-00.txt' |
| 2340 | + uploaded_filename_01 = f'agenda-{meeting_number}-{group_acronym}-01.md' |
| 2341 | + f = io.open(os.path.join(agenda_dir, uploaded_filename_00), 'w') |
| 2342 | + f.write('This is some unremarkable text') |
| 2343 | + f.close() |
| 2344 | + f = io.open(os.path.join(agenda_dir, uploaded_filename_01), 'w') |
| 2345 | + f.write('This links to [an unusual place](https://unusual.example).') |
| 2346 | + f.close() |
| 2347 | + |
| 2348 | + self.doc = DocumentFactory(type_id='agenda',rev='00',group__acronym=group_acronym, newrevisiondocevent=None, name=f'agenda-{meeting_number}-{group_acronym}', uploaded_filename=uploaded_filename_00) |
| 2349 | + e = NewRevisionDocEventFactory(doc=self.doc,rev='00') |
| 2350 | + self.doc.save_with_history([e]) |
| 2351 | + self.doc.rev = '01' |
| 2352 | + self.doc.uploaded_filename = uploaded_filename_01 |
| 2353 | + e = NewRevisionDocEventFactory(doc=self.doc, rev='01') |
| 2354 | + self.doc.save_with_history([e]) |
| 2355 | + |
| 2356 | + # This is necessary for the view to be able to find the document |
| 2357 | + # which hints that the view has an issue : if a materials document is taken out of all SessionPresentations, it is no longer accessable by this view |
| 2358 | + SessionPresentationFactory(session__meeting__number=meeting_number, session__group=self.doc.group, document=self.doc) |
| 2359 | + |
| 2360 | + except: |
| 2361 | + shutil.rmtree(self.id_dir) |
| 2362 | + raise |
| 2363 | + |
| 2364 | + def tearDown(self): |
| 2365 | + settings.AGENDA_PATH = self.saved_agenda_path |
| 2366 | + shutil.rmtree(self.id_dir) |
| 2367 | + |
| 2368 | + def test_markdown_and_text(self): |
| 2369 | + url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=self.doc.name,rev='00')) |
| 2370 | + r = self.client.get(url) |
| 2371 | + self.assertEqual(r.status_code,200) |
| 2372 | + q = PyQuery(r.content) |
| 2373 | + self.assertTrue(q('#materials-content > pre')) |
| 2374 | + |
| 2375 | + url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=self.doc.name,rev='01')) |
| 2376 | + r = self.client.get(url) |
| 2377 | + self.assertEqual(r.status_code,200) |
| 2378 | + q = PyQuery(r.content) |
| 2379 | + self.assertEqual(q('#materials-content .panel-body a').attr['href'],'https://unusual.example') |
0 commit comments