def test_positive_delete_tokens_check_keys(self): """ Check the response contains correct keys. """ r = self.res.delete('/tokens/'+self.token['access_token'], headers=utils.headers) logging.info("Return response is '%s'" % r) # convert string to dictionary rd = ast.literal_eval(r) logging.info("Return response in dictionary format is '%s'" % rd) self.assertEqual(self.res.response.status, 200) keys = ['revoked_token_num'] self.assertTrue(utils.is_same_array(keys, rd.keys()), "Keys are not correct!")
def test_postive_get_auth_horizon_check_keys(self): """ Check the response contains correct keys. """ r = self.res.get('/auth/config/'+utils.partner, headers=utils.headers) logging.info("Return response is '%s'" % r) # convert string to dictionary rd = ast.literal_eval(r) logging.info("Return response in dictionary format is '%s'" % rd) self.assertEqual(self.res.response.status, 200) keys = ['type', 'web_endpoint', 'client_endpoint', 'org_name'] self.assertTrue(utils.is_same_array(keys, rd.keys()), "Keys are not correct!")
def test_positive_get_tokens_check_keys(self): """ Check the response contains correct keys. """ r = self.res.get('/tokens/'+self.token['access_token'], headers=utils.headers) logging.info("Return response is '%s'" % r) # convert string to dictionary rd = ast.literal_eval(r) logging.info("Return response in dictionary format is '%s'" % rd) self.assertEqual(self.res.response.status, 200) keys = ['access_token_expires_at', 'user_id', 'access_token', 'user', 'client_id', 'access_token_secret', 'permissions'] self.assertTrue(utils.is_same_array(keys, rd.keys()), "Keys are not correct!")
def test_positive_auth_get_config_check_keys(self): """ Check the response contains correct keys returned. """ # get config headers = utils.headers # compose basic auth headers['Authorization'] = "Basic %s" % base64.encodestring('%s:%s' % (utils.auth_client_id, utils.auth_client_secret))[:-1] logging.debug("The requested url is '%s'" % str(self.url)) h, c = self.http.request(self.url, 'GET', headers = utils.headers) logging.debug("The response head is '%s'" % str(h)) logging.debug("The response body is '%s'" % str(c)) # convert result string to dictionary cd = ast.literal_eval(c) # assert head is correct self.assertEqual(int(h['status']), 200) keys = ['type', 'web_endpoint', 'client_endpoint', 'org_name'] self.assertTrue(utils.is_same_array(keys, cd.keys()), "Keys are not correct!")
def test_positive_get_tokens_check_values(self): """ Check the response contains correct values. """ r = self.res.get('/tokens/'+self.token['access_token'], headers=utils.headers) logging.info("Return response is '%s'" % r) # convert string to dictionary rd = ast.literal_eval(r) logging.info("Return response in dictionary format is '%s'" % rd) self.assertEqual(self.res.response.status, 200) # assert 'access_token_expires_at' is in the given values p = re.compile("\d{4,4}(\-\d\d){2,2}T(\d\d:){2,2}\d\dZ") self.assertTrue(p.match(rd['access_token_expires_at']), "The 'access_token_expires_at' does not match '2011-10-21T11:28:39Z'") # assert 'user_id' is integer self.assertEqual(type(rd['client_id']), type(1), "The 'client_id' is not integer") # assert 'access_token' is equal to the one given in token self.assertEqual(rd['access_token'], self.token['access_token'], "The 'access_token' is not equal to the one given in token") # assert 'user' is a dictionary object self.assertEqual(type(rd['user']), type({}), "The 'user' is not dictionary") # assert 'user' has the 'name', 'custom_permission', 'email' and 'id' fields. keys = ['name', 'custom_permission', 'email', 'id'] self.assertTrue(utils.is_same_array(keys, rd['user'].keys()), "The 'user' keys are not correct!") # assert 'user:name' is string self.assertEqual(type(rd['user']['name']), type(""), "The 'user:name' is not string") # assert 'user:custom_permission' is list self.assertEqual(type(rd['user']['custom_permission']), type([]), "The 'user:custom_permission' is not list") # assert 'user:email' is correct format pe = re.compile("[\w\-\._]+@[\w]+\.[\w]+") self.assertTrue(pe.match(rd['user']['email']), "The 'user:email' does not match email address") # assert 'user:id' is integer and equal to the 'user_id' self.assertEqual(rd['user']['id'], rd['user_id'], "The 'user:id' does not equal to 'user_id'") # assert 'client_id' is integer self.assertEqual(type(rd['client_id']), type(1), "The 'client_id' is not integer") # assert 'access_token_secret' is 32 character long self.assertEqual(len(rd['access_token_secret']), 32, "The 'access_token_secret' is not 32 character-long") # assert 'permissions' is a list and values are in the given range self.assertEqual(type(rd['permissions']), type([]), "The 'permissions' is not a list") permissions = ['triton_manifest', 'triton_read', 'triton_write', 'mip_fs_read', 'mip_fs_write', 'mip_photos_read', 'mip_photos_write'] for p in rd['permissions']: assertTrue( p in permissions, "The 'permissions' - '%s' is not in the permission list" % p)