licensing 0.54__tar.gz → 0.56__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {licensing-0.54/licensing.egg-info → licensing-0.56}/PKG-INFO +2 -2
- {licensing-0.54 → licensing-0.56}/README.md +41 -36
- {licensing-0.54 → licensing-0.56}/licensing/methods.py +158 -0
- {licensing-0.54 → licensing-0.56/licensing.egg-info}/PKG-INFO +2 -2
- {licensing-0.54 → licensing-0.56}/setup.py +2 -2
- {licensing-0.54 → licensing-0.56}/tests/test_ai_usage_analytics.py +176 -128
- {licensing-0.54 → licensing-0.56}/LICENSE.txt +0 -0
- {licensing-0.54 → licensing-0.56}/LicenseFile.skm +0 -0
- {licensing-0.54 → licensing-0.56}/licensing/__init__.py +0 -0
- {licensing-0.54 → licensing-0.56}/licensing/internal.py +0 -0
- {licensing-0.54 → licensing-0.56}/licensing/models.py +0 -0
- {licensing-0.54 → licensing-0.56}/licensing.egg-info/SOURCES.txt +0 -0
- {licensing-0.54 → licensing-0.56}/licensing.egg-info/dependency_links.txt +0 -0
- {licensing-0.54 → licensing-0.56}/licensing.egg-info/top_level.txt +0 -0
- {licensing-0.54 → licensing-0.56}/setup.cfg +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: licensing
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.56
|
|
4
4
|
Home-page: https://devolens.com
|
|
5
|
-
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/
|
|
5
|
+
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/v_56.tar.gz
|
|
6
6
|
Author: Cryptolens AB
|
|
7
7
|
Author-email: help@devolens.com
|
|
8
8
|
License: MIT
|
|
@@ -157,7 +157,7 @@ else:
|
|
|
157
157
|
print("License expires: " + str(license_key.expires))
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
### Create Trial Key (verified trial)
|
|
160
|
+
### Create Trial Key (verified trial)
|
|
161
161
|
|
|
162
162
|
#### Idea
|
|
163
163
|
|
|
@@ -198,41 +198,46 @@ else:
|
|
|
198
198
|
|
|
199
199
|
license_key = result[0]
|
|
200
200
|
print("Feature 1: " + str(license_key.f1))
|
|
201
|
-
print("License expires: " + str(license_key.expires))
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
### Usage analytics
|
|
205
|
-
|
|
206
|
-
The SDK can retrieve the aggregate usage analytics endpoints from the `AI` class. These methods return a tuple of `(items, message)`, where `items` is a list of dictionaries using the API's camelCase JSON field names.
|
|
207
|
-
|
|
208
|
-
```python
|
|
209
|
-
from licensing.methods import AI
|
|
210
|
-
|
|
211
|
-
result = AI.get_daily_aggregates(
|
|
212
|
-
token="ACCESS_TOKEN_WITH_USAGE_ANALYTICS_PERMISSION",
|
|
213
|
-
product_id=YOUR_PRODUCT_ID,
|
|
214
|
-
start="2026-05-01",
|
|
215
|
-
end="2026-05-31"
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
if result[0] == None:
|
|
219
|
-
print("An error occurred: {0}".format(result[1]))
|
|
220
|
-
else:
|
|
221
|
-
for aggregate in result[0]:
|
|
222
|
-
print(aggregate["date"], aggregate["totalRequestsLogged"])
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
Available usage analytics methods:
|
|
226
|
-
|
|
227
|
-
* `AI.get_daily_aggregates`
|
|
228
|
-
* `AI.get_daily_country_aggregates`
|
|
229
|
-
* `AI.get_key_usage_summaries`
|
|
230
|
-
* `AI.get_key_devices`
|
|
231
|
-
* `AI.get_license_activity_buckets`
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
201
|
+
print("License expires: " + str(license_key.expires))
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Usage analytics
|
|
205
|
+
|
|
206
|
+
The SDK can retrieve the aggregate usage analytics endpoints from the `AI` class. These methods return a tuple of `(items, message)`, where `items` is a list of dictionaries using the API's camelCase JSON field names.
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from licensing.methods import AI
|
|
210
|
+
|
|
211
|
+
result = AI.get_daily_aggregates(
|
|
212
|
+
token="ACCESS_TOKEN_WITH_USAGE_ANALYTICS_PERMISSION",
|
|
213
|
+
product_id=YOUR_PRODUCT_ID,
|
|
214
|
+
start="2026-05-01",
|
|
215
|
+
end="2026-05-31"
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
if result[0] == None:
|
|
219
|
+
print("An error occurred: {0}".format(result[1]))
|
|
220
|
+
else:
|
|
221
|
+
for aggregate in result[0]:
|
|
222
|
+
print(aggregate["date"], aggregate["totalRequestsLogged"])
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Available usage analytics methods:
|
|
226
|
+
|
|
227
|
+
* `AI.get_daily_aggregates`
|
|
228
|
+
* `AI.get_daily_country_aggregates`
|
|
229
|
+
* `AI.get_key_usage_summaries`
|
|
230
|
+
* `AI.get_key_devices`
|
|
231
|
+
* `AI.get_license_activity_buckets`
|
|
232
|
+
|
|
233
|
+
The following license reports return `(report, message)`, with the license rows and pagination details in the `report` dictionary.
|
|
234
|
+
|
|
235
|
+
* `AI.get_floating_capacity_licenses(token, product_id, interval_start_utc, min_utilization_percent=90)` finds licenses using at least 90% of their floating seats. Supply the start of a 30-minute UTC interval in Unix seconds. Omit `capacity_mode` to include licenses below, at, and above their seat limit.
|
|
236
|
+
* `AI.get_expiring_licenses(token, window="90d", last_seen_days=30)` finds licenses expiring in the next 90 days whose last recorded API activity was more than 30 days ago. Follow `report["pageActivity"]["nextPage"]` until it is `None`, even if a page has no matches.
|
|
237
|
+
|
|
238
|
+
### License server or custom endpoint
|
|
239
|
+
|
|
240
|
+
To forward requests to a local license server or a different API, you can set it using the `server_address` in HelperMethods, i.e.,
|
|
236
241
|
|
|
237
242
|
```python
|
|
238
243
|
HelperMethods.server_address = "http://localhost:8080/api/";
|
|
@@ -642,6 +642,10 @@ class AI:
|
|
|
642
642
|
else:
|
|
643
643
|
return (None, "Could not contact the server.")
|
|
644
644
|
|
|
645
|
+
# Reports need their summary and paging fields as well as the rows.
|
|
646
|
+
if result_field is None:
|
|
647
|
+
return (jobj, "")
|
|
648
|
+
|
|
645
649
|
return (jobj[result_field], "")
|
|
646
650
|
|
|
647
651
|
@staticmethod
|
|
@@ -756,6 +760,160 @@ class AI:
|
|
|
756
760
|
"Start": start,\
|
|
757
761
|
"End": end})
|
|
758
762
|
|
|
763
|
+
@staticmethod
|
|
764
|
+
def get_floating_capacity(token, product_id=0, start="", end="",
|
|
765
|
+
capacity_mode="exceeded", granularity="day",
|
|
766
|
+
page=1, limit=100):
|
|
767
|
+
"""
|
|
768
|
+
Retrieve excess or unused floating-license capacity by product and period.
|
|
769
|
+
Requires Usage Analytics permission. Use product_id=0 for all products
|
|
770
|
+
allowed by the token. capacity_mode is "exceeded" or "below", and
|
|
771
|
+
granularity is "day" or "30m".
|
|
772
|
+
|
|
773
|
+
Supply start and end together as inclusive UTC dates in yyyy-MM-dd
|
|
774
|
+
format, covering at most 90 days and not extending into the future.
|
|
775
|
+
Omit both for the last 7 UTC calendar days, including today.
|
|
776
|
+
page starts at 1; limit defaults to 100 and is capped at 1000 by the API.
|
|
777
|
+
|
|
778
|
+
Returns (report, message), or (None, message) on failure. report is the
|
|
779
|
+
full dictionary with camelCase fields, including periods, summary,
|
|
780
|
+
page, limit, total, returned, and generatedUtc. Check each period's
|
|
781
|
+
hasData before interpreting zero usage as observed data.
|
|
782
|
+
|
|
783
|
+
More docs: https://app.cryptolens.io/docs/api/v3/GetFloatingCapacity
|
|
784
|
+
"""
|
|
785
|
+
|
|
786
|
+
return AI.__get_usage_analytics("ai/GetFloatingCapacity", None, token, {
|
|
787
|
+
"ProductId": product_id,
|
|
788
|
+
"Start": start,
|
|
789
|
+
"End": end,
|
|
790
|
+
"CapacityMode": capacity_mode,
|
|
791
|
+
"Granularity": granularity,
|
|
792
|
+
"Page": page,
|
|
793
|
+
"Limit": limit})
|
|
794
|
+
|
|
795
|
+
@staticmethod
|
|
796
|
+
def get_floating_capacity_licenses(token, product_id, interval_start_utc,
|
|
797
|
+
capacity_mode=None, page=1, limit=100,
|
|
798
|
+
min_utilization_percent=None):
|
|
799
|
+
"""
|
|
800
|
+
Retrieve licenses by floating-seat utilization in a 30-minute UTC interval.
|
|
801
|
+
Requires Usage Analytics permission. Returning customer names, company
|
|
802
|
+
names, and email addresses also requires Get Customers permission.
|
|
803
|
+
|
|
804
|
+
product_id is required. interval_start_utc is a non-future Unix timestamp
|
|
805
|
+
in seconds, aligned to a 30-minute UTC boundary. It can be taken from a
|
|
806
|
+
Get Floating Capacity period's worstIntervalStartUtc. page starts at 1;
|
|
807
|
+
limit defaults to 100 and is capped at 1000 by the API.
|
|
808
|
+
|
|
809
|
+
min_utilization_percent is an inclusive minimum percentage of floating
|
|
810
|
+
seats used. Zero includes tracked licenses with a positive limit even
|
|
811
|
+
when no seats are in use. Values above 100 select overuse. Supply
|
|
812
|
+
capacity_mode ("exceeded" or "below") to apply both filters. Omitting
|
|
813
|
+
both filters defaults to "exceeded".
|
|
814
|
+
|
|
815
|
+
Returns (report, message), or (None, message) on failure. report is the
|
|
816
|
+
full dictionary with camelCase fields, including licenses, hasData,
|
|
817
|
+
page, limit, total, returned, and generatedUtc. An empty licenses list
|
|
818
|
+
can mean there is no finding or that the requested page is out of range.
|
|
819
|
+
|
|
820
|
+
More docs: https://app.cryptolens.io/docs/api/v3/GetFloatingCapacityLicenses
|
|
821
|
+
"""
|
|
822
|
+
|
|
823
|
+
params = {
|
|
824
|
+
"ProductId": product_id,
|
|
825
|
+
"IntervalStartUtc": interval_start_utc,
|
|
826
|
+
"Page": page,
|
|
827
|
+
"Limit": limit}
|
|
828
|
+
|
|
829
|
+
if capacity_mode is not None:
|
|
830
|
+
params["CapacityMode"] = capacity_mode
|
|
831
|
+
elif min_utilization_percent is None:
|
|
832
|
+
params["CapacityMode"] = "exceeded"
|
|
833
|
+
|
|
834
|
+
if min_utilization_percent is not None:
|
|
835
|
+
params["MinUtilizationPercent"] = min_utilization_percent
|
|
836
|
+
|
|
837
|
+
return AI.__get_usage_analytics("ai/GetFloatingCapacityLicenses", None, token, params)
|
|
838
|
+
|
|
839
|
+
@staticmethod
|
|
840
|
+
def get_floating_capacity_history(token, product_id, key_id=0, key="",
|
|
841
|
+
start="", end="", page=1, limit=100):
|
|
842
|
+
"""
|
|
843
|
+
Retrieve a license's recorded floating usage and historical limits.
|
|
844
|
+
Requires Usage Analytics permission. Supply product_id and either
|
|
845
|
+
key_id or key. If both are supplied, they must identify the same
|
|
846
|
+
license in that product.
|
|
847
|
+
|
|
848
|
+
Supply start and end together as inclusive UTC dates in yyyy-MM-dd
|
|
849
|
+
format, covering at most 90 days and not extending into the future.
|
|
850
|
+
Omit both for the last 30 UTC calendar days, including today.
|
|
851
|
+
page starts at 1; limit defaults to 100 and is capped at 1000 by the API.
|
|
852
|
+
|
|
853
|
+
Returns (report, message), or (None, message) on failure. report is the
|
|
854
|
+
full dictionary with camelCase fields, including points, summary,
|
|
855
|
+
page, limit, total, returned, and generatedUtc. Points retain tracking
|
|
856
|
+
gaps, historical limits, and any available baseline. Use
|
|
857
|
+
report["summary"]["hasTrackedCapacityData"] to check for usable
|
|
858
|
+
tracked capacity, even when the requested page is empty.
|
|
859
|
+
|
|
860
|
+
More docs: https://app.cryptolens.io/docs/api/v3/GetFloatingCapacityHistory
|
|
861
|
+
"""
|
|
862
|
+
|
|
863
|
+
return AI.__get_usage_analytics("ai/GetFloatingCapacityHistory", None, token, {
|
|
864
|
+
"ProductId": product_id,
|
|
865
|
+
"KeyId": key_id,
|
|
866
|
+
"Key": key,
|
|
867
|
+
"Start": start,
|
|
868
|
+
"End": end,
|
|
869
|
+
"Page": page,
|
|
870
|
+
"Limit": limit})
|
|
871
|
+
|
|
872
|
+
@staticmethod
|
|
873
|
+
def get_expiring_licenses(token, product_id=0, window="7d", customer_id=None,
|
|
874
|
+
include_blocked_licenses=False, page=1, limit=100,
|
|
875
|
+
last_seen_days=None):
|
|
876
|
+
"""
|
|
877
|
+
Retrieve upcoming license expirations and a 7/14/30-day summary.
|
|
878
|
+
Requires Usage Analytics permission. Returning customer names, company
|
|
879
|
+
names, and email addresses also requires Get Customers permission.
|
|
880
|
+
|
|
881
|
+
Use product_id=0 for all products allowed by the token. window defaults
|
|
882
|
+
to "7d" and accepts a nonnegative integer with d, w, m, or y for days,
|
|
883
|
+
weeks, calendar months, or calendar years. A bare integer means days.
|
|
884
|
+
customer_id=None omits the customer filter; otherwise supply a positive
|
|
885
|
+
customer ID. Blocked licenses are excluded unless
|
|
886
|
+
include_blocked_licenses=True. page starts at 1; limit defaults to 100
|
|
887
|
+
and is capped at 1000 by the API. Set last_seen_days (1 to 36500) to
|
|
888
|
+
return licenses whose last recorded API activity was more than that
|
|
889
|
+
many days ago.
|
|
890
|
+
|
|
891
|
+
Returns (report, message), or (None, message) on failure. report is the
|
|
892
|
+
full dictionary with camelCase fields, including licenses, summary,
|
|
893
|
+
expiresBeforeUtc, page, limit, total, returned, and generatedUtc.
|
|
894
|
+
The summary is independent of window, page, limit and last_seen_days.
|
|
895
|
+
With last_seen_days, total counts candidates before activity filtering.
|
|
896
|
+
pageActivity.noRecordedActivity counts licenses with no recorded activity.
|
|
897
|
+
Follow report["pageActivity"]["nextPage"] until it is None, even when
|
|
898
|
+
a page has no matching licenses.
|
|
899
|
+
|
|
900
|
+
More docs: https://app.cryptolens.io/docs/api/v3/GetExpiringLicenses
|
|
901
|
+
"""
|
|
902
|
+
|
|
903
|
+
params = {
|
|
904
|
+
"ProductId": product_id,
|
|
905
|
+
"Window": window,
|
|
906
|
+
"IncludeBlockedLicenses": include_blocked_licenses,
|
|
907
|
+
"Page": page,
|
|
908
|
+
"Limit": limit}
|
|
909
|
+
|
|
910
|
+
if customer_id is not None:
|
|
911
|
+
params["CustomerId"] = customer_id
|
|
912
|
+
if last_seen_days is not None:
|
|
913
|
+
params["LastSeenDays"] = last_seen_days
|
|
914
|
+
|
|
915
|
+
return AI.__get_usage_analytics("ai/GetExpiringLicenses", None, token, params)
|
|
916
|
+
|
|
759
917
|
@staticmethod
|
|
760
918
|
def get_web_api_log(token, product_id = 0, key = "", machine_code="", friendly_name = "",\
|
|
761
919
|
limit = 10, starting_after = 0, ending_before=0, order_by=""):
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: licensing
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.56
|
|
4
4
|
Home-page: https://devolens.com
|
|
5
|
-
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/
|
|
5
|
+
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/v_56.tar.gz
|
|
6
6
|
Author: Cryptolens AB
|
|
7
7
|
Author-email: help@devolens.com
|
|
8
8
|
License: MIT
|
|
@@ -3,7 +3,7 @@ from setuptools import setup
|
|
|
3
3
|
setup(
|
|
4
4
|
name = 'licensing', # How you named your package folder (MyLib)
|
|
5
5
|
packages = ['licensing'], # Chose the same as "name"
|
|
6
|
-
version = '0.
|
|
6
|
+
version = '0.56', # Start with a small number and increase it with every change you make
|
|
7
7
|
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
|
|
8
8
|
#description_file = 'Client library for Cryptolens licensing Web API.', # Give a short description about your library
|
|
9
9
|
long_description = 'Client library for Devolens (formerly Cryptolens) Web API (software licensing).',
|
|
@@ -11,7 +11,7 @@ setup(
|
|
|
11
11
|
author = 'Cryptolens AB', # Type in your name
|
|
12
12
|
author_email = 'help@devolens.com', # Type in your E-Mail
|
|
13
13
|
url = 'https://devolens.com', # Provide either the link to your github or to your website
|
|
14
|
-
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/
|
|
14
|
+
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_56.tar.gz',
|
|
15
15
|
project_urls={ # optional, shows on PyPI
|
|
16
16
|
"Source": "https://github.com/Cryptolens/cryptolens-python",
|
|
17
17
|
"Tracker": "https://github.com/Cryptolens/cryptolens-python/issues",
|
|
@@ -1,128 +1,176 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import unittest
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
from licensing.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
captured["
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
self.assertEqual(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
"
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
1
|
+
import json
|
|
2
|
+
import unittest
|
|
3
|
+
from unittest.mock import patch
|
|
4
|
+
|
|
5
|
+
from licensing.internal import HelperMethods
|
|
6
|
+
from licensing.methods import AI
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AIUsageAnalyticsTests(unittest.TestCase):
|
|
10
|
+
|
|
11
|
+
def _assert_usage_analytics_call(self, call, expected_endpoint, expected_field, expected_params):
|
|
12
|
+
original_send_request = HelperMethods.send_request
|
|
13
|
+
captured = {}
|
|
14
|
+
|
|
15
|
+
def fake_send_request(endpoint, params):
|
|
16
|
+
captured["endpoint"] = endpoint
|
|
17
|
+
captured["params"] = params
|
|
18
|
+
return json.dumps({
|
|
19
|
+
"result": 0,
|
|
20
|
+
"message": None,
|
|
21
|
+
expected_field: [{"id": 1}]
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
HelperMethods.send_request = fake_send_request
|
|
26
|
+
result = call()
|
|
27
|
+
finally:
|
|
28
|
+
HelperMethods.send_request = original_send_request
|
|
29
|
+
|
|
30
|
+
self.assertEqual(result, ([{"id": 1}], ""))
|
|
31
|
+
self.assertEqual(captured["endpoint"], expected_endpoint)
|
|
32
|
+
|
|
33
|
+
for key, value in expected_params.items():
|
|
34
|
+
self.assertEqual(captured["params"][key], value)
|
|
35
|
+
|
|
36
|
+
def test_get_daily_aggregates(self):
|
|
37
|
+
self._assert_usage_analytics_call(
|
|
38
|
+
lambda: AI.get_daily_aggregates(
|
|
39
|
+
token="token",
|
|
40
|
+
product_id=123,
|
|
41
|
+
limit=25,
|
|
42
|
+
starting_after=10,
|
|
43
|
+
ending_before=20,
|
|
44
|
+
start="2026-05-01",
|
|
45
|
+
end="2026-05-31"
|
|
46
|
+
),
|
|
47
|
+
"ai/GetDailyAggregates",
|
|
48
|
+
"aggregates",
|
|
49
|
+
{
|
|
50
|
+
"token": "token",
|
|
51
|
+
"ProductId": 123,
|
|
52
|
+
"Limit": 25,
|
|
53
|
+
"StartingAfter": 10,
|
|
54
|
+
"EndingBefore": 20,
|
|
55
|
+
"Start": "2026-05-01",
|
|
56
|
+
"End": "2026-05-31"
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
def test_get_daily_country_aggregates(self):
|
|
60
|
+
self._assert_usage_analytics_call(
|
|
61
|
+
lambda: AI.get_daily_country_aggregates(
|
|
62
|
+
token="token",
|
|
63
|
+
product_id=123,
|
|
64
|
+
country_code="SE"
|
|
65
|
+
),
|
|
66
|
+
"ai/GetDailyCountryAggregates",
|
|
67
|
+
"aggregates",
|
|
68
|
+
{
|
|
69
|
+
"token": "token",
|
|
70
|
+
"ProductId": 123,
|
|
71
|
+
"CountryCode": "SE"
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
def test_get_key_usage_summaries(self):
|
|
75
|
+
self._assert_usage_analytics_call(
|
|
76
|
+
lambda: AI.get_key_usage_summaries(
|
|
77
|
+
token="token",
|
|
78
|
+
product_id=123,
|
|
79
|
+
key_id=456,
|
|
80
|
+
key="AAAA-BBBB-CCCC-DDDD"
|
|
81
|
+
),
|
|
82
|
+
"ai/GetKeyUsageSummaries",
|
|
83
|
+
"summaries",
|
|
84
|
+
{
|
|
85
|
+
"token": "token",
|
|
86
|
+
"ProductId": 123,
|
|
87
|
+
"KeyId": 456,
|
|
88
|
+
"Key": "AAAA-BBBB-CCCC-DDDD"
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
def test_get_key_devices(self):
|
|
92
|
+
self._assert_usage_analytics_call(
|
|
93
|
+
lambda: AI.get_key_devices(
|
|
94
|
+
token="token",
|
|
95
|
+
product_id=123,
|
|
96
|
+
key_id=456,
|
|
97
|
+
machine_code="MACHINE-1"
|
|
98
|
+
),
|
|
99
|
+
"ai/GetKeyDevices",
|
|
100
|
+
"devices",
|
|
101
|
+
{
|
|
102
|
+
"token": "token",
|
|
103
|
+
"ProductId": 123,
|
|
104
|
+
"KeyId": 456,
|
|
105
|
+
"MachineCode": "MACHINE-1"
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
def test_get_license_activity_buckets(self):
|
|
109
|
+
self._assert_usage_analytics_call(
|
|
110
|
+
lambda: AI.get_license_activity_buckets(
|
|
111
|
+
token="token",
|
|
112
|
+
product_id=123,
|
|
113
|
+
key_id=456,
|
|
114
|
+
key="AAAA-BBBB-CCCC-DDDD",
|
|
115
|
+
machine_code="MACHINE-1"
|
|
116
|
+
),
|
|
117
|
+
"ai/GetLicenseActivityBuckets",
|
|
118
|
+
"buckets",
|
|
119
|
+
{
|
|
120
|
+
"token": "token",
|
|
121
|
+
"ProductId": 123,
|
|
122
|
+
"KeyId": 456,
|
|
123
|
+
"Key": "AAAA-BBBB-CCCC-DDDD",
|
|
124
|
+
"MachineCode": "MACHINE-1"
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
@patch.object(HelperMethods, "send_request", return_value='{"result": 0}')
|
|
128
|
+
def test_floating_capacity_minimum_without_mode(self, send_request):
|
|
129
|
+
for minimum in (0, 90, 110):
|
|
130
|
+
with self.subTest(minimum=minimum):
|
|
131
|
+
AI.get_floating_capacity_licenses(
|
|
132
|
+
"token", 123, 1800, min_utilization_percent=minimum)
|
|
133
|
+
|
|
134
|
+
send_request.assert_called_with("ai/GetFloatingCapacityLicenses", {
|
|
135
|
+
"token": "token", "ProductId": 123, "IntervalStartUtc": 1800,
|
|
136
|
+
"MinUtilizationPercent": minimum, "Page": 1, "Limit": 100})
|
|
137
|
+
|
|
138
|
+
@patch.object(HelperMethods, "send_request", return_value='{"result": 0}')
|
|
139
|
+
def test_floating_capacity_minimum_with_explicit_mode(self, send_request):
|
|
140
|
+
for mode in ("below", "exceeded"):
|
|
141
|
+
with self.subTest(mode=mode):
|
|
142
|
+
AI.get_floating_capacity_licenses(
|
|
143
|
+
"token", 123, 1800, mode, 2, 10, min_utilization_percent=90)
|
|
144
|
+
|
|
145
|
+
send_request.assert_called_with("ai/GetFloatingCapacityLicenses", {
|
|
146
|
+
"token": "token", "ProductId": 123, "IntervalStartUtc": 1800,
|
|
147
|
+
"CapacityMode": mode, "MinUtilizationPercent": 90, "Page": 2, "Limit": 10})
|
|
148
|
+
|
|
149
|
+
@patch.object(HelperMethods, "send_request", return_value='{"result": 0}')
|
|
150
|
+
def test_reports_without_new_filters_keep_existing_requests(self, send_request):
|
|
151
|
+
AI.get_floating_capacity_licenses("token", 123, 1800)
|
|
152
|
+
send_request.assert_called_with("ai/GetFloatingCapacityLicenses", {
|
|
153
|
+
"token": "token", "ProductId": 123, "IntervalStartUtc": 1800,
|
|
154
|
+
"CapacityMode": "exceeded", "Page": 1, "Limit": 100})
|
|
155
|
+
|
|
156
|
+
AI.get_expiring_licenses("token", 123, "90d", 456, True, 2, 10)
|
|
157
|
+
send_request.assert_called_with("ai/GetExpiringLicenses", {
|
|
158
|
+
"token": "token", "ProductId": 123, "Window": "90d", "CustomerId": 456,
|
|
159
|
+
"IncludeBlockedLicenses": True, "Page": 2, "Limit": 10})
|
|
160
|
+
|
|
161
|
+
@patch.object(HelperMethods, "send_request")
|
|
162
|
+
def test_expiring_licenses_last_seen_filter_preserves_page_activity(self, send_request):
|
|
163
|
+
report = {"result": 0, "licenses": [], "pageActivity": {"nextPage": 3, "noRecordedActivity": 1}}
|
|
164
|
+
send_request.return_value = json.dumps(report)
|
|
165
|
+
|
|
166
|
+
result = AI.get_expiring_licenses(
|
|
167
|
+
"token", window="90d", page=2, limit=10, last_seen_days=30)
|
|
168
|
+
|
|
169
|
+
send_request.assert_called_once_with("ai/GetExpiringLicenses", {
|
|
170
|
+
"token": "token", "ProductId": 0, "Window": "90d", "IncludeBlockedLicenses": False,
|
|
171
|
+
"LastSeenDays": 30, "Page": 2, "Limit": 10})
|
|
172
|
+
self.assertEqual(result, (report, ""))
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
if __name__ == "__main__":
|
|
176
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|