import pytest from apps.jobs.models import JobSourceAlias, ScoreRun from apps.jobs.services.skill_demand import build_skill_demand_report from apps.sources.models import Source @pytest.mark.django_db def test_skill_demand_distinguishes_structured_evidence_and_text_signals(job, profile): job.skills_required = ["Microsoft 365"] job.skills_preferred = [] job.description_text = ( "Bouw governance voor Dynamics 365 en Microsoft Copilot. " "Zorg ook voor high availability en gebruikersadoptie." ) report = build_skill_demand_report(profile, jobs=[job]) by_key = {item.key: item for item in report.items} assert by_key["microsoft 365"].covered is True assert by_key["microsoft 365"].explicit_count == 1 assert by_key["dynamics 365"].covered is False assert by_key["dynamics 365"].inferred_count == 1 assert by_key["microsoft copilot"].vacancy_count == 1 assert by_key["high availability"].learning_focus assert report.gap_count >= 3 @pytest.mark.django_db def test_skill_demand_filters_category_and_profile_coverage(job, profile): job.skills_required = ["Microsoft 365", "FortiGate"] job.description_text = "Microsoft 365 en FortiGate-beheer." gaps = build_skill_demand_report( profile, category="netwerk-security", coverage="gap", jobs=[job], ) assert [item.key for item in gaps.items] == ["fortinet"] assert gaps.selected_category == "netwerk-security" assert gaps.selected_coverage == "gap" @pytest.mark.django_db def test_generic_team_word_is_not_microsoft_teams_demand(job, profile): job.skills_required = [] job.skills_preferred = [] job.description_text = "Je werkt samen met internationale teams aan klanttevredenheid." report = build_skill_demand_report(profile, jobs=[job]) assert "microsoft teams" not in {item.key for item in report.items} @pytest.mark.django_db def test_disabled_source_vacancies_do_not_feed_learning_advice(job, profile, source): JobSourceAlias.objects.create( job=job, source=source, external_id="disabled-source-job", url=job.canonical_url, canonical_url=job.canonical_url, ) ScoreRun.objects.create( job=job, profile=profile, profile_version=profile.version, score=75, confidence=0.9, recommendation=ScoreRun.Recommendation.POSSIBLE, ) source.status = Source.Status.DISABLED source.save(update_fields=["status"]) report = build_skill_demand_report(profile) assert report.total_jobs == 0 assert report.signal_count == 0