This commit is contained in:
@@ -15,6 +15,7 @@ from inse.auth.model import (
|
||||
UserRole,
|
||||
)
|
||||
from inse.dashboard.service import (
|
||||
get_dashboard_analytical_institution,
|
||||
get_dashboard_institutions,
|
||||
get_dashboard_organization,
|
||||
get_dashboard_persons,
|
||||
@@ -1682,6 +1683,107 @@ async def test_dashboard_institutions_include_openalex_associations():
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_dashboard_analytical_institution_all_uses_root_organization():
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
with Session(engine) as session:
|
||||
organization = Organization(
|
||||
name="Example University",
|
||||
openalex_institution_id="I123",
|
||||
)
|
||||
session.add(organization)
|
||||
session.commit()
|
||||
session.refresh(organization)
|
||||
|
||||
result = await get_dashboard_analytical_institution(
|
||||
session,
|
||||
organization,
|
||||
"all",
|
||||
)
|
||||
|
||||
assert result == ("I123", "Example University")
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_dashboard_analytical_institution_uses_selected_tab_institution():
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
with Session(engine) as session:
|
||||
organization = Organization(
|
||||
name="Example University",
|
||||
openalex_institution_id="I123",
|
||||
)
|
||||
session.add(organization)
|
||||
session.commit()
|
||||
session.refresh(organization)
|
||||
session.add(
|
||||
OrganizationInstitution(
|
||||
organization_id=organization.id,
|
||||
openalex_institution_id="I123",
|
||||
position=0,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
associations = [
|
||||
InstitutionAssociationsResponse(
|
||||
id="I123",
|
||||
display_name="Main institution",
|
||||
associated_institutions=[
|
||||
InstitutionAssociation(
|
||||
id="I456",
|
||||
display_name="Child institution",
|
||||
relationship="child",
|
||||
),
|
||||
],
|
||||
)
|
||||
]
|
||||
with patch(
|
||||
"inse.dashboard.service.organization_management_service."
|
||||
"resolve_institution_associations",
|
||||
new=AsyncMock(return_value=associations),
|
||||
):
|
||||
result = await get_dashboard_analytical_institution(
|
||||
session,
|
||||
organization,
|
||||
"https://openalex.org/I456",
|
||||
)
|
||||
|
||||
assert result == ("I456", "Child institution")
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_dashboard_analytical_institution_rejects_unassociated_selection():
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
with Session(engine) as session:
|
||||
organization = Organization(
|
||||
name="Example University",
|
||||
openalex_institution_id="I123",
|
||||
)
|
||||
session.add(organization)
|
||||
session.commit()
|
||||
session.refresh(organization)
|
||||
|
||||
with patch(
|
||||
"inse.dashboard.service.organization_management_service."
|
||||
"resolve_institution_associations",
|
||||
new=AsyncMock(return_value=[]),
|
||||
):
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await get_dashboard_analytical_institution(
|
||||
session,
|
||||
organization,
|
||||
"I999",
|
||||
)
|
||||
|
||||
assert exc_info.value.status_code == 422
|
||||
|
||||
|
||||
def test_get_dashboard_organization_rejects_missing_openalex_id():
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False})
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
HttpTestingController,
|
||||
provideHttpClientTesting,
|
||||
} from '@angular/common/http/testing';
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
|
||||
import { DashboardStatisticsService } from './dashboard-statistics.service';
|
||||
|
||||
describe('DashboardStatisticsService', () => {
|
||||
let service: DashboardStatisticsService;
|
||||
let httpMock: HttpTestingController;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
DashboardStatisticsService,
|
||||
provideHttpClient(),
|
||||
provideHttpClientTesting(),
|
||||
],
|
||||
});
|
||||
|
||||
service = TestBed.inject(DashboardStatisticsService);
|
||||
httpMock = TestBed.inject(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
it('sends the selected institution and period for lower project status requests', () => {
|
||||
service
|
||||
.getEuProjectStatuses({ fromYear: 2024, toYear: 2026 }, 'I456')
|
||||
.subscribe();
|
||||
|
||||
const request = httpMock.expectOne((req) => {
|
||||
return req.url === '/api/dashboard/projects/eu/status';
|
||||
});
|
||||
|
||||
expect(request.request.params.get('institution_id')).toBe('I456');
|
||||
expect(request.request.params.get('from_year')).toBe('2024');
|
||||
expect(request.request.params.get('to_year')).toBe('2026');
|
||||
|
||||
request.flush({
|
||||
institution_id: 'https://openalex.org/I456',
|
||||
organization_name: 'Selected institution',
|
||||
ongoing: 1,
|
||||
upcoming: 0,
|
||||
completed: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it('sends only the active institution for a topic treemap request', () => {
|
||||
service.getTopicTreemap(2024, 2026, 'I789').subscribe();
|
||||
|
||||
const request = httpMock.expectOne((req) => {
|
||||
return req.url === '/api/dashboard/topic-heatmap';
|
||||
});
|
||||
|
||||
expect(request.request.params.get('institution_id')).toBe('I789');
|
||||
expect(request.request.params.get('from_year')).toBe('2024');
|
||||
expect(request.request.params.get('to_year')).toBe('2026');
|
||||
|
||||
request.flush({
|
||||
institution_id: 'https://openalex.org/I789',
|
||||
organization_name: 'Selected institution',
|
||||
years: [],
|
||||
fields: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps all as the default lower-dashboard institution scope', () => {
|
||||
service.getBundProjectTopics().subscribe();
|
||||
|
||||
const request = httpMock.expectOne((req) => {
|
||||
return req.url === '/api/dashboard/projects/bund/topics';
|
||||
});
|
||||
|
||||
expect(request.request.params.get('institution_id')).toBe('all');
|
||||
expect(request.request.params.has('from_year')).toBeFalse();
|
||||
expect(request.request.params.has('to_year')).toBeFalse();
|
||||
|
||||
request.flush({
|
||||
institution_id: 'https://openalex.org/I123',
|
||||
organization_name: 'Root organization',
|
||||
project_count: 0,
|
||||
matched_project_count: 0,
|
||||
topics: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user