from colors import * import testlib import tentapp tentapp.debug = False print yellow( '-----------------------------------------------------------------------\\' ) testlib.begin('TentApp') #------------------------------------------------------------------------------------------- #--- AUTHENTICATION entityUrl = 'https://pythonclienttest.tent.is' app = tentapp.TentApp(entityUrl) testlib.eq(app.hasRegistrationKeys(), False, 'when starting, should not have registration keys') testlib.eq(app.hasPermanentKeys(), False, 'when starting, should not have permanent keys') # We use the result of getFollowers to see if we're actually authenticated or not # The resulting JSON objects will have a "groups" field if and only if the authentication is working. aFollower = app.getFollowers()[0] testlib.eq('groups' in aFollower, False, 'non-authenticated GET /followers should not have "groups"') # Generators with no authentication try: generator = app.generateFollowers()
def debugJson(s=''): print magenta(pprint.pformat(s)) print yellow( '-----------------------------------------------------------------------\\' ) # Turn on or off the verbose debug output from tentapp tentapp.debug = False # "entity" is the Tent version of a username. It's a full URL. # For tent.is it should be "https://yourname.tent.is" # Instantiating this class will perform discovery on the entity URL entityUrl = 'https://pythonclienttest.tent.is' app = tentapp.TentApp(entityUrl) # Authenticate # You can use your own database here instead of KeyStore if you want. # KeyStore just saves the keys to a local JSON file. keyStore = tentapp.KeyStore('keystore.js') keys = keyStore.getKey(entityUrl) if keys: # Reuse auth keys from a previous run app.authenticate(keys) else: # Get auth keys for the first time # and save them into the keyStore keys = app.authenticate() keyStore.addKey(entityUrl, keys)