fix: support grouped HSE publication API responses
This commit is contained in:
@@ -64,6 +64,47 @@ class FakeSession:
|
||||
)
|
||||
|
||||
|
||||
class GroupedPublicationsSession(FakeSession):
|
||||
def post(self, url, **kwargs):
|
||||
self.posts.append((url, kwargs))
|
||||
return FakeResponse(
|
||||
{
|
||||
"status": "ok",
|
||||
"result": {
|
||||
"more": False,
|
||||
"total": 1,
|
||||
"groupType": 2,
|
||||
"items": {
|
||||
"year": {
|
||||
"header": {"ru": "по году", "en": "by year"},
|
||||
"criteria": {"year": []},
|
||||
"items": {
|
||||
"2011": [
|
||||
{
|
||||
"id": "146366790",
|
||||
"type": "ARTICLE",
|
||||
"title": "Развитие теории самосогласованного поля",
|
||||
"year": 2011,
|
||||
"description": {"short": {"ru": "Журнал физической химии 2011."}},
|
||||
}
|
||||
],
|
||||
"2012": [
|
||||
{
|
||||
"id": "146367323",
|
||||
"type": "ARTICLE",
|
||||
"title": "Self-consistent field theory investigation",
|
||||
"year": 2012,
|
||||
"description": {"short": {"en": "Russian Journal of Physical Chemistry A 2012."}},
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_normalize_profile_url_supports_staff_and_org_persons():
|
||||
assert normalize_profile_url("/staff/avsergeev#sci") == "https://www.hse.ru/staff/avsergeev"
|
||||
assert normalize_profile_url("https://www.hse.ru/org/persons/123/") == "https://www.hse.ru/org/persons/123"
|
||||
@@ -117,3 +158,29 @@ def test_enrich_sections_from_hse_widgets_loads_publications_and_vkr():
|
||||
assert theses["theses"][0]["project_url"] == "https://www.hse.ru/edu/vkr/1045750164"
|
||||
assert session.posts[0][0] == "https://publications.hse.ru/api/searchPubs"
|
||||
assert session.gets[0][1]["params"] == {"supervisorId": "803294906"}
|
||||
|
||||
|
||||
def test_enrich_sections_from_hse_widgets_loads_grouped_publications():
|
||||
soup = BeautifulSoup(
|
||||
"""
|
||||
<script src="/n/stat/publications/dist-w/publs.js" data-author="133709486" data-widget-name="AuthorSearch"></script>
|
||||
""",
|
||||
"html.parser",
|
||||
)
|
||||
session = GroupedPublicationsSession()
|
||||
|
||||
sections = enrich_sections_from_hse_widgets(
|
||||
session,
|
||||
soup,
|
||||
"https://www.hse.ru/org/persons/133709486",
|
||||
{"User-Agent": "test"},
|
||||
10,
|
||||
[],
|
||||
)
|
||||
|
||||
publications = next(section for section in sections if section["type"] == "publications")
|
||||
|
||||
assert publications["publications_count"] == 2
|
||||
assert [item["id"] for item in publications["publications"]] == ["146366790", "146367323"]
|
||||
assert publications["publications"][0]["url"] == "https://publications.hse.ru/view/146366790"
|
||||
assert publications["publications"][1]["url"] == "https://publications.hse.ru/view/146367323"
|
||||
|
||||
Reference in New Issue
Block a user