@@ -403,31 +403,44 @@ def test_as_swat():
403403 HOST = 'example.com'
404404 USERNAME = 'username'
405405 PASSWORD = 'password'
406+ AUTH_TOKEN = 'token'
406407
407408 with mock .patch ('sasctl.core.Session.get_auth' ):
408409 with Session (HOST , USERNAME , PASSWORD ) as s :
409410 with mock .patch ('swat.CAS' ) as CAS :
410- # Verify default parameters were passed
411- _ = s .as_swat ()
412- CAS .assert_called_with (
413- hostname = 'https://%s/cas-shared-default-http/' % HOST ,
414- username = USERNAME ,
415- password = PASSWORD ,
416- )
417-
418- # Verify connection to a non-default CAS instance
419- SERVER_NAME = 'my-cas-server'
420- _ = s .as_swat (SERVER_NAME )
421- CAS .assert_called_with (
422- hostname = 'https://%s/%s-http/' % (HOST , SERVER_NAME ),
423- username = USERNAME ,
424- password = PASSWORD ,
425- )
426411
427- # Verify default parameters can be overridden
428- _ = s .as_swat (username = 'testuser' , password = None )
429- CAS .assert_called_with (
430- hostname = 'https://%s/cas-shared-default-http/' % HOST ,
431- username = 'testuser' ,
432- password = None ,
433- )
412+ # Verify default username/password parameters were passed.
413+ with mock .patch ('swat.__version__' , '1.6.1' ):
414+ _ = s .as_swat ()
415+ CAS .assert_called_with (
416+ hostname = 'https://%s/cas-shared-default-http/' % HOST ,
417+ username = USERNAME ,
418+ password = PASSWORD ,
419+ )
420+
421+ # Verify auth token is passed with new SWAT versions
422+ with mock .patch ('swat.__version__' , '1.9' ):
423+ s .auth .access_token = AUTH_TOKEN
424+ _ = s .as_swat ()
425+ CAS .assert_called_with (
426+ hostname = 'https://%s/cas-shared-default-http/' % HOST ,
427+ username = None ,
428+ password = AUTH_TOKEN ,
429+ )
430+
431+ # Verify connection to a non-default CAS instance
432+ SERVER_NAME = 'my-cas-server'
433+ _ = s .as_swat (SERVER_NAME )
434+ CAS .assert_called_with (
435+ hostname = 'https://%s/%s-http/' % (HOST , SERVER_NAME ),
436+ username = None ,
437+ password = AUTH_TOKEN ,
438+ )
439+
440+ # Verify default parameters can be overridden
441+ _ = s .as_swat (username = 'testuser' , password = None )
442+ CAS .assert_called_with (
443+ hostname = 'https://%s/cas-shared-default-http/' % HOST ,
444+ username = 'testuser' ,
445+ password = None ,
446+ )
0 commit comments