LoginSignup
3
4

More than 5 years have passed since last update.

[django]テストでユーザログインしたい

Last updated at Posted at 2019-01-10

Client.login メソッドを使ってログインする


from django.test import Client, TestCase

class HogeTestCase(TestCase):
    """                                                                                                                                                                                                                                                                         
    """
    def setUp(self):
        """                                                                                                                                                                                                                                                                     
        """
        self.user = User.objects.create_user('HogeTaro', 'taro@hoge.com', 'password')

        self.client = Client()

        self.client.login(username='HogeTaro', password='password')
3
4
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
3
4