# -*- coding: utf-8 -*-

"""
This program invoke the Agyo webservice to test it is reachable and the local environment is functional
The result of the script is the printing of the status code witch should be 200
"""

from requests import Session
from zeep import Client
from zeep.transports import Transport
import hashlib

url = 'https://soap-b2b-auth-service-test.azurewebsites.net/AuthApi_v1/AuthApi.ws?wsdl'
userid = "761dbf24-3e2e-44d5-b8bf-7ad2e9e750ed"
secret = "0b14e493-52c9-4be9-b90d-31476559c10c"

session = Session()
session.verify = False
transport = Transport(session=session)

client = Client(url, transport=transport)

nonce = client.service.getNonce(id=userid)
print "nonce:"+nonce

digest = hashlib.sha256(hashlib.sha256(userid + secret).hexdigest() + nonce).hexdigest()
print "digest:"+digest

token = client.service.verifyDigest(id=userid, digest=digest)
print "token:"+token

with client.settings(raw_response=True):
    result = client.service.verifyToken(id=userid, token=token)
    print "result:" + str(result.status_code)

print "Se il risultato e' 200 tutto OK!"
