Skip to content

Commit

Permalink
update notes in task
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr KOZAREV committed Oct 15, 2024
1 parent 9468264 commit 5cabb0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion core/lcsb/rems.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,8 @@ def bulk_update_rems_external_ids():
for access in accesses:
external_id = get_rems_external_id(access.application_id)
access.application_external_id = external_id
Access.objects.bulk_update(accesses, ["application_external_id"])
access.access_notes = build_access_notes_rems(
access.application_id, external_id
)
Access.objects.bulk_update(accesses, ["application_external_id", "access_notes"])
logger.info(f"REMS :: Accesses updated: {len(accesses)}")
19 changes: 16 additions & 3 deletions core/tests/test_lcsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,29 @@ def test_update_accesses_external_id(caplog):
with requests_mock.Mocker() as m:
m.get(
rems_url + f"api/applications/{access_0.application_id}",
json={"application/external-id": "0"},
json={"application/external-id": "new_external_id-0"},
)
m.get(
rems_url + f"api/applications/{access_1.application_id}",
json={"application/external-id": "1"},
json={"application/external-id": "new_external_id-1"},
)
m.get(
rems_url + f"api/applications/{access_2.application_id}",
json={"application/external-id": "2"},
json={"application/external-id": "new_external_id-2"},
)
bulk_update_rems_external_ids()

assert "REMS :: Accesses updated: 1" in caplog.text

updated_access_0 = Access.objects.get(id=access_0.id)
assert not updated_access_0.application_external_id

updated_access_1 = Access.objects.get(id=access_1.id)
assert updated_access_1.application_external_id == "new_external_id-1"
assert (
updated_access_1.access_notes
== f"Set automatically by REMS data access request #{access_1.id} (new_external_id-1)"
)

updated_access_2 = Access.objects.get(id=access_2.id)
assert updated_access_2.application_external_id == access_2.application_external_id
1 change: 1 addition & 0 deletions test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Meta:
model = "core.Access"
django_get_or_create = ("user",)

id = factory.Sequence(lambda n: n)
access_notes = factory.Faker("sentence")
dataset = factory.SubFactory(DatasetFactory)
user = factory.SubFactory(UserFactory)
Expand Down

0 comments on commit 5cabb0a

Please sign in to comment.