-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from freud-digital/5-refactor-fetch_entitiy
5 refactor fetch entitiy
- Loading branch information
Showing
8 changed files
with
279 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ max-line-length = 120 | |
exclude = | ||
.git, | ||
build, | ||
env | ||
env | ||
play.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"count": 1, | ||
"next": null, | ||
"previous": null, | ||
"results": [ | ||
{ | ||
"id": 21, | ||
"order": "21.00000000000000000000", | ||
"name": "Freud, Sigmund", | ||
"frd_id": "frd_person_21", | ||
"gnd_id": "https://d-nb.info/gnd/118535315", | ||
"birth_year": "1856", | ||
"place_of_birth": [ | ||
{ | ||
"id": 1, | ||
"value": "Příbor" | ||
} | ||
], | ||
"death_year": "1939", | ||
"place_of_death": [ | ||
{ | ||
"id": 2, | ||
"value": "London" | ||
} | ||
], | ||
"bio": "", | ||
"profession": [], | ||
"pmb": "", | ||
"labels": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
[ | ||
{ | ||
"key": "V9N337QB", | ||
"version": 50, | ||
"library": { | ||
"type": "group", | ||
"id": 4690432, | ||
"name": "sigmund-freud", | ||
"links": { | ||
"alternate": { | ||
"href": "https://www.zotero.org/groups/sigmund-freud", | ||
"type": "text/html" | ||
} | ||
} | ||
}, | ||
"links": { | ||
"self": { | ||
"href": "https://api.zotero.org/groups/4690432/items/V9N337QB", | ||
"type": "application/json" | ||
}, | ||
"alternate": { | ||
"href": "https://www.zotero.org/groups/sigmund-freud/items/V9N337QB", | ||
"type": "text/html" | ||
} | ||
}, | ||
"meta": { | ||
"createdByUser": { | ||
"id": 9548878, | ||
"username": "ch2103", | ||
"name": "", | ||
"links": { | ||
"alternate": { | ||
"href": "https://www.zotero.org/ch2103", | ||
"type": "text/html" | ||
} | ||
} | ||
}, | ||
"creatorSummary": "Breuer and Freud", | ||
"parsedDate": "1895", | ||
"numChildren": 0 | ||
}, | ||
"data": { | ||
"key": "V9N337QB", | ||
"version": 50, | ||
"itemType": "book", | ||
"title": "Studien über Hysterie", | ||
"creators": [ | ||
{ | ||
"creatorType": "author", | ||
"firstName": "Josef", | ||
"lastName": "Breuer" | ||
}, | ||
{ | ||
"creatorType": "author", | ||
"firstName": "Sigmund", | ||
"lastName": "Freud" | ||
} | ||
], | ||
"abstractNote": "", | ||
"series": "", | ||
"seriesNumber": "", | ||
"volume": "", | ||
"numberOfVolumes": "", | ||
"edition": "", | ||
"place": "Leipzig Wien", | ||
"publisher": "Deuticke", | ||
"date": "1895", | ||
"numPages": "269", | ||
"language": "ger", | ||
"ISBN": "", | ||
"shortTitle": "", | ||
"url": "http://phaidra.univie.ac.at/o:350215", | ||
"accessDate": "2022-07-19T11:05:41Z", | ||
"archive": "", | ||
"archiveLocation": "", | ||
"libraryCatalog": "usearch.univie.ac.at", | ||
"callNumber": "I-176203", | ||
"rights": "", | ||
"extra": "", | ||
"tags": [ | ||
{ | ||
"tag": "Fallstudiensammlung", | ||
"type": 1 | ||
}, | ||
{ | ||
"tag": "Hysterie", | ||
"type": 1 | ||
}, | ||
{ | ||
"tag": "Psychoanalyse", | ||
"type": 1 | ||
} | ||
], | ||
"collections": [], | ||
"relations": {}, | ||
"dateAdded": "2022-07-19T11:06:44Z", | ||
"dateModified": "2022-07-19T11:06:44Z" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import unittest | ||
import json | ||
import os | ||
|
||
from .utils import zotero_description, populate_baserow_response, populate_zotero_response | ||
|
||
file_path = os.path.dirname(os.path.realpath(__file__)) | ||
fixtures_path = os.path.join(file_path, 'fixtures') | ||
|
||
with open(os.path.join(fixtures_path, "zotero.json")) as f: | ||
zotero_data = json.load(f) | ||
|
||
with open(os.path.join(fixtures_path, "baserow.json")) as f: | ||
baserow_data = json.load(f) | ||
|
||
|
||
class TestUtilityFunctions(unittest.TestCase): | ||
|
||
def test_zotero_description(self): | ||
item_data = zotero_data[0]['data'] | ||
data = zotero_description(item_data) | ||
print(data) | ||
self.assertEqual(data['id'], '#frd_bibl_V9N337QB') | ||
self.assertTrue(data['value'].startswith('Studien über Hysterie')) | ||
|
||
def test_populate_zotero_response(self): | ||
data = populate_zotero_response(zotero_data, "select2") | ||
keys = data['results'][0].keys() | ||
self.assertIn('id', keys) | ||
data = populate_zotero_response(zotero_data) | ||
keys = data['tc:suggestion'][0].keys() | ||
self.assertIn('tc:description', keys) | ||
data = populate_zotero_response(zotero_data, format='original') | ||
keys = data['result'][0].keys() | ||
self.assertIn('key', keys) | ||
|
||
def test_baserow_population_select2(self): | ||
data = populate_baserow_response(baserow_data, format="select2") | ||
keys = data['results'][0].keys() | ||
self.assertIn('id', keys) | ||
|
||
def test_baserow_population_teicompleter(self): | ||
data = populate_baserow_response(baserow_data) | ||
keys = data['tc:suggestion'][0].keys() | ||
self.assertIn('tc:description', keys) | ||
self.assertTrue('tc:description', 'Freud, Sigmund') | ||
|
||
def test_baserow_population_original(self): | ||
data = populate_baserow_response(baserow_data, format='original') | ||
keys = data['results']['results'][0].keys() | ||
self.assertIn('frd_id', keys) | ||
self.assertTrue(data['results']['results'][0]['name'], 'Freud, Sigmund') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
def zotero_description(item_data: dict) -> dict: | ||
item_title = item_data.get('title', 'no title provided') | ||
item_place = item_data.get('place', 'no place provided') | ||
item_date = item_data.get('date', 'no date provided') | ||
item_id = f"#frd_bibl_{item_data['key']}" | ||
item_description = f"{item_title}, {item_place}, {item_date}" | ||
return { | ||
"id": item_id, | ||
"value": item_description | ||
} | ||
|
||
|
||
def populate_zotero_response(data: list, format: str = "teicompleter") -> dict: | ||
if format == 'select2': | ||
result = { | ||
"results": [], | ||
} | ||
for x in data: | ||
item_data = zotero_description(x['data']) | ||
item = { | ||
"id": item_data['id'], | ||
"text": item_data['value'] | ||
} | ||
result['results'].append(item) | ||
return result | ||
|
||
elif format == 'original': | ||
return { | ||
"result": data | ||
} | ||
else: | ||
result = { | ||
"tc:suggestion": [] | ||
} | ||
for x in data: | ||
item_data = zotero_description(x['data']) | ||
item = { | ||
"tc:value": item_data['id'], | ||
"tc:description": item_data['value'] | ||
} | ||
result['tc:suggestion'].append(item) | ||
return result | ||
|
||
|
||
def populate_baserow_response(data: dict, format: str = "teicompleter") -> dict: | ||
if format == 'select2': | ||
result = { | ||
"results": [], | ||
} | ||
for x in data['results']: | ||
item = { | ||
"id": f"#{x['frd_id']}", | ||
"text": x['name'] | ||
} | ||
result['results'].append(item) | ||
|
||
return result | ||
|
||
elif format == 'original': | ||
|
||
return { | ||
"results": data | ||
} | ||
|
||
else: | ||
result = { | ||
"tc:suggestion": [] | ||
} | ||
for x in data['results']: | ||
item = { | ||
"tc:value": f"#{x['frd_id']}", | ||
"tc:description": x['name'] | ||
} | ||
result['tc:suggestion'].append(item) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#/bin/bash | ||
|
||
coverage run -m pytest -v | ||
coverage report | ||
coverage html | ||
xdg-open ./htmlcov/index.html |