1+ # -*- coding: utf-8 -*-
12import datetime
23import os
34import shutil
1819from ietf .meeting .models import Meeting
1920from ietf .message .models import Message
2021from ietf .person .models import Person , Email
22+ from ietf .person .factories import UserFactory , PersonFactory
2123from ietf .submit .models import Submission , Preapproval
2224from ietf .submit .mail import add_submission_email , process_response_email
2325from ietf .utils .mail import outbox , empty_outbox
2426from ietf .utils .test_data import make_test_data
2527from ietf .utils .test_utils import login_testing_unauthorized , unicontent , TestCase
2628
2729
28- def submission_file (name , rev , group , format , templatename ):
30+ def submission_file (name , rev , group , format , templatename , author = None ):
2931 # construct appropriate text draft
3032 f = open (os .path .join (settings .BASE_DIR , "submit" , templatename ))
3133 template = f .read ()
3234 f .close ()
3335
36+ if not author :
37+ author = PersonFactory ()
38+
3439 submission_text = template % dict (
3540 date = datetime .date .today ().strftime ("%d %B %Y" ),
3641 expiration = (datetime .date .today () + datetime .timedelta (days = 100 )).strftime ("%d %B, %Y" ),
3742 year = datetime .date .today ().strftime ("%Y" ),
3843 month = datetime .date .today ().strftime ("%B" ),
3944 name = "%s-%s" % (name , rev ),
4045 group = group or "" ,
46+ author = author .name ,
47+ initials = author .initials (),
48+ surname = author .last_name (),
49+ email = author .email ().address .lower (),
4150 )
4251
43- file = StringIO (str ( submission_text ) )
52+ file = StringIO (submission_text )
4453 file .name = "%s-%s.%s" % (name , rev , format )
4554 return file
4655
@@ -618,7 +627,10 @@ def test_edit_submission_and_force_post(self):
618627 "authors-0-email" : "person1@example.com" ,
619628 "authors-1-name" : "Person 2" ,
620629 "authors-1-email" : "person2@example.com" ,
621- "authors-prefix" : ["authors-" , "authors-0" , "authors-1" ],
630+ "authors-2-name" : "Person 3" ,
631+ "authors-2-email" : "" ,
632+
633+ "authors-prefix" : ["authors-" , "authors-0" , "authors-1" , "authors-2" ],
622634 })
623635 self .assertEqual (r .status_code , 302 )
624636
@@ -633,11 +645,13 @@ def test_edit_submission_and_force_post(self):
633645 self .assertEqual (submission .state_id , "manual" )
634646
635647 authors = submission .authors_parsed ()
636- self .assertEqual (len (authors ), 2 )
648+ self .assertEqual (len (authors ), 3 )
637649 self .assertEqual (authors [0 ]["name" ], "Person 1" )
638650 self .assertEqual (authors [0 ]["email" ], "person1@example.com" )
639651 self .assertEqual (authors [1 ]["name" ], "Person 2" )
640652 self .assertEqual (authors [1 ]["email" ], "person2@example.com" )
653+ self .assertEqual (authors [2 ]["name" ], "Person 3" )
654+ self .assertEqual (authors [2 ]["email" ], "unknown-email-Person-3" )
641655
642656 self .assertEqual (len (outbox ), mailbox_before + 1 )
643657 self .assertTrue ("Manual Post Requested" in outbox [- 1 ]["Subject" ])
@@ -873,6 +887,36 @@ def test_submit_bad_file_ps(self):
873887 self .assertIn ('Expected the PS file to have extension ".ps"' , m )
874888 self .assertIn ('Expected an PS file of type "application/postscript"' , m )
875889
890+ def test_submit_nonascii_name (self ):
891+ make_test_data ()
892+
893+ name = "draft-authorname-testing-nonascii"
894+ rev = "00"
895+ group = None
896+
897+ # get
898+ url = urlreverse ('ietf.submit.views.upload_submission' )
899+ r = self .client .get (url )
900+ self .assertEqual (r .status_code , 200 )
901+ q = PyQuery (r .content )
902+
903+ # submit
904+ #author = PersonFactory(name=u"Jörgen Nilsson".encode('latin1'))
905+ user = UserFactory (first_name = u"Jörgen" , last_name = u"Nilsson" )
906+ author = PersonFactory (user = user )
907+ files = {"txt" : submission_file (name , rev , group , "txt" , "test_submission.nonascii" , author = author ) }
908+
909+ r = self .client .post (url , files )
910+
911+ self .assertEqual (r .status_code , 302 )
912+ status_url = r ["Location" ]
913+ r = self .client .get (status_url )
914+ q = PyQuery (r .content )
915+ m = q ('p.alert-warning' ).text ()
916+
917+ self .assertIn ('The idnits check returned 1 error' , m )
918+
919+
876920class ApprovalsTestCase (TestCase ):
877921 def test_approvals (self ):
878922 make_test_data ()
0 commit comments