Skip to content

Commit c7f19fa

Browse files
Add circuit contributions (#325)
1 parent 9afc52f commit c7f19fa

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

app/schemas/scientific_artifact.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
LicenseCreateMixin,
1717
LicenseReadMixin,
1818
)
19+
from app.schemas.contribution import ContributionReadWithoutEntityMixin
1920
from app.schemas.subject import SubjectCreateMixin, SubjectReadMixin
2021

2122

@@ -45,6 +46,7 @@ class ScientificArtifactRead(
4546
CreationMixin,
4647
LicenseReadMixin,
4748
AssetsMixin,
49+
ContributionReadWithoutEntityMixin,
4850
):
4951
pass
5052

app/service/circuit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from app.db.model import (
88
Agent,
99
Circuit,
10+
Contribution,
1011
Subject,
1112
)
1213
from app.dependencies.auth import UserContextDep, UserContextWithProjectIdDep
@@ -37,6 +38,8 @@ def _load(query: sa.Select):
3738
joinedload(Circuit.brain_region),
3839
joinedload(Circuit.created_by),
3940
joinedload(Circuit.updated_by),
41+
selectinload(Circuit.contributions).joinedload(Contribution.agent),
42+
selectinload(Circuit.contributions).joinedload(Contribution.role),
4043
selectinload(Circuit.assets),
4144
raiseload("*"),
4245
)

tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
USER_SUB_ID_2,
6363
VIRTUAL_LAB_ID,
6464
ClientProxy,
65+
add_contribution,
6566
add_db,
6667
assert_request,
6768
create_electrical_cell_recording_id_with_assets,
@@ -957,8 +958,8 @@ def circuit_json_data(brain_atlas_id, root_circuit, subject_id, brain_region_id,
957958

958959

959960
@pytest.fixture
960-
def circuit(db, circuit_json_data, person_id):
961-
return add_db(
961+
def circuit(db, circuit_json_data, person_id, role_id):
962+
circuit = add_db(
962963
db,
963964
Circuit(
964965
**circuit_json_data
@@ -969,6 +970,8 @@ def circuit(db, circuit_json_data, person_id):
969970
}
970971
),
971972
)
973+
add_contribution(db, circuit.id, person_id, role_id, person_id)
974+
return circuit
972975

973976

974977
@pytest.fixture

tests/test_circuit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_create_one(client, circuit_json_data):
5757
def test_read_one(client, circuit, circuit_json_data):
5858
data = assert_request(client.get, url=f"{ROUTE}/{circuit.id}").json()
5959
_assert_read_response(data, circuit_json_data)
60+
assert len(data["contributions"]) == 1
6061

6162

6263
def test_read_many(client, circuit, circuit_json_data):

tests/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from app.db.model import (
1212
BrainRegion,
1313
BrainRegionHierarchy,
14+
Contribution,
1415
ElectricalCellRecording,
1516
ElectricalRecordingStimulus,
1617
ETypeClass,
@@ -558,3 +559,16 @@ def check_creation_fields(data: dict):
558559
assert data["update_date"] == ANY
559560
assert data["created_by"]["id"] == ANY
560561
assert data["updated_by"]["id"] == ANY
562+
563+
564+
def add_contribution(db, entity_id, agent_id, role_id, created_by_id):
565+
return add_db(
566+
db,
567+
Contribution(
568+
agent_id=agent_id,
569+
role_id=role_id,
570+
entity_id=entity_id,
571+
created_by_id=created_by_id,
572+
updated_by_id=created_by_id,
573+
),
574+
)

0 commit comments

Comments
 (0)