1
1
"""IRWS service interface"""
2
2
import re
3
3
import copy
4
- from six .moves .urllib .parse import quote_plus
4
+ from six .moves .urllib .parse import quote
5
5
import json
6
6
from resttools .dao import IRWS_DAO
7
7
from resttools .models .irws import UWNetId
@@ -43,7 +43,7 @@ def _get_code_from_error(self, message):
43
43
44
44
def _clean (self , arg ):
45
45
if arg is not None :
46
- arg = quote_plus (arg )
46
+ arg = quote (arg )
47
47
return arg
48
48
49
49
# v2 - no change
@@ -363,7 +363,7 @@ def get_generic_person(self, uri):
363
363
The uris come in from values in irws.Person.identifiers.
364
364
Raises DataFailureExeption on error.
365
365
"""
366
- uri = quote_plus (uri , '/' )
366
+ uri = quote (uri , '/' )
367
367
368
368
url = '/%s/v2%s' % (self ._service_name , uri )
369
369
response = self .dao .getURL (url , {'Accept' : 'application/json' })
@@ -470,7 +470,7 @@ def verify_sc_pin(self, netid, pin):
470
470
response = self .dao .getURL (url , {"Accept" : "application/json" })
471
471
if response .status != 200 :
472
472
# the pin was good. we return OK, but note the error
473
- logging . warn ('Delete SC pin failed: %d' % response .status )
473
+ logger . error ('Delete SC pin failed: %d' % response .status )
474
474
return 200
475
475
476
476
if (response .status == 400 or response .status == 404 ):
@@ -497,25 +497,20 @@ def get_qna(self, netid):
497
497
def get_verify_qna (self , netid , answers ):
498
498
"""
499
499
Verifies that all answers are present and that all are correct.
500
- answers: dict ('ordinal': 'answer')
501
- """
502
- netid = self ._clean (netid )
503
-
504
- q_list = self .get_qna (netid )
505
- for q in q_list :
506
- if q .ordinal not in answers :
507
- logging .debug ('q %s, no answer' % q .ordinal )
508
- return False
509
- ans = re .sub (r'\W+' , '' , answers [q .ordinal ])
510
- url = "/%s/v2/qna/%s/%s/check?ans=%s" % (self ._service_name , q .ordinal , netid , quote_plus (ans ))
500
+ answers: ordered list of answers
501
+ """
502
+ questions = self .get_qna (netid )
503
+ if len (questions ) != len (answers ):
504
+ return False
505
+ for index , answer in enumerate (answers , start = 1 ):
506
+ answer = re .sub (r'\W+' , '' , answer )
507
+ url = "/%s/v2/qna/%s/%s/check?ans=%s" % (self ._service_name , index , quote (netid ), quote (answer ))
511
508
response = self .dao .getURL (url , {"Accept" : "application/json" })
512
- if response .status == 404 :
513
- logging .debug ('q %s, wrong answer' % q . ordinal )
509
+ if response .status in ( 400 , 404 ) :
510
+ logger .debug ('qna wrong answer #{}, status = {}' . format ( index , response . status ) )
514
511
return False
515
512
if response .status != 200 :
516
- logging .debug ('q %s, error return: %d' % (q .ordinal , response .status ))
517
- return False
518
- logging .debug ('q %s, correct answer' % q .ordinal )
513
+ raise DataFailureException (url , response .status , response .data )
519
514
return True
520
515
521
516
def verify_person_attribute (self , netid , attribute , value ):
0 commit comments