Skip to content

Commit 2ff8af1

Browse files
Merge branch 'main' of github.com:geo-engine/geoengine-python into ge_test
2 parents 3e1205b + ef00121 commit 2ff8af1

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed

geoengine/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ def data_usage(offset: int = 0, limit: int = 10) -> List[geoengine_openapi_clien
991991

992992

993993
def data_usage_summary(granularity: geoengine_openapi_client.UsageSummaryGranularity,
994-
data: Optional[str] = None,
994+
dataset: Optional[str] = None,
995995
offset: int = 0, limit: int = 10) -> pd.DataFrame:
996996
'''
997997
Get data usage summary
@@ -1001,7 +1001,7 @@ def data_usage_summary(granularity: geoengine_openapi_client.UsageSummaryGranula
10011001

10021002
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
10031003
user_api = geoengine_openapi_client.UserApi(api_client)
1004-
response = user_api.data_usage_summary_handler(dataset=data, granularity=granularity,
1004+
response = user_api.data_usage_summary_handler(dataset=dataset, granularity=granularity,
10051005
offset=offset, limit=limit)
10061006

10071007
# create dataframe from response

tests/test_data_usage.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
'''Tests for WMS calls'''
2+
3+
import unittest
4+
import pandas as pd
5+
import geoengine as ge
6+
from . import UrllibMocker
7+
8+
9+
class DataUsageTests(unittest.TestCase):
10+
'''Test methods for data usage'''
11+
12+
def setUp(self) -> None:
13+
ge.reset(False)
14+
15+
def test_data_usage(self):
16+
17+
with UrllibMocker() as m:
18+
m.post('http://mock-instance/login',
19+
expected_request_body={"email": "admin@localhost", "password": "adminadmin"},
20+
json={
21+
"id": "e327d9c3-a4f3-4bd7-a5e1-30b26cae8064",
22+
"user": {
23+
"id": "328ca8d1-15d7-4f59-a989-5d5d72c98744",
24+
},
25+
"created": "2021-06-08T15:22:22.605891994Z",
26+
"validUntil": "2021-06-08T16:22:22.605892183Z",
27+
"project": None,
28+
"view": None
29+
})
30+
31+
m.get('http://mock-instance/quota/dataUsage?offset=0&limit=10', json=[
32+
{
33+
"timestamp": "2025-01-09T16:40:22.933Z",
34+
"userId": "e440bffc-d899-4304-aace-b23fc56828b2",
35+
"computationId": "7b08af4a-8793-4299-83c1-39d0c20560f5",
36+
"data": "land_cover",
37+
"count": 4
38+
},
39+
{
40+
"timestamp": "2025-01-09T16:40:10.970Z",
41+
"userId": "e440bffc-d899-4304-aace-b23fc56828b2",
42+
"computationId": "57fba95f-d693-432b-a65b-58ac225a384a",
43+
"data": "land_cover",
44+
"count": 4
45+
}
46+
])
47+
48+
ge.initialize("http://mock-instance", ("admin@localhost", "adminadmin"))
49+
50+
df = ge.data_usage(offset=0, limit=10)
51+
52+
expected = pd.DataFrame({
53+
'computationId': [
54+
'7b08af4a-8793-4299-83c1-39d0c20560f5',
55+
'57fba95f-d693-432b-a65b-58ac225a384a'
56+
],
57+
'count': [4, 4],
58+
'data': ['land_cover', 'land_cover'],
59+
'timestamp': [pd.Timestamp('2025-01-09 16:40:22.933000+0000', tz='UTC'),
60+
pd.Timestamp('2025-01-09 16:40:10.970000+0000', tz='UTC')],
61+
'userId': ['e440bffc-d899-4304-aace-b23fc56828b2', 'e440bffc-d899-4304-aace-b23fc56828b2']})
62+
63+
pd.testing.assert_frame_equal(df, expected)
64+
65+
def test_data_usage_summary(self):
66+
67+
with UrllibMocker() as m:
68+
m.post('http://mock-instance/login',
69+
expected_request_body={"email": "admin@localhost", "password": "adminadmin"},
70+
json={
71+
"id": "e327d9c3-a4f3-4bd7-a5e1-30b26cae8064",
72+
"user": {
73+
"id": "328ca8d1-15d7-4f59-a989-5d5d72c98744",
74+
},
75+
"created": "2021-06-08T15:22:22.605891994Z",
76+
"validUntil": "2021-06-08T16:22:22.605892183Z",
77+
"project": None,
78+
"view": None
79+
})
80+
81+
m.get('http://mock-instance/quota/dataUsage/summary?granularity=minutes&offset=0&limit=10', json=[
82+
{
83+
"timestamp": "2025-01-09T16:40:00.000Z",
84+
"data": "land_cover",
85+
"count": 8
86+
}
87+
])
88+
89+
ge.initialize("http://mock-instance", ("admin@localhost", "adminadmin"))
90+
91+
df = ge.data_usage_summary(granularity=ge.UsageSummaryGranularity.MINUTES, offset=0, limit=10)
92+
93+
expected = pd.DataFrame({
94+
'count': {0: 8},
95+
'data': {0: 'land_cover'},
96+
'timestamp': {0: pd.Timestamp('2025-01-09 16:40:00+0000', tz='UTC')}})
97+
98+
pd.testing.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)