1+ import uuid
2+ import pytest
3+ import pytest
4+ from streamlit .testing .v1 import AppTest
5+ from dp_sdk .ocf import dp
6+ import pandas as pd
7+
8+
9+ @pytest .fixture
10+ def app ():
11+ test_app = AppTest .from_file ("src/dataplatform/toolbox/main.py" )
12+ test_app .run ()
13+ return test_app
14+
15+
16+ @pytest .mark .integration
17+ @pytest .mark .asyncio (loop_scope = "session" )
18+ async def test_list_locations_ui (app , data_client : dp .DataPlatformDataServiceStub ):
19+ # -----------------
20+ # LIST LOCATIONS (UI)
21+ # -----------------
22+
23+ # Create some locations via gRPC
24+ location_names = []
25+ for i in range (3 ):
26+ location_name = "ui_location_" + str (uuid .uuid4 ()).replace ("-" , "_" )
27+ location_names .append (location_name )
28+ await data_client .create_location (
29+ dp .CreateLocationRequest (
30+ location_name = location_name ,
31+ energy_source = 1 ,
32+ geometry_wkt = "Point(0 0)" ,
33+ location_type = 1 ,
34+ effective_capacity_watts = 100 ,
35+ metadata = {}
36+ )
37+ )
38+ app .run ()
39+ # Expand filter options and click list button
40+ app .selectbox ("list_loc_energy" ).set_value ("All" )
41+ app .selectbox ("list_loc_type" ).set_value ("All" )
42+ app .text_input ("list_loc_user" ).set_value ("" )
43+ app .run ()
44+ app .button ("list_locations_button" ).click ()
45+ app .run ()
46+
47+ dfs = [df .value for df in app .dataframe ]
48+ # Combine all rendered dataframes
49+ all_tables = pd .concat (dfs )
50+ for location_name in location_names :
51+ assert location_name in all_tables ["Name" ].values
52+
53+
54+ @pytest .mark .integration
55+ @pytest .mark .asyncio (loop_scope = "session" )
56+ async def test_get_location_ui (app , data_client : dp .DataPlatformDataServiceStub ):
57+ # -----------------
58+ # GET LOCATION (UI)
59+ # -----------------
60+ location_name = "ui_location_" + str (uuid .uuid4 ()).replace ("-" , "_" )
61+
62+ # Create location via gRPC
63+ response = await data_client .create_location (
64+ dp .CreateLocationRequest (
65+ location_name = location_name ,
66+ energy_source = 1 ,
67+ geometry_wkt = "Point(0 0)" ,
68+ location_type = 1 ,
69+ effective_capacity_watts = 100 ,
70+ metadata = {}
71+ )
72+ )
73+ location_uuid = response .location_uuid
74+
75+ # Get location via UI
76+ app .text_input ("get_loc_uuid" ).set_value (location_uuid )
77+ app .selectbox ("get_loc_energy" ).set_value ("SOLAR" )
78+ app .checkbox ("get_loc_geom" ).set_value (True )
79+ app .button ("get_location_button" ).click ()
80+ app .run ()
81+
82+ # Assert location details are displayed
83+ assert any (location_uuid in s .value for s in app .success )
84+
85+ @pytest .mark .integration
86+ @pytest .mark .asyncio (loop_scope = "session" )
87+ async def test_create_location_ui (app , data_client : dp .DataPlatformDataServiceStub ):
88+ # -----------------
89+ # CREATE LOCATION (UI)
90+ # -----------------
91+ location_name = "ui_location_" + str (uuid .uuid4 ()).replace ("-" , "_" )
92+
93+ # Fill in form and create location via UI
94+ app .text_input ("create_loc_name" ).set_value (location_name )
95+ app .selectbox ("create_loc_energy" ).set_value ("WIND" )
96+ app .selectbox ("create_loc_type" ).set_value ("REGION" )
97+ app .text_input ("create_loc_geom" ).set_value ("POINT(0 0)" )
98+ app .number_input ("create_loc_cap" ).set_value (100 )
99+ app .text_area ("create_loc_metadata" ).set_value ("{}" )
100+ app .button ("create_location_button" ).click ()
101+ app .run ()
102+
103+ # Assert success message in UI
104+ assert any ("created" in s .value .lower () for s in app .success )
105+
106+ # Verify location was actually created via gRPC
107+ response = await data_client .list_locations (
108+ dp .ListLocationsRequest ()
109+ )
110+ assert any (loc .location_name == location_name for loc in response .locations )
111+
0 commit comments