92 lines
3.5 KiB
Python
92 lines
3.5 KiB
Python
from datetime import timedelta
|
|
|
|
import pytest
|
|
import yaml
|
|
from django.core.management import call_command
|
|
from django.utils import timezone
|
|
|
|
from apps.sources.models import Source, SourcePolicyReview
|
|
from apps.sources.views import _source_list_queryset
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_seed_sources_registers_reviewed_live_feed_and_hides_demo(tmp_path):
|
|
Source.objects.create(
|
|
name="Voorbeeldwerkgever (fixture)",
|
|
source_type=Source.Type.EMPLOYER,
|
|
base_url="https://jobs.example.org/vacatures/",
|
|
domain="jobs.example.org",
|
|
)
|
|
expires_at = (timezone.now() + timedelta(days=30)).isoformat()
|
|
retired_source = Source.objects.create(
|
|
name="Brusselse werkgever",
|
|
source_type=Source.Type.ATS,
|
|
base_url="https://brussels-employer.example/jobs",
|
|
domain="brussels-employer.example",
|
|
status=Source.Status.ACTIVE,
|
|
policy=Source.Policy.ALLOW,
|
|
next_run_at=timezone.now(),
|
|
)
|
|
payload = {
|
|
"disable_demo_sources": True,
|
|
"retire_source_urls": [retired_source.base_url],
|
|
"sources": [
|
|
{
|
|
"name": "VITO",
|
|
"url": "https://vito.recruitee.com/api/offers/",
|
|
"type": "ats",
|
|
"status": "trial",
|
|
"policy": "review",
|
|
"parser": "ats-recruitee",
|
|
"allow_public_endpoint": True,
|
|
"metadata": {"country_scope": "BE"},
|
|
"review": {
|
|
"decision": "trial",
|
|
"reason": "Publieke feed",
|
|
"evidence_link": "https://docs.recruitee.com/reference/offers",
|
|
"expires_at": expires_at,
|
|
},
|
|
},
|
|
{
|
|
"name": "Lever werkgever A",
|
|
"url": "https://api.lever.co/v0/postings/werkgever-a?mode=json",
|
|
"type": "ats",
|
|
"status": "trial",
|
|
"policy": "allow",
|
|
"parser": "ats-lever",
|
|
"allow_public_endpoint": True,
|
|
},
|
|
{
|
|
"name": "Lever werkgever B",
|
|
"url": "https://api.lever.co/v0/postings/werkgever-b?mode=json",
|
|
"type": "ats",
|
|
"status": "trial",
|
|
"policy": "allow",
|
|
"parser": "ats-lever",
|
|
"allow_public_endpoint": True,
|
|
},
|
|
],
|
|
}
|
|
seed_path = tmp_path / "sources.yaml"
|
|
seed_path.write_text(yaml.safe_dump(payload), encoding="utf-8")
|
|
|
|
call_command("seed_sources", str(seed_path))
|
|
call_command("seed_sources", str(seed_path))
|
|
|
|
demo = Source.objects.get(domain="jobs.example.org")
|
|
assert demo.status == Source.Status.DISABLED
|
|
assert demo.metadata["demo"] is True
|
|
retired_source.refresh_from_db()
|
|
assert retired_source.status == Source.Status.DISABLED
|
|
assert retired_source.next_run_at is None
|
|
assert retired_source.metadata["hidden_from_source_list"] is True
|
|
assert retired_source.metadata["retired_reason"] == "Buiten de ingestelde regionale dekking"
|
|
source = Source.objects.get(name="VITO")
|
|
assert retired_source not in _source_list_queryset()
|
|
assert source in _source_list_queryset()
|
|
assert source.allow_public_endpoint is True
|
|
assert source.parser_key == "ats-recruitee"
|
|
assert source.latest_policy_review.decision == SourcePolicyReview.Decision.TRIAL
|
|
assert source.policy_reviews.count() == 1
|
|
assert Source.objects.filter(domain="api.lever.co", source_type=Source.Type.ATS).count() == 2
|