@@ -98,11 +98,65 @@ async def state_backend(request: pytest.FixtureRequest) -> _t.AsyncIterator[Stat
9898 yield state_backend
9999
100100
101+ @pytest .mark .asyncio
102+ @pytest .mark .parametrize ("with_components" , [True , False ])
103+ async def test_state_backend_upsert_process (
104+ state_backend : StateBackend ,
105+ B_components : list [Component ],
106+ B_connectors : list [Connector ],
107+ C_components : list [Component ],
108+ C_connectors : list [Connector ],
109+ with_components : bool ,
110+ ) -> None :
111+ """Tests `StateBackend.upsert_process` method.
112+
113+ Two processes are created to ensure no interference between them. Each process is upserted into
114+ the state backend, and then retrieved. The retrieved data is compared to the process data
115+ obtained from the process.dump method.
116+ """
117+ comp_b1 , comp_b2 = B_components
118+ conn_1 , conn_2 = B_connectors
119+
120+ comp_c1 , comp_c2 = C_components
121+ conn_3 , conn_4 = C_connectors
122+
123+ async with state_backend :
124+ process_1 = LocalProcess (
125+ name = "P1" , components = [comp_b1 , comp_b2 ], connectors = [conn_1 , conn_2 ]
126+ )
127+ await state_backend .upsert_process (process_1 , with_components = with_components )
128+
129+ process_2 = LocalProcess (
130+ name = "P2" , components = [comp_c1 , comp_c2 ], connectors = [conn_3 , conn_4 ]
131+ )
132+ await state_backend .upsert_process (process_2 , with_components = with_components )
133+
134+ process_1_dict = process_1 .dict ()
135+ process_2_dict = process_2 .dict ()
136+ if not with_components :
137+ process_1_dict ["components" ] = {comp .id : {} for comp in B_components }
138+ process_1_dict ["connectors" ] = {conn .id : {} for conn in B_connectors }
139+ process_2_dict ["components" ] = {comp .id : {} for comp in C_components }
140+ process_2_dict ["connectors" ] = {conn .id : {} for conn in C_connectors }
141+
142+ assert await state_backend .get_process (process_1 .id ) == process_1_dict
143+ assert await state_backend .get_process (process_2 .id ) == process_2_dict
144+
145+
101146@pytest .mark .asyncio
102147async def test_state_backend_upsert_component (
103148 state_backend : StateBackend , A_components : list [Component ]
104149) -> None :
105- """Tests `StateBackend.upsert_component` method."""
150+ """Tests `StateBackend.upsert_component` method.
151+
152+ Two `A` components are created and upserted into the state backend. The components are stepped
153+ multiple times, with assertions verifying that the state backend reflects the correct state
154+ before and after each upsert.
155+
156+ Note that the components must be a part of a process in the state backend before they can be
157+ upserted. Hence, a `LocalProcess` is created and upserted into the state backend first. Method
158+ tested separately.
159+ """
106160 comp_a1 , comp_a2 = A_components
107161
108162 process = LocalProcess (name = "P1" , components = [comp_a1 , comp_a2 ], connectors = [])
@@ -147,7 +201,15 @@ async def test_state_backend_upsert_component(
147201async def test_state_backend_upsert_connector (
148202 state_backend : StateBackend , B_connectors : list [Connector ]
149203) -> None :
150- """Tests `StateBackend.upsert_connector` method."""
204+ """Tests `StateBackend.upsert_connector` method.
205+
206+ Two connectors are created and upserted into the state backend. The retrieved connector data is
207+ compared to the original connector data to ensure correctness.
208+
209+ Note that the connectors must be a part of a process in the state backend before they can be
210+ upserted. Hence, a `LocalProcess` is created and upserted into the state backend first. Method
211+ tested separately.
212+ """
151213 conn_1 , conn_2 = B_connectors
152214
153215 process = LocalProcess (name = "P1" , components = [], connectors = [conn_1 , conn_2 ])
@@ -166,46 +228,6 @@ async def test_state_backend_upsert_connector(
166228 assert await state_backend .get_connector (conn_2 .id ) == conn_2 .dict ()
167229
168230
169- @pytest .mark .asyncio
170- @pytest .mark .parametrize ("with_components" , [True , False ])
171- async def test_state_backend_upsert_process (
172- state_backend : StateBackend ,
173- B_components : list [Component ],
174- B_connectors : list [Connector ],
175- C_components : list [Component ],
176- C_connectors : list [Connector ],
177- with_components : bool ,
178- ) -> None :
179- """Tests `StateBackend.upsert_process` method."""
180- comp_b1 , comp_b2 = B_components
181- conn_1 , conn_2 = B_connectors
182-
183- comp_c1 , comp_c2 = C_components
184- conn_3 , conn_4 = C_connectors
185-
186- async with state_backend :
187- process_1 = LocalProcess (
188- name = "P1" , components = [comp_b1 , comp_b2 ], connectors = [conn_1 , conn_2 ]
189- )
190- await state_backend .upsert_process (process_1 , with_components = with_components )
191-
192- process_2 = LocalProcess (
193- name = "P2" , components = [comp_c1 , comp_c2 ], connectors = [conn_3 , conn_4 ]
194- )
195- await state_backend .upsert_process (process_2 , with_components = with_components )
196-
197- process_1_dict = process_1 .dict ()
198- process_2_dict = process_2 .dict ()
199- if not with_components :
200- process_1_dict ["components" ] = {comp .id : {} for comp in B_components }
201- process_1_dict ["connectors" ] = {conn .id : {} for conn in B_connectors }
202- process_2_dict ["components" ] = {comp .id : {} for comp in C_components }
203- process_2_dict ["connectors" ] = {conn .id : {} for conn in C_connectors }
204-
205- assert await state_backend .get_process (process_1 .id ) == process_1_dict
206- assert await state_backend .get_process (process_2 .id ) == process_2_dict
207-
208-
209231@pytest .mark .asyncio
210232async def test_state_backend_process_init (
211233 state_backend : StateBackend , B_components : list [Component ], B_connectors : list [Connector ]
0 commit comments