0
0

テスト時にAPI認証の通し方

OAuthで認証を実装したら、ライブラリがうまいこと隠蔽してるのでテスト時に躓いた。
テストする際にサクッと認証を通す関数を作成した。

from rest_framework_simplejwt.tokens import RefreshToken
....
    def auth_factory(self, user):
        # トークンを直接生成
        refresh = RefreshToken.for_user(user)
        token = str(refresh.access_token)

        client = APIClient()
        client.credentials(HTTP_AUTHORIZATION="Bearer " + token)
        return client
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0