예제 #1
0
async def accounts_from_user(user_id: str):
    user = await UsersService.get_user_by_id(int(user_id), UsersBackend())

    status_code = HTTPStatus.OK if user else HTTPStatus.NOT_FOUND

    if user:
        accounts = await UsersService.get_accounts_from_user(
            user, UsersBackend())
        return web.json_response(
            UserAccountsResource(accounts=accounts).dict(), status=status_code)
    return web.json_response(UserAccountsResource().dict(), status=status_code)
예제 #2
0
 async def test_get_accounts_from_user_user_not_found(self):
     resp = await self.client.get(
         f"/users/99/accounts",
         headers={
             "Authorization": f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
         },
     )
     self.assertEqual(404, resp.status)
     accounts_data = await resp.json()
     self.assertEqual(UserAccountsResource().dict(), accounts_data)
예제 #3
0
 async def test_get_accounts_from_user_user_with_accounts(self):
     resp = await self.client.get(
         f"/users/{USER_WITH_MULTIPLE_ACCOUNTS_ID}/accounts",
         headers={
             "Authorization":
             f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
         },
     )
     self.assertEqual(200, resp.status)
     accounts_data = await resp.json()
     self.assertEqual(
         UserAccountsResource(accounts=[
             Account(**ACCOUNT_DEV_DICT),
             Account(**ACCOUNT_INFRA_DICT),
         ]).dict(),
         accounts_data,
     )