Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 30356c7

Browse files
committed
#19 Get usage report business unit
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent d82f6d0 commit 30356c7

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

bintray/bintray.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,3 +3000,30 @@ def get_usage_report_for_package(self, subject, repo, package=None, start_pos=50
30003000
response = self._requester.post(url, json=json_data, params=params)
30013001
self._logger.info("Search successfully")
30023002
return response
3003+
3004+
def get_usage_report_grouped_by_business_unit(self, subject, business_unit=None, from_date=None,
3005+
to_date=None):
3006+
""" Get monthly download and storage usage report, according to the specified date range
3007+
and grouped by business unit. Report can be requested for a subject or for a specific
3008+
subject business unit.
3009+
3010+
Security: Authenticated user with 'admin' permission.
3011+
3012+
:param subject: repository owner
3013+
:param business_unit: business unit name
3014+
:param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3015+
:param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3016+
:return: download details
3017+
"""
3018+
url = "{}/usage/business_unit_usage/{}".format(Bintray.BINTRAY_URL, subject)
3019+
if business_unit:
3020+
url += "/{}".format(business_unit)
3021+
json_data = {}
3022+
if from_date:
3023+
json_data["from"] = from_date
3024+
if to_date:
3025+
json_data["to"] = to_date
3026+
3027+
response = self._requester.post(url, json=json_data)
3028+
self._logger.info("Search successfully")
3029+
return response

tests/test_statistics.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,14 @@ def test_get_usage_report_for_package():
6565
error_message = str(error)
6666
assert "Could not POST (403): This resource is only available for Premium repositories" \
6767
== error_message
68+
69+
70+
def test_get_usage_report_grouped_by_business_unit():
71+
bintray = Bintray()
72+
error_message = ""
73+
try:
74+
bintray.get_usage_report_grouped_by_business_unit("uilianries", "generic")
75+
except Exception as error:
76+
error_message = str(error)
77+
assert "Could not POST (403): This resource is only available for Enterprise users" \
78+
== error_message

0 commit comments

Comments
 (0)