async def delete_bot(bot: str, current_user: User = Depends(auth.get_current_user)): """ Deletes bot. """ AccountProcessor.delete_bot(bot, current_user.get_user()) return {'message': 'Bot removed'}
def test_get_user_details_account_inactive(self, mock_account_inactive): with pytest.raises(ValidationError): user_details = AccountProcessor.get_user_details("*****@*****.**") assert all(user_details[key] is False if key == "is_integration_user" else user_details[key] for key in AccountProcessor.get_user_details( user_details["email"]).keys())
async def add_bot(request: TextData, current_user: User = Depends(auth.get_current_user)): """ Add new bot in a account. """ AccountProcessor.add_bot(request.data, current_user.account, current_user.get_user()) return {'message': 'Bot created'}
async def update_bot(bot: str, request: TextData, current_user: User = Depends(auth.get_current_user)): """ Update name of the bot. """ AccountProcessor.update_bot(request.data, bot) return {'message': 'Bot name updated'}
def test_add_account(self): account_response = AccountProcessor.add_account("paypal", "testAdmin") account = AccountProcessor.get_account(account_response["_id"]) assert account_response assert account_response["_id"] == account["_id"] assert account_response["name"] == account["name"] account_response = AccountProcessor.add_account("ebay", "testAdmin") account = AccountProcessor.get_account(account_response["_id"]) assert account_response assert account_response["_id"] == account["_id"] assert account_response["name"] == account["name"]
def test_add_user_blank_lastname(self): with pytest.raises(AppException): AccountProcessor.add_user( email="*****@*****.**", first_name="Fahad Ali", last_name=" ", password="******", account=1, bot=pytest.bot, user="******", )
def test_add_user_None_password(self): with pytest.raises(AppException): AccountProcessor.add_user( email="*****@*****.**", first_name="Fahad Ali", last_name="Shaikh", password=None, account=1, bot=pytest.bot, user="******", )
def test_add_user_none_email(self): with pytest.raises(AppException): AccountProcessor.add_user( email=None, first_name="Fahad Ali", last_name="Shaikh", password="******", account=1, bot=pytest.bot, user="******", )
def test_add_user_invalid_email(self): with pytest.raises(ValidationError): AccountProcessor.add_user( email="demo", first_name="Fahad Ali", last_name="Shaikh", password="******", account=1, bot=pytest.bot, user="******", )
def test_add_user_duplicate_case_insensitive(self): with pytest.raises(Exception): AccountProcessor.add_user( email="*****@*****.**", first_name="Fahad Ali", last_name="Shaikh", password="******", account=1, bot=pytest.bot, user="******", )
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_reset_link_with_empty_mail(self, monkeypatch): AccountProcessor.EMAIL_ENABLED = True monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) loop = asyncio.new_event_loop() with pytest.raises(Exception): loop.run_until_complete(AccountProcessor.send_reset_link('')) AccountProcessor.EMAIL_ENABLED = False
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
def test_account_setup_empty_values(self): account = {} with pytest.raises(AppException): loop = asyncio.new_event_loop() loop.run_until_complete( AccountProcessor.account_setup(account_setup=account, user="******"))
def test_reset_link_with_mail(self, monkeypatch): AccountProcessor.EMAIL_ENABLED = True monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) loop = asyncio.new_event_loop() loop.run_until_complete( AccountProcessor.send_reset_link('*****@*****.**')) AccountProcessor.EMAIL_ENABLED = False assert True
def test_send_confirmation_link_with_confirmed_id(self, monkeypatch): AccountProcessor.EMAIL_ENABLED = True monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) loop = asyncio.new_event_loop() with pytest.raises(Exception): loop.run_until_complete( AccountProcessor.send_confirmation_link('*****@*****.**')) AccountProcessor.EMAIL_ENABLED = False
def test_send_confirmation_link_with_valid_id(self, monkeypatch): AccountProcessor.add_user( email="*****@*****.**", first_name="inteq", last_name="3", password='******', account=1, bot=pytest.bot, user="******", ) AccountProcessor.EMAIL_ENABLED = True monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) loop = asyncio.new_event_loop() loop.run_until_complete( AccountProcessor.send_confirmation_link('*****@*****.**')) AccountProcessor.EMAIL_ENABLED = False assert True
def test_overwrite_password_with_empty_password_string(self, monkeypatch): monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) loop = asyncio.new_event_loop() with pytest.raises(Exception): loop.run_until_complete( AccountProcessor.overwrite_password( 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtYWlsX2lkIjoiaW50ZWcxQGdtYWlsLmNvbSJ9.Ycs1ROb1w6MMsx2WTA4vFu3-jRO8LsXKCQEB3fkoU20', " "))
async def get_users_details(current_user: User = Depends( auth.get_current_user)): """ returns the details of the current logged-in user """ return { "data": { "user": AccountProcessor.get_complete_user_details(current_user.email) } }
def test_account_setup_missing_bot_name(self): account = { "account": "TestAccount", "email": "*****@*****.**", "first_name": "Test_First", "last_name": "Test_Last", "password": "******", } with pytest.raises(AppException): loop = asyncio.new_event_loop() loop.run_until_complete( AccountProcessor.account_setup(account_setup=account, user="******"))
def test_add_user(self): user = AccountProcessor.add_user( email="*****@*****.**", first_name="Fahad Ali", last_name="Shaikh", password="******", account=1, bot=pytest.bot, user="******", ) assert user assert user["password"] != "12345" assert user["status"]
def test_account_setup_user_info(self): account = { "account": "Test_Account", "bot": "Test", "first_name": "Test_First", "last_name": "Test_Last", "password": SecretStr("Welcome@1"), } with pytest.raises(AppException): loop = asyncio.new_event_loop() loop.run_until_complete( AccountProcessor.account_setup(account_setup=account, user="******"))
def test_account_setup(self): account = { "account": "Test_Account", "bot": "Test", "email": "*****@*****.**", "first_name": "Test_First", "last_name": "Test_Last", "password": SecretStr("Welcome@1"), } loop = asyncio.new_event_loop() actual, mail, subject, body = loop.run_until_complete( AccountProcessor.account_setup(account_setup=account, user="******")) assert actual["role"] == "admin" assert actual["_id"] assert actual["account"] assert actual["bot"]
def test_add_bot_for_existing_user(self): bot_response = AccountProcessor.add_bot("test_version_2", pytest.account, "*****@*****.**", False) bot = Bot.objects(name="test_version_2").get().to_mongo().to_dict() assert bot['_id'].__str__() == bot_response['_id'].__str__() user = User.objects(email="*****@*****.**").get() assert len(user.bot) == 2 config = Configs.objects( bot=bot['_id'].__str__()).get().to_mongo().to_dict() assert config['language'] assert config['pipeline'][6]['name'] == 'FallbackClassifier' assert config['pipeline'][6]['threshold'] == 0.7 assert config['policies'][2]['name'] == 'RulePolicy' assert config['policies'][2][ 'core_fallback_action_name'] == "action_default_fallback" assert config['policies'][2]['core_fallback_threshold'] == 0.3 assert Rules.objects(bot=bot['_id'].__str__()).get() assert Responses.objects(name='utter_default', bot=bot['_id'].__str__(), status=True).get()
def test_add_bot(self): bot_response = AccountProcessor.add_bot("test", pytest.account, "*****@*****.**", True) bot = Bot.objects(name="test").get().to_mongo().to_dict() assert bot['_id'].__str__() == bot_response['_id'].__str__() config = Configs.objects( bot=bot['_id'].__str__()).get().to_mongo().to_dict() assert config['language'] assert config['pipeline'][6]['name'] == 'FallbackClassifier' assert config['pipeline'][6]['threshold'] == 0.7 assert config['policies'][2]['name'] == 'RulePolicy' assert config['policies'][2][ 'core_fallback_action_name'] == "action_default_fallback" assert config['policies'][2]['core_fallback_threshold'] == 0.3 assert Rules.objects(bot=bot['_id'].__str__()).get() assert Responses.objects(name__iexact='utter_please_rephrase', bot=bot['_id'].__str__(), status=True).get() assert Responses.objects(name='utter_default', bot=bot['_id'].__str__(), status=True).get() pytest.bot = bot_response['_id'].__str__()
def test_add_none_bot(self): with pytest.raises(AppException): AccountProcessor.add_bot(None, 1, "testAdmin")
def test_add_empty_bot(self): with pytest.raises(AppException): AccountProcessor.add_bot("", 1, "testAdmin")
def test_add_duplicate_bot_case_insensitive(self): with pytest.raises(Exception): AccountProcessor.add_bot("TEST", 1, "testAdmin")
def test_add_duplicate_bot(self): with pytest.raises(Exception): AccountProcessor.add_bot("test", 1, "testAdmin")
def test_send_confirmation_link_with_mail_not_enabled(self, monkeypatch): monkeypatch.setattr(Utility, 'trigger_smtp', self.mock_smtp) loop = asyncio.new_event_loop() with pytest.raises(Exception): loop.run_until_complete( AccountProcessor.send_confirmation_link('*****@*****.**'))