Skip to content

Commit 3e4fe8e

Browse files
authored
update person (#505)
2 parents 94404cc + 3d7aad8 commit 3e4fe8e

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/connectors/example/resources/resource/persons.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"keyword2"
3737
],
3838
"relevant_link": ["https://www.example.com/a_relevant_link", "https://www.example.com/another_relevant_link"],
39-
"language": [
39+
"languages": [
4040
"eng",
4141
"fra",
4242
"spa"
@@ -68,6 +68,7 @@
6868
"Voice Recognition",
6969
"Computer Vision."
7070
],
71-
"price_per_hour_euro": 75.5
71+
"price_per_hour_euro": 75.5,
72+
"member_of": []
7273
}
7374
]

src/database/model/agent/person.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from database.model.agent.contact import Contact
88
from database.model.agent.expertise import Expertise
99
from database.model.agent.language import Language
10+
from database.model.agent.organisation import Organisation
1011
from database.model.concept.aiod_entry import AIoDEntryORM
1112
from database.model.field_length import NORMAL
1213
from database.model.helper_functions import many_to_many_link_factory
@@ -50,11 +51,14 @@ class Person(PersonBase, Agent, table=True): # type: ignore [call-arg]
5051
expertise: list[Expertise] = Relationship(
5152
link_model=many_to_many_link_factory("person", Expertise.__tablename__)
5253
)
53-
language: list[Language] = Relationship(
54+
languages: list[Language] = Relationship(
5455
link_model=many_to_many_link_factory("person", Language.__tablename__)
5556
)
5657
contact_details: Optional[Contact] = Relationship(sa_relationship_kwargs={"uselist": False})
57-
# TODO(jos): memberOf? This should probably be on Agent
58+
59+
member_of: list[Organisation] = Relationship(
60+
link_model=many_to_many_link_factory("person", Organisation.__tablename__)
61+
)
5862

5963
class RelationshipConfig(Agent.RelationshipConfig):
6064
contact_details: int | None = OneToOne(
@@ -70,14 +74,22 @@ class RelationshipConfig(Agent.RelationshipConfig):
7074
default_factory_pydantic=list,
7175
on_delete_trigger_orphan_deletion=list,
7276
)
73-
language: list[str] = ManyToMany(
77+
languages: list[str] = ManyToMany(
7478
description="A language this person masters, in ISO639-3",
7579
_serializer=AttributeSerializer("name"),
7680
deserializer=FindByNameDeserializerList(Language),
7781
example=["eng", "fra", "spa"],
7882
default_factory_pydantic=list,
7983
)
8084

85+
member_of: list[int] = ManyToMany(
86+
description="The list of Organisations that a Person affiliates with.",
87+
_serializer=AttributeSerializer("identifier"),
88+
deserializer=FindByIdentifierDeserializerList(Organisation),
89+
example=[],
90+
default_factory_pydantic=list,
91+
)
92+
8193

8294
deserializer_list = FindByIdentifierDeserializerList(Person)
8395
AIoDEntryORM.RelationshipConfig.editor.deserializer = deserializer_list # type: ignore

src/tests/routers/resource_routers/test_router_person.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from authentication import keycloak_openid
88
from database.model.agent.contact import Contact
99
from database.model.agent.person import Person
10+
from database.model.agent.organisation import Organisation
1011
from database.model.platform.platform import Platform
1112
from database.session import DbSession
1213
from tests.testutils.default_sqlalchemy import AI4EUROPE_CMS_TOKEN
@@ -18,19 +19,23 @@ def test_happy_path(
1819
body_agent: dict,
1920
person: Person,
2021
contact: Contact,
22+
organisation: Organisation,
23+
2124
):
2225
with DbSession() as session:
2326
person.platform_resource_identifier = "2"
2427
session.add(person)
2528
session.add(contact)
29+
session.merge(organisation)
2630
session.commit()
2731

2832
body = copy.copy(body_agent)
2933
body["expertise"] = ["machine learning"]
30-
body["language"] = ["eng", "nld"]
34+
body["languages"] = ["eng", "nld"]
3135
body["price_per_hour_euro"] = 10.50
3236
body["wants_to_be_contacted"] = True
3337
body["contact_details"] = 1
38+
body["member_of"] = [1]
3439

3540
response = client.post("/persons/v1", json=body, headers={"Authorization": "Fake token"})
3641
assert response.status_code == 200, response.json()
@@ -40,15 +45,16 @@ def test_happy_path(
4045

4146
response_json = response.json()
4247
assert response_json["identifier"] == 2
43-
assert response_json["ai_resource_identifier"] == 2
44-
assert response_json["agent_identifier"] == 2
48+
assert response_json["ai_resource_identifier"] == 3
49+
assert response_json["agent_identifier"] == 3
4550

4651
assert set(response_json["expertise"]) == {"machine learning"}
47-
assert set(response_json["language"]) == {"eng", "nld"}
52+
assert set(response_json["languages"]) == {"eng", "nld"}
4853

4954
assert response_json["price_per_hour_euro"] == 10.50
5055
assert response_json["wants_to_be_contacted"]
5156
assert response_json["contact_details"] == 1
57+
assert response_json["member_of"] == [1]
5258

5359

5460
@pytest.fixture(

0 commit comments

Comments
 (0)