'Django selenium: StaticLiveServerTestCase => 'admin' user can not login

EDIT 15/03/2022 - 15:30

If I set 'admin' user password in test method (see updated code below) it works

but I would like to understand what is the issue when defining password in fixture. I've checked my code to look for line where I could have set admin password but thare no such a line....


I try to use StaticLiveServerTestCase and fixtures.

I have created 7 users using fixture and one of them, 'admin' is_superuser=True.

My tests pass for all of users except admin that failed to login.

I've checked password of admin at the begining of the test method, and I don't know how but (1) password do not correspond to the password set in fixture and (2) password change every runs. That explain failed in login but why only this user has such a behavior?

If I try to connect in my dev environnement, using database containing fixtures datas, it works...

I try to change is_superuser to false, or 'admin' username with 'myadmin' if there could be a side effect but none works...

tests.py

class L_access_menu_creation_patient_TestCase(StaticLiveServerTestCase):
    
    fixtures = ['dumpdata.json']

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.selenium = WebDriver()
        cls.selenium.implicitly_wait(1)
        cls.selenium.maximize_window()
        cls.date_saisie = timezone.now()
        cls.selenium.get(cls.live_server_url)

    # le menu "Ajouter un patient" est disponible (id=menucreate) 
    def test_menu_create_available_admin(self):
        
        # ----------------------------------------- connexion -------------------------------
        
        self.admin = User.objects.get(username='admin')
        self.admin.set_password('admin')  # => new line EDIT 15:30
        self.admin.save()                 # => new line EDIT 15:30

        # envoie de données d'identification
        username_input = self.selenium.find_element_by_name("username")
        username_input.send_keys('admin')
        password_input = self.selenium.find_element_by_name("password")
        password_input.send_keys('admin')

fixture dumpdata.json

...
  {
    "model": "auth.user",
    "fields": {
      "password": "pbkdf2_sha256$150000$qe1v2XJKkik8$jF6iFZ+4GpK1JzBdHzRG0H3XsYY+YphYpxc9Cbgg+7Y=",
      "last_login": null,
      "is_superuser": true,
      "username": "admin",
      "first_name": "",
      "last_name": "",
      "email": "",
      "is_staff": true,
      "is_active": true,
      "date_joined": "2022-03-15T08:32:13.528Z",
      "groups": [],
      "user_permissions": []
    }
  },
...


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source