fix: resolve parser organizations from directory only
This commit is contained in:
30
tests/apps/parsers/organization_helpers.py
Normal file
30
tests/apps/parsers/organization_helpers.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Organization helpers for parser tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from django.utils import timezone
|
||||
from organizations.models import Organization
|
||||
|
||||
|
||||
def create_directory_organization(**kwargs) -> Organization:
|
||||
"""Create an organization row that belongs to the authoritative directory."""
|
||||
kwargs.setdefault("directory_imported_at", timezone.now())
|
||||
return Organization.objects.create(**kwargs)
|
||||
|
||||
|
||||
def get_or_create_directory_organization(
|
||||
*,
|
||||
defaults: dict | None = None,
|
||||
**lookup,
|
||||
) -> tuple[Organization, bool]:
|
||||
"""Get or create an authoritative directory organization for ingestion tests."""
|
||||
directory_defaults = dict(defaults or {})
|
||||
directory_defaults.setdefault("directory_imported_at", timezone.now())
|
||||
organization, created = Organization.objects.get_or_create(
|
||||
defaults=directory_defaults,
|
||||
**lookup,
|
||||
)
|
||||
if not created and organization.directory_imported_at is None:
|
||||
organization.directory_imported_at = timezone.now()
|
||||
organization.save(update_fields=["directory_imported_at"])
|
||||
return organization, created
|
||||
Reference in New Issue
Block a user