def mocked_monitoring(loop, mocker, activity_data): prometheus_data = activity_data.get("prometheus") cpu_ret = prometheus_data.get("cpu_return") mocker.patch( "simcore_service_webserver.activity.handlers.get_cpu_usage", return_value=future_with_result(cpu_ret), ) mem_ret = prometheus_data.get("memory_return") mocker.patch( "simcore_service_webserver.activity.handlers.get_memory_usage", return_value=future_with_result(mem_ret), ) labels_ret = prometheus_data.get("labels_return") mocker.patch( "simcore_service_webserver.activity.handlers.get_container_metric_for_labels", return_value=future_with_result(labels_ret), ) celery_data = activity_data.get("celery") celery_ret = celery_data.get("celery_return") mocker.patch( "simcore_service_webserver.activity.handlers.get_celery_reserved", return_value=future_with_result(celery_ret), )
def mocked_director_subsystem(mocker): mock_director_api = { "get_running_interactive_services": mocker.patch( "simcore_service_webserver.director.director_api.get_running_interactive_services", return_value=future_with_result(""), ), "start_service": mocker.patch( "simcore_service_webserver.director.director_api.start_service", return_value=future_with_result(""), ), "stop_service": mocker.patch( "simcore_service_webserver.director.director_api.stop_service", return_value=future_with_result(""), ), } return mock_director_api
async def test_add_new_project_from_model_instance( file_type: str, viewer: ViewerInfo, client, mocker, ): mock_func = mocker.patch( "simcore_service_webserver.director_v2.create_or_update_pipeline", return_value=future_with_result(result=None), ) async with NewUser() as user_db: try: # preparation await auto_add_user_to_groups(client.app, user_db["id"]) user_db = await get_user(client.app, user_db["id"]) # this part is under test --- user = UserInfo( id=user_db["id"], name=user_db["name"], primary_gid=user_db["primary_gid"], email=user_db["email"], ) project_id = "e3ee7dfc-25c3-11eb-9fae-02420a01b846" file_picker_id = "4c69c0ce-00e4-4bd5-9cf0-59b67b3a9343" viewer_id = "fc718e5a-bf07-4abe-b526-d9cafd34830c" project: Project = create_viewer_project_model( project_id, file_picker_id, viewer_id, owner=user, download_link="http://httpbin.org/image/jpeg", viewer_info=viewer, ) await add_new_project(client.app, project, user) # checks start here --- assert mock_func.called # internally validates project injected in db project_db = await get_project_for_user( client.app, project.uuid, user.id, include_state=False, include_templates=False, ) assert set( project_db["workbench"].keys()) == {file_picker_id, viewer_id} finally: # tear-down: delete before user gets deleted await delete_all_projects(client.app)
def mocks_on_projects_api(mocker): """ All projects in this module are UNLOCKED """ state = ProjectState(locked=ProjectLocked( value=False, owner=Owner(first_name="Speedy", last_name="Gonzalez"))) mocker.patch( "simcore_service_webserver.projects.projects_api.get_project_state_for_user", return_value=future_with_result(state), )
def mocks_on_projects_api(mocker) -> Dict: """ All projects in this module are UNLOCKED """ state = ProjectState( locked=ProjectLocked( value=False, owner=Owner(user_id=2, first_name="Speedy", last_name="Gonzalez"), ), state=ProjectRunningState(value=RunningState.NOT_STARTED), ).dict(by_alias=True, exclude_unset=True) mocker.patch( "simcore_service_webserver.projects.projects_api.get_project_state_for_user", return_value=future_with_result(state), )
async def test_dispatch_viewer_anonymously( client, storage_subsystem_mock, catalog_subsystem_mock, mocks_on_projects_api, mocker, ): mock_client_director_v2_func = mocker.patch( "simcore_service_webserver.director_v2.create_or_update_pipeline", return_value=future_with_result(result=None), ) redirect_url = (client.app.router["get_redirection_to_viewer"].url_for( ).with_query( file_name="users.csv", file_size=3 * 1024, file_type="CSV", download_link=urllib.parse.quote( "https://raw.githubusercontent.com/ITISFoundation/osparc-simcore/8987c95d0ca0090e14f3a5b52db724fa24114cf5/services/storage/tests/data/users.csv" ), )) resp = await client.get(redirect_url) expected_prj_id = await assert_redirected_to_study(resp, client.session) # has auto logged in as guest? me_url = client.app.router["get_my_profile"].url_for() resp = await client.get(me_url) data, _ = await assert_status(resp, web.HTTPOk) assert data["login"].endswith("guest-at-osparc.io") assert data["gravatar_id"] assert data["role"].upper() == UserRole.GUEST.name # guest user only a copy of the template project projects = await _get_user_projects(client) assert len(projects) == 1 guest_project = projects[0] assert expected_prj_id == guest_project["uuid"] assert guest_project["prjOwner"] == data["login"] assert mock_client_director_v2_func.called