Esempio n. 1
0
 def setUpClass(cls):
     super().setUpClass()
     user = cls.baker.make(settings.AUTH_USER_MODEL,
                           is_superuser=True,
                           is_active=True)
     cls.user_pass = gen_random_password(user=user)
     user.set_password(cls.user_pass)
     user.save()
     cls.user = user
Esempio n. 2
0
 def setUpClass(cls):
     super().setUpClass()
     user = cls.baker.make(
         settings.AUTH_USER_MODEL, is_superuser=True, is_staff=True, is_active=True
     )
     cls.user_pass = gen_random_password(user=user)
     user.set_password(cls.user_pass)
     user.save()
     cls.user = get_user_model().objects.get(username=user.username)
Esempio n. 3
0
 def setUpClass(cls):
     super().setUpClass()
     users = cls.baker.make(settings.AUTH_USER_MODEL,
                            is_active=True,
                            _quantity=4)
     cls.activated_initial_password = gen_random_password(user=users[0])
     users[0].set_password(cls.activated_initial_password)
     users[0].save()
     cls.activated_user = authenticate(
         username=users[0].username,
         password=cls.activated_initial_password)
Esempio n. 4
0
 def test_user_change_password(self):
     user = self.baker.make(settings.AUTH_USER_MODEL, is_active=True)
     user_initial_password = gen_random_password(user=user)
     user.set_password(user_initial_password)
     user.save()
     user = authenticate(username=user.username,
                         password=user_initial_password)
     self.assertIsNotNone(user)
     self.client.force_authenticate(user)
     new_password = gen_random_password(user=user)
     data = {
         "old_password": user_initial_password,
         "new_password": new_password,
         "re_new_password": new_password,
     }
     url = self.reverse("user-change-password", kwargs={"version": "v1"})
     response = self.client.post(url, data)
     self.assertEqual(response.status_code, self.status_code.HTTP_200_OK,
                      response.json())
     user = authenticate(username=user.username, password=new_password)
     self.assertIsNotNone(user)
Esempio n. 5
0
 def test_user_email_verify(self):
     non_activated_user_pass = gen_random_password()
     non_activated_user_username = random_gen.gen_string(15)
     user_data = {
         "username": non_activated_user_username,
         "email": random_gen.gen_email(),
         "first_name": random_gen.gen_string(150),
         "last_name": random_gen.gen_string(150),
         "password": non_activated_user_pass,
         "re_password": non_activated_user_pass,
         "organization": random_gen.gen_string(255),
         "role": random_gen.gen_string(50),
     }
     url = self.reverse("user-register", kwargs={"version": "v1"})
     response = self.client.post(url, data=user_data)
     self.assertEqual(response.status_code,
                      self.status_code.HTTP_201_CREATED, response.json())
     non_activated_user = get_user_model().objects.get(
         username=non_activated_user_username)
     url = self.reverse("user-email-confirm", kwargs={"version": "v1"})
     user = authenticate(username=non_activated_user.username,
                         password=non_activated_user_pass)
     self.assertIsNone(user)
     email_verify_pin = (apps.get_model(
         "user",
         "EmailConfirmationPin").objects.get(user=non_activated_user).pin)
     response = self.client.post(
         url,
         data={
             "username": non_activated_user.username,
             "pin": email_verify_pin,
         },
     )
     self.assertEqual(response.status_code, self.status_code.HTTP_200_OK,
                      response.json())
     email_verified = get_user_model().objects.get(
         username=non_activated_user.username)
     self.assertTrue(email_verified.check_password(non_activated_user_pass))