from flexmock import flexmock from sqlalchemy.exc import SQLAlchemyError from masters_registry.connectors import mysql from masters_registry.constant import bulk_tasks_const from masters_registry.logic import bulk_tasks as bulk_tasks_logic from masters_registry.models import bulk_tasks from masters_registry.models import users def test_get_orchard_user_names_exception(): """Test get_isrcs function for valid exception. """ (flexmock(mysql) .should_receive('mr_session_scope') .and_raise(SQLAlchemyError)) result = users.get_orchard_user_names([-1, -2]) assert result.status == 500 def test_get_orchard_user_names_empty_list(): """Test for empty input list """ result = users.get_orchard_user_names([]) assert result.status == 400 def test_get_orchard_user_names_success( db_orchard_users_list, result_orchard_users_dict): """Successful call of get_orchard_user_names function. """ session_scope = flexmock( execute=lambda query, data: db_orchard_users_list ) (flexmock(mysql) .should_receive('mr_session_scope') .and_return(session_scope)) result = users.get_orchard_user_names([1, 2, 3]) assert result.message == result_orchard_users_dict def test_show_user_name(db_single_get_orchard_user_names): """Test show user names in bulk statuses page. """ (flexmock(users) .should_receive('get_orchard_user_names') .and_return(db_single_get_orchard_user_names)) (flexmock(bulk_tasks) .should_receive('create_task') .with_args( correlation_id='correlation_id', user_id=123, task_type=bulk_tasks_const.DONE_STATUS, count=2, context=['ISRC1', 'ISRC2'], user_name='Test User') .once()) bulk_tasks_logic.create_task( correlation_id='correlation_id', user_id=123, task_type=bulk_tasks_const.DONE_STATUS, count=2, context=['ISRC1', 'ISRC2'] )