@@ -124,10 +124,9 @@ def test_api_set_session_video_url(self):
124124 event = doc .latest_event ()
125125 self .assertEqual (event .by , recman )
126126
127-
128127 def test_person_export (self ):
129128 person = PersonFactory ()
130- url = urlreverse ('ietf.api.views.PersonExportView ' )
129+ url = urlreverse ('ietf.api.views.PersonalInformationExportView ' )
131130 login_testing_unauthorized (self , person .user .username , url )
132131 r = self .client .get (url )
133132 jsondata = r .json ()
@@ -136,6 +135,41 @@ def test_person_export(self):
136135 self .assertEqual (data ['ascii' ], person .ascii )
137136 self .assertEqual (data ['user' ]['email' ], person .user .email )
138137
138+ def test_api_v2_person_export_view (self ):
139+ url = urlreverse ('ietf.api.views.ApiV2PersonExportView' )
140+ secretariat_role = RoleFactory (group__acronym = 'secretariat' , name_id = 'secr' )
141+ secretariat = secretariat_role .person
142+ apikey = PersonalApiKey .objects .create (endpoint = url , person = secretariat )
143+
144+ # error cases
145+ r = self .client .post (url , {})
146+ self .assertContains (r , "Missing apikey parameter" , status_code = 400 )
147+
148+ badrole = RoleFactory (group__type_id = 'ietf' , name_id = 'ad' )
149+ badapikey = PersonalApiKey .objects .create (endpoint = url , person = badrole .person )
150+ badrole .person .user .last_login = timezone .now ()
151+ badrole .person .user .save ()
152+ r = self .client .post (url , {'apikey' : badapikey .hash ()})
153+ self .assertContains (r , "Restricted to role Secretariat" , status_code = 403 )
154+
155+ r = self .client .post (url , {'apikey' : apikey .hash ()})
156+ self .assertContains (r , "Too long since last regular login" , status_code = 400 )
157+ secretariat .user .last_login = timezone .now ()
158+ secretariat .user .save ()
159+
160+ r = self .client .post (url , {'apikey' : apikey .hash ()})
161+ self .assertContains (r , "No filters provided" , status_code = 400 )
162+
163+ # working case
164+ r = self .client .post (url , {'apikey' : apikey .hash (), 'email' : secretariat .email ().address , '_expand' : 'user' })
165+ self .assertEqual (r .status_code , 200 )
166+ jsondata = r .json ()
167+ data = jsondata ['person.person' ][str (secretariat .id )]
168+ self .assertEqual (data ['name' ], secretariat .name )
169+ self .assertEqual (data ['ascii' ], secretariat .ascii )
170+ self .assertEqual (data ['user' ]['email' ], secretariat .user .email )
171+
172+
139173class TastypieApiTestCase (ResourceTestCaseMixin , TestCase ):
140174 def __init__ (self , * args , ** kwargs ):
141175 self .apps = {}
0 commit comments