Skip to content
Snippets Groups Projects
Verified Commit 75d7c2e1 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

just in case

parent 17cbacd5
No related branches found
No related tags found
No related merge requests found
Pipeline #108420 failed
This commit is part of merge request !227. Comments created here will be created in the context of that merge request.
......@@ -40,6 +40,7 @@ class Command(BaseCommand):
organizational_unit=unit,
source=self.CEREBRUM_SOURCE,
automatic=True,
hierarchical_access=False,
)
if created:
logger.info("sponsor_ou_link_create", sponsor=sponsor.id, sunit=sunit.id)
......@@ -119,7 +120,7 @@ class Command(BaseCommand):
active_units = OrganizationalUnit.objects.filter(
active=True,
deleted=False,
)
).exclude(identifiers__value__in=[])
logger.info("import_start", nr_of_units=len(active_units))
for unit in active_units:
......
......@@ -163,12 +163,20 @@ def unit_foo() -> OrganizationalUnit:
@pytest.fixture
def ouidentifier_foo(unit_foo) -> OuIdentifier:
ouid = OuIdentifier.objcets.create(
ouid = OuIdentifier.objects.create(
source="orgreg", name="orgreg", value="12345", orgunit=unit_foo
)
return OuIdentifier.objects.get(id=ouid.id)
@pytest.fixture
def ouidentifier_foo2(unit_foo) -> OuIdentifier:
ouid = OuIdentifier.objects.create(
source="orgreg", name="legacy_stedkode", value="12345", orgunit=unit_foo
)
return OuIdentifier.objects.get(id=ouid.id)
@pytest.fixture
def role_person_foo(
person_foo: Person,
......
import datetime
from cerebrum_client.models import Group
import pytest
from django.conf import settings
from django.core.management import call_command
from greg.models import Sponsor
class MockResponse:
def __init__(self, response):
self.response = response
def json(self):
return self.response
@pytest.fixture
def cerebrum_response():
created_at = (datetime.datetime.now() - datetime.timedelta(days=1)).isoformat()
return MockResponse(
f"""{{"href": "", "id": 1, "name": "", "description": "",
"created_at": "{created_at}",
"contexts": ["das"],
"visibility": "",
"moderators": ""}}"""
)
@pytest.fixture
def group_members_response():
return MockResponse("""{"members":[{"href": "asd", "type": "person", "id": 1}]}""")
@pytest.fixture
def person_response():
return MockResponse(
"""{
"contexts": [""],
"href": "",
"names": [
{"source_system":"DFO_SAP", "variant": "FIRST", "name": "Ola"},
{"source_system":"DFO_SAP", "variant": "LAST", "name": "Nordmann"}
],
"id": 1}"""
)
@pytest.fixture
def account_response():
return MockResponse(
"""{"accounts": [{
"href": "",
"primary": true,
"id": 1,
"name": "olanord"}]}"""
)
@pytest.mark.django_db
def test_import_sponsors_from_cerebrum(
requests_mock,
cerebrum_response,
group_members_response,
person_response,
account_response,
sponsor_org_unit,
ouidentifier_foo2,
):
settings.CEREBRUM_CLIENT = {
"url": "http://example.com/cerebrum/",
"headers": {"X-Gravitee-Api-Key": "fake-key"},
}
requests_mock.get(
"http://example.com/cerebrum/v1/groups/adm-leder-12345",
text=cerebrum_response.json(),
)
requests_mock.get(
"http://example.com/cerebrum/v1/groups/adm-leder-12345/members/",
text=group_members_response.json(),
)
requests_mock.get(
"http://example.com/cerebrum/v1/persons/1",
text=person_response.json(),
)
requests_mock.get(
"http://example.com/cerebrum/v1/persons/1/accounts",
text=account_response.json(),
)
assert Sponsor.objects.all().count() == 1
call_command("import_sponsors_from_cerebrum")
assert Sponsor.objects.all().count() == 2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment