HomePosts

Tsubasa Nakagawa

2st-year master's student at Iyatomi Lab.

Major in Applied Informatics, Graduate School of Science and Engineering, Hosei University

Posts

【Django】JWT 認証付きの API のテストでユーザー認証を行う方法

2023-06-11

JWT 認証には [djangorestframework-simplejwt](https://github.com/jazzband/djangorestframework-simplejwt) を用いていることを前提とする。 ```python from django.contrib.auth import get_user_model from rest_framework.test import APITestCase from rest_framework_simplejwt.tokens import RefreshToken User = get_user_model() class ExampleTests(APITestCase): def setUp(self): self.user = User.objects.create_user(username='username', password='password') self.refresh = RefreshToken.for_user(self.user) self.client.credentials( HTTP_AUTHORIZATION='Bearer ' + str(self.refresh.access_token) ) ``` ### 参考 - https://django-rest-framework-simplejwt.readthedocs.io/en/latest/creating_tokens_manually.html

cron で 1 時間ごとに自動で git push する

2023-05-13

現在の設定を確認 ```shell crontab -l ``` 現在の設定を削除 ```shell crontab -r ``` 現在の設定を編集 ```shell crontab -e ``` 1 時間ごとに自動で git push する ```shell 0 * * * * export LANG=ja_JP.UTF-8 && git add -A && git diff --staged --quiet || (git commit -m "$(date +"%Y-%m-%d %H:%M:%S")" && git push) >/dev/null 2>&1 ``` ### 参考 - https://www.server-memo.net/tips/crontab.html - https://orebibou.com/ja/home/201412/20141225_001/ - https://superuser.com/questions/564829/git-push-to-github-via-cron-on-mac - https://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/

Read more →

© 2022 Tsubasa Nakagawa. All rights reserved