Example #1
0
class RestorePasswordAPITests(APITestCase):
    def setUp(self):
        self.user = UserFactory()

    def test_request_restore_code(self):
        self.assertIsNone(self.user.restore_password_code)
        data = {
            "email": self.user.email,
        }
        response = self.client.post("/api/v1/request_restore_code/",
                                    data=data,
                                    format="json")
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        user = User.objects.get(pk=self.user.pk)
        self.assertIsNotNone(user.restore_password_code)

    def test_restore_password(self):
        self.user.send_restore_code()
        data = {
            "password": "******",
            "repeat_password": "******",
            "restore_password_code": self.user.restore_password_code,
        }
        response = self.client.post("/api/v1/restore_password/",
                                    data=data,
                                    format="json")
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        user = User.objects.get(pk=self.user.pk)
        self.assertTrue(user.check_password(data["password"]))
Example #2
0
 def test_list_users(self):
     UserFactory.create_batch(size=10)
     self.client.force_authenticate(self.user)
     response = self.client.get("/api/v1/users/", format="json")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     data = response.json()
     self.assertEqual(1, data["count"])
    def test_clean_username(self):
        # A user with proto_user params does not exist yet.
        proto_user = UserFactory.build()

        form = UserCreationForm({
            "username": proto_user.username,
            "password1": proto_user._password,
            "password2": proto_user._password,
        })

        assert form.is_valid()
        assert form.clean_username() == proto_user.username

        # Creating a user.
        form.save()

        # The user with proto_user params already exists,
        # hence cannot be created.
        form = UserCreationForm({
            "username": proto_user.username,
            "password1": proto_user._password,
            "password2": proto_user._password,
        })

        assert not form.is_valid()
        assert len(form.errors) == 1
        assert "username" in form.errors
Example #4
0
class VerifyEmailAPITests(APITestCase):
    def setUp(self):
        self.user = UserFactory()

    def test_request_restore_code(self):
        self.user.is_email_verified = False
        self.user.save()
        self.assertFalse(self.user.is_email_verified)
        data = {
            "verification_code": self.user.verification_code,
        }
        response = self.client.post("/api/v1/verify_email/",
                                    data=data,
                                    format="json")
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        user = User.objects.get(pk=self.user.pk)
        self.assertTrue(user.is_email_verified)
Example #5
0
def user() -> settings.AUTH_USER_MODEL:
    return UserFactory()
Example #6
0
 def setUp(self):
     self.user = UserFactory()
Example #7
0
    def setUp(self):
        self.question = Question(
        )  #now I can use question as an instance of the Model Question

        #create a user to prevent 403 error
        self.user = UserFactory()