@@ -158,6 +158,103 @@ async def test_client_get_pending_clash_of_code(client: AsyncClient, mock_http):
158158 assert isinstance (clash_of_code , ClashOfCode ) or clash_of_code is None
159159
160160
161+ async def test_client_create_private_clash_of_code (
162+ auth_client : AsyncClient , mock_http
163+ ):
164+ mock_http (auth_client ._state .http , "create_private_clash_of_code" )
165+ mock_http (auth_client ._state .http , "get_clash_of_code_from_handle" )
166+ clash_of_code = await auth_client .create_private_clash_of_code (
167+ ["Python3" ], ["SHORTEST" , "FASTEST" ]
168+ )
169+ assert isinstance (clash_of_code , ClashOfCode )
170+ assert clash_of_code .modes in (
171+ ["SHORTEST" , "FASTEST" ],
172+ ["FASTEST" , "SHORTEST" ],
173+ )
174+ assert clash_of_code .programming_languages == ["Python3" ]
175+ assert auth_client .codingamer .id in [p .id for p in clash_of_code .players ]
176+
177+
178+ async def test_client_create_private_clash_of_code_logged_in_error (
179+ client : AsyncClient ,
180+ ):
181+ with pytest .raises (exceptions .LoginRequired ):
182+ await client .create_private_clash_of_code (
183+ ["Python3" ], ["SHORTEST" , "FASTEST" ]
184+ )
185+
186+
187+ async def test_client_create_private_clash_of_code_value_error (
188+ auth_client : AsyncClient , mock_httperror
189+ ):
190+ with pytest .raises (ValueError ):
191+ await auth_client .create_private_clash_of_code (
192+ ["Python3" ], ["BAD MODE" , "FASTEST" ]
193+ )
194+
195+ mock_httperror (
196+ auth_client ._state .http ,
197+ "create_private_clash_of_code" ,
198+ {"id" : 501 , "message" : "You need to be logged to perform this action." },
199+ )
200+ with pytest .raises (exceptions .LoginRequired ):
201+ await auth_client .create_private_clash_of_code (
202+ ["Python3" ], ["SHORTEST" , "FASTEST" ]
203+ )
204+
205+
206+ async def test_client_join_private_clash_of_code (
207+ auth_client : AsyncClient , private_clash : ClashOfCode , mock_http
208+ ):
209+ mock_http (auth_client ._state .http , "join_clash_of_code_by_handle" )
210+ mock_http (auth_client ._state .http , "get_clash_of_code_from_handle" )
211+ clash_of_code = await auth_client .join_private_clash_of_code (private_clash )
212+ assert isinstance (clash_of_code , ClashOfCode )
213+ assert private_clash .public_handle == clash_of_code .public_handle
214+ assert auth_client .codingamer .id in [p .id for p in clash_of_code .players ]
215+
216+
217+ async def test_client_join_private_clash_of_code_logged_in_error (
218+ client : AsyncClient ,
219+ ):
220+ with pytest .raises (exceptions .LoginRequired ):
221+ await client .join_private_clash_of_code ("0" * 7 + "a" * 32 )
222+
223+
224+ async def test_client_join_private_clash_of_code_value_error (
225+ auth_client : AsyncClient , is_mocking : bool , mock_httperror
226+ ):
227+ with pytest .raises (ValueError ):
228+ await auth_client .join_private_clash_of_code ("not a public handle" )
229+
230+ mock_httperror (
231+ auth_client ._state .http , "join_clash_of_code_by_handle" , {"id" : 502 }
232+ )
233+ with pytest .raises (exceptions .ClashOfCodeNotFound ):
234+ await auth_client .join_private_clash_of_code ("0" * 7 + "a" * 32 )
235+
236+ if not is_mocking :
237+ return
238+
239+ mock_httperror (
240+ auth_client ._state .http , "join_clash_of_code_by_handle" , {"id" : 504 }
241+ )
242+ with pytest .raises (exceptions .ClashOfCodeStarted ):
243+ await auth_client .join_private_clash_of_code ("0" * 7 + "a" * 32 )
244+
245+ mock_httperror (
246+ auth_client ._state .http , "join_clash_of_code_by_handle" , {"id" : 505 }
247+ )
248+ with pytest .raises (exceptions .ClashOfCodeFinished ):
249+ await auth_client .join_private_clash_of_code ("0" * 7 + "a" * 32 )
250+
251+ mock_httperror (
252+ auth_client ._state .http , "join_clash_of_code_by_handle" , {"id" : 506 }
253+ )
254+ with pytest .raises (exceptions .ClashOfCodeFull ):
255+ await auth_client .join_private_clash_of_code ("0" * 7 + "a" * 32 )
256+
257+
161258async def test_client_get_language_ids (client : AsyncClient , mock_http ):
162259 mock_http (client ._state .http , "get_language_ids" )
163260 language_ids = await client .get_language_ids ()
0 commit comments