88import datetime
99import mock
1010import quopri
11+ import requests
1112
1213from dataclasses import dataclass
1314
1819
1920import debug # pyflakes:ignore
2021
21- from ietf .doc .factories import WgDraftFactory , RfcFactory
22+ from ietf .doc .factories import WgDraftFactory , RfcFactory , DocumentAuthorFactory
2223from ietf .doc .models import Document , DocEvent , DeletedEvent , DocTagName , RelatedDocument , State , StateDocEvent
2324from ietf .doc .utils import add_state_change_event
2425from ietf .group .factories import GroupFactory
@@ -238,6 +239,7 @@ def test_rfc_index(self):
238239 external_url = "http://my-external-url.example.com" ,
239240 note = "this is a note" ,
240241 )
242+ DocumentAuthorFactory .create_batch (2 , document = draft_doc )
241243 draft_doc .action_holders .add (draft_doc .ad ) # not normally set, but add to be sure it's cleared
242244
243245 RfcFactory (rfc_number = 123 )
@@ -381,6 +383,7 @@ def test_rfc_index(self):
381383
382384 rfc_doc = Document .objects .filter (rfc_number = 1234 , type_id = "rfc" ).first ()
383385 self .assertIsNotNone (rfc_doc , "RFC document should have been created" )
386+ self .assertEqual (rfc_doc .authors (), draft_doc .authors ())
384387 rfc_events = rfc_doc .docevent_set .all ()
385388 self .assertEqual (len (rfc_events ), 8 )
386389 expected_events = [
@@ -715,11 +718,14 @@ def json(self):
715718 errata_response = MockResponse (
716719 text = "these are the errata" , json_length = rfceditor .MIN_ERRATA_RESULTS
717720 )
718-
721+ rfc = RfcFactory ()
722+
719723 # Test with full_index = False
720724 requests_get_mock .side_effect = (index_response , errata_response ) # will step through these
721725 parse_index_mock .return_value = MockIndexData (length = rfceditor .MIN_INDEX_RESULTS )
722- update_docs_mock .return_value = [] # not tested
726+ update_docs_mock .return_value = (
727+ (rfc .rfc_number , ("something changed" ,), rfc , False ),
728+ )
723729
724730 tasks .rfc_editor_index_update_task (full_index = False )
725731
@@ -741,9 +747,10 @@ def json(self):
741747 self .assertIsNotNone (update_docs_kwargs ["skip_older_than_date" ])
742748
743749 # Test again with full_index = True
750+ requests_get_mock .reset_mock ()
751+ parse_index_mock .reset_mock ()
752+ update_docs_mock .reset_mock ()
744753 requests_get_mock .side_effect = (index_response , errata_response ) # will step through these
745- parse_index_mock .return_value = MockIndexData (length = rfceditor .MIN_INDEX_RESULTS )
746- update_docs_mock .return_value = [] # not tested
747754 tasks .rfc_editor_index_update_task (full_index = True )
748755
749756 # Check parse_index() call
@@ -762,3 +769,38 @@ def json(self):
762769 update_docs_args , (parse_index_mock .return_value , errata_response .json ())
763770 )
764771 self .assertIsNone (update_docs_kwargs ["skip_older_than_date" ])
772+
773+ # Test error handling
774+ requests_get_mock .reset_mock ()
775+ parse_index_mock .reset_mock ()
776+ update_docs_mock .reset_mock ()
777+ requests_get_mock .side_effect = requests .Timeout # timeout on every get()
778+ tasks .rfc_editor_index_update_task (full_index = False )
779+ self .assertFalse (parse_index_mock .called )
780+ self .assertFalse (update_docs_mock .called )
781+
782+ requests_get_mock .reset_mock ()
783+ parse_index_mock .reset_mock ()
784+ update_docs_mock .reset_mock ()
785+ requests_get_mock .side_effect = [index_response , requests .Timeout ] # timeout second get()
786+ tasks .rfc_editor_index_update_task (full_index = False )
787+ self .assertFalse (update_docs_mock .called )
788+
789+ requests_get_mock .reset_mock ()
790+ parse_index_mock .reset_mock ()
791+ update_docs_mock .reset_mock ()
792+ requests_get_mock .side_effect = [index_response , errata_response ]
793+ # feed in an index that is too short
794+ parse_index_mock .return_value = MockIndexData (length = rfceditor .MIN_INDEX_RESULTS - 1 )
795+ tasks .rfc_editor_index_update_task (full_index = False )
796+ self .assertTrue (parse_index_mock .called )
797+ self .assertFalse (update_docs_mock .called )
798+
799+ requests_get_mock .reset_mock ()
800+ parse_index_mock .reset_mock ()
801+ update_docs_mock .reset_mock ()
802+ requests_get_mock .side_effect = [index_response , errata_response ]
803+ errata_response .json_length = rfceditor .MIN_ERRATA_RESULTS - 1 # too short
804+ parse_index_mock .return_value = MockIndexData (length = rfceditor .MIN_INDEX_RESULTS )
805+ tasks .rfc_editor_index_update_task (full_index = False )
806+ self .assertFalse (update_docs_mock .called )
0 commit comments