@@ -2682,3 +2682,55 @@ def test_rfc_with_broken_history(self):
26822682 # tricky draft names
26832683 self .do_rfc_with_broken_history_test (draft_name = 'draft-gizmo-01' )
26842684 self .do_rfc_with_broken_history_test (draft_name = 'draft-oh-boy-what-a-draft-02-03' )
2685+
2686+ class RawIdTests (TestCase ):
2687+
2688+ def __init__ (self , * args , ** kwargs ):
2689+ self .view = "ietf.doc.views_doc.document_raw_id"
2690+ self .mimetypes = {'txt' :'text/plain' ,'html' :'text/html' ,'xml' :'application/xml' }
2691+ super (self .__class__ , self ).__init__ (* args , ** kwargs )
2692+
2693+ def should_succeed (self , argdict ):
2694+ url = urlreverse (self .view , kwargs = argdict )
2695+ r = self .client .get (url )
2696+ self .assertEqual (r .status_code ,200 )
2697+ self .assertEqual (r .get ('Content-Type' ),f"{ self .mimetypes [argdict .get ('ext' ,'txt' )]} ;charset=utf-8" )
2698+
2699+ def should_404 (self , argdict ):
2700+ url = urlreverse (self .view , kwargs = argdict )
2701+ r = self .client .get (url )
2702+ self .assertEqual (r .status_code , 404 )
2703+
2704+ def test_raw_id (self ):
2705+ draft = WgDraftFactory (create_revisions = range (0 ,2 ))
2706+
2707+ dir = settings .INTERNET_ALL_DRAFTS_ARCHIVE_DIR
2708+ for r in range (0 ,2 ):
2709+ rev = f'{ r :02d} '
2710+ (Path (dir ) / f'{ draft .name } -{ rev } .txt' ).touch ()
2711+ if r == 1 :
2712+ (Path (dir ) / f'{ draft .name } -{ rev } .html' ).touch ()
2713+ (Path (dir ) / f'{ draft .name } -{ rev } .xml' ).touch ()
2714+
2715+ self .should_succeed (dict (name = draft .name ))
2716+ for ext in ('txt' , 'html' , 'xml' ):
2717+ self .should_succeed (dict (name = draft .name , ext = ext ))
2718+ self .should_succeed (dict (name = draft .name , rev = '01' , ext = ext ))
2719+ self .should_404 (dict (name = draft .name , ext = 'pdf' ))
2720+
2721+ self .should_succeed (dict (name = draft .name , rev = '00' ))
2722+ self .should_succeed (dict (name = draft .name , rev = '00' ,ext = 'txt' ))
2723+ self .should_404 (dict (name = draft .name , rev = '00' ,ext = 'html' ))
2724+
2725+ def test_raw_id_rfc (self ):
2726+ rfc = WgRfcFactory ()
2727+ dir = settings .INTERNET_ALL_DRAFTS_ARCHIVE_DIR
2728+ (Path (dir ) / f'{ rfc .name } -{ rfc .rev } .txt' ).touch ()
2729+ self .should_succeed (dict (name = rfc .name ))
2730+ self .should_404 (dict (name = rfc .canonical_name ()))
2731+
2732+ def test_non_draft (self ):
2733+ charter = CharterFactory ()
2734+ self .should_404 (dict (name = charter .name ))
2735+
2736+
0 commit comments