def test_overwrite_password_with_valid_entries(self, monkeypatch): monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) token = Utility.generate_token('*****@*****.**') loop = asyncio.new_event_loop() loop.run_until_complete( AccountProcessor.overwrite_password(token, "Welcome@3")) assert True
async def send_confirmation_link(mail: str): """ Sends a link to the user's mail id for account verification :param mail: the mail id of the user :return: mail id, mail subject and mail body """ if AccountProcessor.EMAIL_ENABLED: if isinstance(mail_check(mail), ValidationFailure): raise AppException("Please enter valid email id") Utility.is_exist(UserEmailConfirmation, exp_message="Email already confirmed!", email__iexact=mail.strip()) if not Utility.is_exist( User, email__iexact=mail.strip(), raise_error=False): raise AppException( "Error! There is no user with the following mail id") token = Utility.generate_token(mail) link = Utility.email_conf["app"]["url"] + '/verify/' + token body = Utility.email_conf['email']['templates'][ 'confirmation_body'] + link subject = Utility.email_conf['email']['templates'][ 'confirmation_subject'] return mail, subject, body else: raise AppException("Error! Email verification is not enabled")
async def account_setup(account_setup: Dict, user: Text): """ create new account :param account_setup: dict of account details :param user: user id :return: dict user details, user email id, confirmation mail subject, mail body """ account = None bot = None user_details = None body = None subject = None mail_to = None try: account = AccountProcessor.add_account( account_setup.get("account"), user) bot = AccountProcessor.add_bot(account_setup.get("bot"), account["_id"], user) user_details = AccountProcessor.add_user( email=account_setup.get("email"), first_name=account_setup.get("first_name"), last_name=account_setup.get("last_name"), password=account_setup.get("password").get_secret_value(), account=account["_id"].__str__(), bot=bot["_id"].__str__(), user=user, role="admin", ) await MongoProcessor().save_from_path( "template/use-cases/Hi-Hello", bot["_id"].__str__(), user="******") if AccountProcessor.EMAIL_ENABLED: token = Utility.generate_token(account_setup.get("email")) link = Utility.email_conf["app"]["url"] + '/verify/' + token body = Utility.email_conf['email']['templates'][ 'confirmation_body'] + link subject = Utility.email_conf['email']['templates'][ 'confirmation_subject'] mail_to = account_setup.get("email") except Exception as e: if account and "_id" in account: Account.objects().get(id=account["_id"]).delete() if bot and "_id" in bot: Bot.objects().get(id=bot["_id"]).delete() raise e return user_details, mail_to, subject, body
def test_new_user_confirm(self, monkeypatch): AccountProcessor.add_user( email="*****@*****.**", first_name="inteq", last_name="2", password='******', account=1, bot=pytest.bot, user="******", ) monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) token = Utility.generate_token('*****@*****.**') loop = asyncio.new_event_loop() loop.run_until_complete(AccountProcessor.confirm_email(token)) assert True
def test_user_already_confirmed(self, monkeypatch): monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) loop = asyncio.new_event_loop() token = Utility.generate_token('*****@*****.**') with pytest.raises(Exception): loop.run_until_complete(AccountProcessor.confirm_email(token))
def test_valid_token(self): token = Utility.generate_token('*****@*****.**') mail = Utility.verify_token(token) assert mail