Skip to content

Commit

Permalink
handle COUNTER 5 SUSHI book reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Wooble committed Sep 16, 2019
1 parent c48b700 commit dd87167
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pycounter/sushi5.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ def raw_to_full(raw_report):
month_data=month_data,
)
)
elif report.report_type.startswith("TR_B"):
report.pubs.append(
pycounter.report.CounterBook(
title=title,
platform=platform,
publisher=publisher_name,
period=report.period,
metric="Total_Item_Requests",
issn=identifiers["issn"],
isbn=identifiers["isbn"],
doi=identifiers["doi"],
proprietary_id=identifiers["prop_id"],
month_data=month_data,
)
)
else:
raise pycounter.exceptions.UnknownReportTypeError

return report

Expand Down
21 changes: 21 additions & 0 deletions pycounter/test/counter5/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ def sushi_mock(url_unused, request_unused):
return datafile.read()


@urlmatch(netloc=r"(.*\.)?example\.com$")
def sushi_book_mock(url_unused, request_unused):
"""Mocked SUSHI service."""
path = os.path.join(os.path.dirname(__file__), "data", "sushi_book.json")
with io.open(path, "r", encoding="utf-8") as datafile:
return datafile.read()


@pytest.fixture
def trj1_report():
"""Tab-separated title report."""
Expand All @@ -25,6 +33,19 @@ def trj1_report():
)


@pytest.fixture
def sushi5_report_trb1():
"""JSON SUSHI report."""
with HTTMock(sushi_book_mock):
return pycounter.sushi.get_report(
url="http://www.example.com/Sushi",
start_date=datetime.date(2019, 1, 1),
end_date=datetime.date(2019, 2, 28),
release=5,
report="TR_B1",
)


@pytest.fixture
def sushi5_report_trj1():
"""JSON SUSHI report."""
Expand Down
86 changes: 86 additions & 0 deletions pycounter/test/counter5/data/sushi_book.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"Report_Header": {
"Created": "2019-03-28T11:25:11Z",
"Created_By": "Example Vendor",
"Customer_ID": "exampleLibrary",
"Report_ID": "TR_B1",
"Release": "5",
"Institution_Name": "Example Library",
"Report_Name": "Book Requests (Excluding OA_Gold)",
"Report_Filters": [
{
"Name": "Begin_Date",
"Value": "2019-01-01"
},
{
"Name": "End_Date",
"Value": "2019-02-28"
}
]
},
"Report_Items": [
{
"Title": "Fake book",
"Item_ID": [
{
"Type": "Print_ISSN",
"Value": "0737-1720"
},
{
"Type": "DOI",
"Value": "some.fake.doi"
},
{
"Type": "Proprietary_ID",
"Value": "fkbook"
},
{
"Type": "ISBN",
"Value": "Book Requests (Excluding OA_Gold)"
}
],
"Platform": "ExamplePlatform",
"Publisher": "Example Publisher",
"Publisher_ID": [
{
"Type": "Proprietary",
"Value": "Example: 41"
}
],
"Performance": [
{
"Period": {
"Begin_Date": "2019-01-01",
"End_Date": "2019-01-31"
},
"Instance": [
{
"Metric_Type": "Total_Item_Requests",
"Count": 22
},
{
"Metric_Type": "Unique_Item_Requests",
"Count": 11
}
]
},
{
"Period": {
"Begin_Date": "2019-02-01",
"End_Date": "2019-02-28"
},
"Instance": [
{
"Metric_Type": "Total_Item_Requests",
"Count": 16
},
{
"Metric_Type": "Unique_Item_Requests",
"Count": 12
}
]
}
]
}
]
}
6 changes: 6 additions & 0 deletions pycounter/test/counter5/test_sushi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ def test_error_not_authorized():
assert exc.message == u"Requestor Not Authorized to Access Service"
assert exc.severity == "Error"
assert exc.code == 2000


def test_bk_data(sushi5_report_trb1):
publication = next(iter(sushi5_report_trb1))
data = [month[2] for month in publication]
assert data[0] == 22

0 comments on commit dd87167

Please sign in to comment.