Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from MITLibraries/name-dlc
Browse files Browse the repository at this point in the history
Add DLC to author
  • Loading branch information
Mike Graves committed Sep 23, 2020
2 parents 3e52ec1 + 339b57b commit f3c31d4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
5 changes: 3 additions & 2 deletions hoard/names/db.py
Expand Up @@ -13,7 +13,7 @@


authors = Table(
"library_person_lookup",
"hr_person_employee_limited",
metadata,
Column("mit_id", String),
Column("first_name", Unicode),
Expand All @@ -22,13 +22,14 @@
Column("full_name", Unicode),
Column("krb_name", String),
Column("email", String),
Column("directory_org_unit_title", String),
)


orcids = Table(
"orcid_to_mitid",
metadata,
Column("mit_id", String, ForeignKey("library_person_lookup.mit_id")),
Column("mit_id", String, ForeignKey("hr_person_employee_limited.mit_id")),
Column("orcid", String),
)

Expand Down
13 changes: 11 additions & 2 deletions hoard/names/repository.py
Expand Up @@ -20,10 +20,19 @@ def find(self, last: str, first: str = "", middle: str = "") -> Iterable[Author]
query.append(authors.c.middle_name.like(middle[0] + "%"))
sql = (
select(
[authors.c.krb_name.label("kerb"), authors.c.full_name, orcids.c.orcid]
[
authors.c.krb_name.label("kerb"),
authors.c.full_name.label("name"),
orcids.c.orcid,
authors.c.directory_org_unit_title.label("dlc"),
]
)
.select_from(authors.outerjoin(orcids))
.where(and_(*query))
.limit(10)
)
with closing(self.engine.connect()) as conn:
yield from conn.execute(sql)
yield from (
Author(kerb=row.kerb, name=row.name, orcid=row.orcid, dlc=row.dlc)
for row in conn.execute(sql)
)
8 changes: 4 additions & 4 deletions hoard/names/types.py
@@ -1,11 +1,11 @@
from typing import Iterable, Protocol
from typing_extensions import TypedDict
from typing import Iterable, Optional, Protocol, TypedDict


class Author(TypedDict):
kerb: str
full_name: str
orcid: str
name: str
orcid: Optional[str]
dlc: str


class Searchable(Protocol):
Expand Down
12 changes: 8 additions & 4 deletions tests/data/warehouse.json
Expand Up @@ -7,7 +7,8 @@
"last_name": "Durance",
"full_name": "Durance, Honor E",
"krb_name": "honor",
"email": "honor@example.com"
"email": "honor@example.com",
"directory_org_unit_title": "Philosophy"
},
{
"mit_id": "900000001",
Expand All @@ -16,7 +17,8 @@
"last_name": "Briggs",
"full_name": "Briggs, Increase D",
"krb_name": "increase",
"email": "increase@example.com"
"email": "increase@example.com",
"directory_org_unit_title": "Architecture"
},
{
"mit_id": "900000002",
Expand All @@ -25,7 +27,8 @@
"last_name": "Joiner",
"full_name": "Joiner, Temperance F",
"krb_name": "temperance",
"email": "temperance@example.com"
"email": "temperance@example.com",
"directory_org_unit_title": "Physics"
},
{
"mit_id": "900000003",
Expand All @@ -34,7 +37,8 @@
"last_name": "Joiner",
"full_name": "Joiner, Silence G",
"krb_name": "silence",
"email": "silence@example.com"
"email": "silence@example.com",
"directory_org_unit_title": "Math"
}
],
"orcids": [
Expand Down
37 changes: 32 additions & 5 deletions tests/names/test_repository.py
Expand Up @@ -6,14 +6,41 @@ def test_warehouse_finds_author(warehouse_data):
warehouse = Warehouse(engine())

results = list(warehouse.find(first="Temper", middle="F", last="Joiner"))
assert results == [("temperance", "Joiner, Temperance F", None)]
assert results == [
{
"kerb": "temperance",
"name": "Joiner, Temperance F",
"orcid": None,
"dlc": "Physics",
}
]

results = list(warehouse.find(first="", middle="", last="Joiner"))
assert ("temperance", "Joiner, Temperance F", None) in results
assert ("silence", "Joiner, Silence G", None) in results
assert {
"kerb": "temperance",
"name": "Joiner, Temperance F",
"orcid": None,
"dlc": "Physics",
} in results
assert {
"kerb": "silence",
"name": "Joiner, Silence G",
"orcid": None,
"dlc": "Math",
} in results

results = list(warehouse.find(first="I", middle="D", last="Briggs"))
assert ("increase", "Briggs, Increase D", "0000-0000-0001") in results
assert {
"kerb": "increase",
"name": "Briggs, Increase D",
"orcid": "0000-0000-0001",
"dlc": "Architecture",
} in results

results = list(warehouse.find(last="Durance"))
assert ("honor", "Durance, Honor E", "0000-0000-0000") in results
assert {
"kerb": "honor",
"name": "Durance, Honor E",
"orcid": "0000-0000-0000",
"dlc": "Philosophy",
} in results

0 comments on commit f3c31d4

Please sign in to comment.