Skip to content

Commit f4a04c5

Browse files
committed
test data usage
1 parent 204bf03 commit f4a04c5

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
@@ -988,7 +988,7 @@ def data_usage(offset: int = 0, limit: int = 10) -> List[geoengine_openapi_clien
988988

989989

990990
def data_usage_summary(granularity: geoengine_openapi_client.UsageSummaryGranularity,
991-
data: Optional[str] = None,
991+
dataset: Optional[str] = None,
992992
offset: int = 0, limit: int = 10) -> pd.DataFrame:
993993
'''
994994
Get data usage summary
@@ -998,7 +998,7 @@ def data_usage_summary(granularity: geoengine_openapi_client.UsageSummaryGranula
998998

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

10041004
# 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+
from geoengine.datasets import DatasetName, UploadId, StoredDataset
6+
import geoengine as ge
7+
from . import UrllibMocker
8+
9+
10+
class DataUsageTests(unittest.TestCase):
11+
'''Test methods for data usage'''
12+
13+
def setUp(self) -> None:
14+
ge.reset(False)
15+
16+
def test_data_usage(self):
17+
18+
with UrllibMocker() as m:
19+
m.post('http://mock-instance/login',
20+
expected_request_body={"email": "admin@localhost", "password": "adminadmin"},
21+
json={
22+
"id": "e327d9c3-a4f3-4bd7-a5e1-30b26cae8064",
23+
"user": {
24+
"id": "328ca8d1-15d7-4f59-a989-5d5d72c98744",
25+
},
26+
"created": "2021-06-08T15:22:22.605891994Z",
27+
"validUntil": "2021-06-08T16:22:22.605892183Z",
28+
"project": None,
29+
"view": None
30+
})
31+
32+
m.get('http://mock-instance/quota/dataUsage?offset=0&limit=10', json=[
33+
{
34+
"timestamp": "2025-01-09T16:40:22.933Z",
35+
"userId": "e440bffc-d899-4304-aace-b23fc56828b2",
36+
"computationId": "7b08af4a-8793-4299-83c1-39d0c20560f5",
37+
"data": "land_cover",
38+
"count": 4
39+
},
40+
{
41+
"timestamp": "2025-01-09T16:40:10.970Z",
42+
"userId": "e440bffc-d899-4304-aace-b23fc56828b2",
43+
"computationId": "57fba95f-d693-432b-a65b-58ac225a384a",
44+
"data": "land_cover",
45+
"count": 4
46+
}
47+
])
48+
49+
ge.initialize("http://mock-instance", ("admin@localhost", "adminadmin"))
50+
51+
df = ge.data_usage(offset=0, limit=10)
52+
53+
expected = pd.DataFrame({
54+
'computationId': [
55+
'7b08af4a-8793-4299-83c1-39d0c20560f5',
56+
'57fba95f-d693-432b-a65b-58ac225a384a'
57+
],
58+
'count': [4, 4],
59+
'data': ['land_cover', 'land_cover'],
60+
'timestamp': [pd.Timestamp('2025-01-09 16:40:22.933000+0000', tz='UTC'), 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)