コード例 #1
0
    def test_reset_password__ok(self, client, user, mocked_auth_send, dbs):
        request_user = user
        await_(request_user.update(dbs, is_superuser=True))
        target_user = await_(
            User.async_create(dbs,
                              db_commit=True,
                              email=self.email,
                              password="******"))

        client.login(user)
        response = client.post(self.url, json={"email": target_user.email})
        response_data = self.assert_ok_response(response)
        token = response_data.get("token")

        assert response_data["user_id"] == target_user.id
        assert token is not None, response_data
        assert decode_jwt(response_data["token"])["user_id"] == target_user.id

        link = f"{settings.SITE_URL}/change-password/?t={token}"
        expected_body = (
            f"<p>You can reset your password for {settings.SITE_URL}</p>"
            f"<p>Please follow the link </p>"
            f"<p><a href={link}>{link}</a></p>")
        mocked_auth_send.assert_awaited_once_with(
            recipient_email=target_user.email,
            subject=f"Welcome back to {settings.SITE_URL}",
            html_content=expected_body,
        )
コード例 #2
0
 def _create_user(self, db_session, is_active=True):
     self.user = await_(
         User.async_create(
             db_session,
             db_commit=True,
             email=self.email,
             password=self.encoded_password,
             is_active=is_active,
         ))
コード例 #3
0
    def test_sign_up__user_already_exists__fail(self, client, user_invite,
                                                dbs):
        request_data = self._sign_up_data(user_invite)
        user_email = request_data["email"]

        await_(
            User.async_create(dbs,
                              db_commit=True,
                              email=user_email,
                              password="******"))
        response = client.post(self.url, json=request_data)
        response_data = self.assert_fail_response(response)
        assert response_data == {
            "error": "Requested data is not valid.",
            "details": f"User with email '{user_email}' already exists",
        }
コード例 #4
0
def create_user(db_session):
    email, password = get_user_data()
    return await_(User.async_create(db_session, db_commit=True, email=email, password=password))