def test_removeAssociation(self): # create and store some associations associations = [] for i in range(3): assoc = Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()), lifetime=3600, assoc_type='HMAC-SHA1') associations.append(assoc) NDBOpenIDStore.storeAssociation('server_url', assoc) # remove existing association removed = NDBOpenIDStore.removeAssociation('server_url', 'handle-1') # check whether the method returned True assert removed is True # check whether there is one less association in the datastore assert NDBOpenIDStore.query().count() == 2 # check whether the right association was deleted assert NDBOpenIDStore.getAssociation('server_url', 'handle-1') is None # check whether the remaining are there assert NDBOpenIDStore.getAssociation('server_url', 'handle-0') == associations[0] assert NDBOpenIDStore.getAssociation('server_url', 'handle-2') == associations[2]
def test_removeAssociation(self): # create and store some associations associations = [] for i in range(3): assoc = Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()), lifetime=3600, assoc_type='HMAC-SHA1') associations.append(assoc) NDBOpenIDStore.storeAssociation('server_url', assoc) # remove existing association removed = NDBOpenIDStore.removeAssociation('server_url', 'handle-1') # check whether the method returned True assert removed is True # check whether there is one less association in the datastore assert NDBOpenIDStore.query().count() == 2 # check whether the right association was deleted assert NDBOpenIDStore.getAssociation('server_url', 'handle-1') is None # check whether the remaining are there assert NDBOpenIDStore.getAssociation('server_url', 'handle-0') == associations[0] assert NDBOpenIDStore.getAssociation('server_url', 'handle-2') == associations[2]
def test_getAssociation(self): # prepare associations for "url_a" url_a_associations = [] # add some valid associations with ascending issue times and descending expiration # so the most recently issued is url_b_associations[4] # and the longest valid is url_b_associations[0] url_a_associations += [ Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) + i, lifetime=3600 - i * 10, assoc_type='HMAC-SHA1') for i in range(5) ] # add some expired associations url_a_associations += [ Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) - 3600, lifetime=1, assoc_type='HMAC-SHA1') for i in range(5, 10) ] # store them for assoc in url_a_associations: NDBOpenIDStore.storeAssociation('url_a', assoc) # prepare associations for "url_b" url_b_associations = [] # add some valid associations with ascending issue times and descending expiration # so the most recently issued is url_b_associations[4] # and the longest valid is url_b_associations[0] url_b_associations += [ Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) + i, lifetime=3600 - i * 10, assoc_type='HMAC-SHA1') for i in range(5) ] # add some expired associations url_b_associations += [ Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) - 3600, lifetime=1, assoc_type='HMAC-SHA1') for i in range(5, 10) ] # store them under "url_a" for assoc in url_b_associations: NDBOpenIDStore.storeAssociation('url_b', assoc) # check whether they are all there assert len(url_a_associations + url_b_associations) == NDBOpenIDStore.query().count() # call the tested method # test for "url_a" # get a valid association with url and handle association = NDBOpenIDStore.getAssociation('url_a', 'handle-3') assert association == url_a_associations[3] # get a valid association with url only # should return the most recent association association = NDBOpenIDStore.getAssociation('url_a') assert association == url_a_associations[4] # test for "url_b" # get a valid association with url and handle association = NDBOpenIDStore.getAssociation('url_b', 'handle-2') assert association == url_b_associations[2] # get a valid association with url only # should return the most recent association association = NDBOpenIDStore.getAssociation('url_b') assert association == url_b_associations[4] # test for non existent url association = NDBOpenIDStore.getAssociation('non_existent_url') assert association is None
def test_getAssociation(self): # prepare associations for "url_a" url_a_associations = [] # add some valid associations with ascending issue times and descending expiration # so the most recently issued is url_b_associations[4] # and the longest valid is url_b_associations[0] url_a_associations += [Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) + i, lifetime=3600 - i * 10, assoc_type='HMAC-SHA1') for i in range(5)] # add some expired associations url_a_associations += [Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) - 3600, lifetime=1, assoc_type='HMAC-SHA1') for i in range(5, 10)] # store them for assoc in url_a_associations: NDBOpenIDStore.storeAssociation('url_a', assoc) # prepare associations for "url_b" url_b_associations = [] # add some valid associations with ascending issue times and descending expiration # so the most recently issued is url_b_associations[4] # and the longest valid is url_b_associations[0] url_b_associations += [Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) + i, lifetime=3600 - i * 10, assoc_type='HMAC-SHA1') for i in range(5)] # add some expired associations url_b_associations += [Association(handle='handle-{}'.format(i), secret='secret', issued=int(time.time()) - 3600, lifetime=1, assoc_type='HMAC-SHA1') for i in range(5, 10)] # store them under "url_a" for assoc in url_b_associations: NDBOpenIDStore.storeAssociation('url_b', assoc) # check whether they are all there assert len(url_a_associations + url_b_associations) == NDBOpenIDStore.query().count() # call the tested method # test for "url_a" # get a valid association with url and handle association = NDBOpenIDStore.getAssociation('url_a', 'handle-3') assert association == url_a_associations[3] # get a valid association with url only # should return the most recent association association = NDBOpenIDStore.getAssociation('url_a') assert association == url_a_associations[4] # test for "url_b" # get a valid association with url and handle association = NDBOpenIDStore.getAssociation('url_b', 'handle-2') assert association == url_b_associations[2] # get a valid association with url only # should return the most recent association association = NDBOpenIDStore.getAssociation('url_b') assert association == url_b_associations[4] # test for non existent url association = NDBOpenIDStore.getAssociation('non_existent_url') assert association is None