from tempfile import TemporaryDirectory from app.models.project import ProjectManager from app.services.simulation_manager import SimulationManager from test_resource_auth_scope import csrf_headers, login, make_resource_app def test_simulation_create_rejects_in_scope_graph_from_another_project(): app, engine, organization_id, user_a_id, _user_b_id = make_resource_app() original_projects_dir = ProjectManager.PROJECTS_DIR original_simulations_dir = SimulationManager.SIMULATION_DATA_DIR try: with TemporaryDirectory() as temp_dir: ProjectManager.PROJECTS_DIR = f"{temp_dir}/projects" SimulationManager.SIMULATION_DATA_DIR = f"{temp_dir}/simulations" project_a = ProjectManager.create_project( "A", organization_id=organization_id, owner_user_id=user_a_id ) project_a.graph_id = "graph-a" ProjectManager.save_project(project_a) project_b = ProjectManager.create_project( "B", organization_id=organization_id, owner_user_id=user_a_id ) project_b.graph_id = "graph-b" ProjectManager.save_project(project_b) client = app.test_client() login(client) response = client.post( "/api/simulation/create", json={"project_id": project_a.project_id, "graph_id": project_b.graph_id}, headers={ **csrf_headers(client), "Idempotency-Key": "cross-project-graph", }, ) assert response.status_code == 404 finally: ProjectManager.PROJECTS_DIR = original_projects_dir SimulationManager.SIMULATION_DATA_DIR = original_simulations_dir engine.dispose()