async def test_query_vfolders(self, create_app_and_client, get_headers, user_keypair): app, client = await create_app_and_client(modules=['auth', 'admin']) # Add test vfolder info to db async with app['dbpool'].acquire() as conn: query = vfolders.insert().values({ 'host': 'test-local-host', 'name': 'test-vfolder', 'belongs_to': user_keypair['access_key'], }) await conn.execute(query) query = '{ vfolders { host name max_files max_size } }' payload = json.dumps({'query': query}).encode() headers = get_headers('POST', self.url, payload, keypair=user_keypair) ret = await client.post(self.url, data=payload, headers=headers) assert ret.status == 200 rsp_json = await ret.json() assert rsp_json['vfolders'][0]['host'] == 'test-local-host' assert rsp_json['vfolders'][0]['name'] == 'test-vfolder' assert rsp_json['vfolders'][0]['max_files'] == 1000 assert rsp_json['vfolders'][0]['max_size'] == 1048576
async def test_cannot_accept_invitation_with_duplicated_vfolder_name( self, prepare_vfolder, get_headers, folder_mount, folder_host, user_keypair): app, client, create_vfolder = prepare_vfolder folder_info = await create_vfolder() inv_id = uuid.uuid4().hex async with app['dbpool'].acquire() as conn: query = (vfolder_invitations.insert().values({ 'id': inv_id, 'permission': 'ro', 'vfolder': folder_info['id'], 'inviter': '*****@*****.**', 'invitee': '*****@*****.**', 'state': 'pending', })) await conn.execute(query) # Invitee already has vfolder with the same name as invitation. query = (vfolders.insert().values({ 'id': uuid.uuid4().hex, 'name': folder_info['name'], 'host': 'azure-shard01', 'last_used': None, 'belongs_to': user_keypair['access_key'], })) await conn.execute(query) url = f'/v3/folders/invitations/accept' req_bytes = json.dumps({ 'inv_id': inv_id, 'inv_ak': user_keypair['access_key'] }).encode() headers = get_headers('POST', url, req_bytes, keypair=user_keypair) ret = await client.post(url, data=req_bytes, headers=headers) async with app['dbpool'].acquire() as conn: query = (sa.select('*').select_from(vfolder_permissions).where( vfolder_permissions.c.access_key == user_keypair['access_key']) ) result = await conn.execute(query) perm = await result.fetchall() query = (sa.select('*').select_from(vfolder_invitations).where( vfolder_invitations.c.invitee == '*****@*****.**')) result = await conn.execute(query) invitations = await result.fetchall() assert ret.status == 400 assert len(perm) == 0 assert len(invitations) == 1 assert invitations[0]['state'] == 'pending'