lundi 29 avril 2019

How a passed dictionary in setUp() method can cause changing the user's password here?

I am learning Django testing. I recently saw these codes, I searched a bit but still couldn't convince myself how they actually work together. Here are the codes:

class PasswordChangeTestCase(TestCase):
    def setUp(self, data={}):
        self.user = User.objects.create_user(username='john', email='john@doe.com', password='old_password')
        self.url = reverse('password_change')
        self.client.login(username='john', password='old_password')
        self.response = self.client.post(self.url, data) 

class SuccessfulPasswordChangeTests(PasswordChangeTestCase):
    def setUp(self):
        super().setUp({ # where do this dictionary is passed in?
            'old_password': 'old_password',
            'new_password1': 'new_password',
            'new_password2': 'new_password',
        })


    def test_password_changed(self):
        self.user.refresh_from_db()
        self.assertTrue(self.user.check_password('new_password'))

Can you please explain What does super().setUp({#keyValues}) does in here? I know what aresuper() and setUp(), but I don't know what does it means when they are next to each other specially when a dictionary is passed into setUp?

testing_password_changed function confused me as well. Where in these parts of the code the old password is changed with new password that it refresh the db with self.user.refresh_from_db() function. Changing old password with new password is done in PasswordChangeForm I expected something like self.client.post(password_change_url, data), or maybe I didn't understand them properly. Please help me

Thank you for reading and helping.

Aucun commentaire:

Enregistrer un commentaire