@@ -342,6 +342,55 @@ def query_statements_by_ids_mock(*args, **kwargs):
342342 assert response .json () == {"detail" : "xAPI statements query failed" }
343343
344344
345+ @pytest .mark .parametrize ("backend" , [get_es_test_backend , get_mongo_test_backend ])
346+ def test_post_statements_list_without_statement_forwarding (
347+ backend , auth_credentials , monkeypatch , es , mongo
348+ ):
349+ """Tests the post statements API route, given an empty forwarding configuration,
350+ should not start the forwarding background task.
351+ """
352+ # pylint: disable=invalid-name,unused-argument
353+
354+ spy = {}
355+
356+ def spy_mock_forward_xapi_statements (_ ):
357+ """Mocks the forward_xapi_statements; spies over whether it has been called."""
358+
359+ spy ["error" ] = "forward_xapi_statements should not have been called!"
360+
361+ monkeypatch .setattr (
362+ "ralph.api.routers.statements.forward_xapi_statements" ,
363+ spy_mock_forward_xapi_statements ,
364+ )
365+ monkeypatch .setattr (
366+ "ralph.api.routers.statements.get_active_xapi_forwardings" , lambda : []
367+ )
368+ monkeypatch .setattr ("ralph.api.routers.statements.DATABASE_CLIENT" , backend ())
369+
370+ statement = {
371+ "actor" : {
372+ "account" : {
373+ "homePage" : "https://example.com/homepage/" ,
374+ "name" : str (uuid4 ()),
375+ },
376+ "objectType" : "Agent" ,
377+ },
378+ "id" : str (uuid4 ()),
379+ "object" : {"id" : "https://example.com/object-id/1/" },
380+ "timestamp" : "2022-06-22T08:31:38Z" ,
381+ "verb" : {"id" : "https://example.com/verb-id/1/" },
382+ }
383+
384+ response = client .post (
385+ "/xAPI/statements/" ,
386+ headers = {"Authorization" : f"Basic { auth_credentials } " },
387+ json = statement ,
388+ )
389+
390+ assert response .status_code == 200
391+ assert "error" not in spy
392+
393+
345394@pytest .mark .asyncio
346395@pytest .mark .parametrize (
347396 "forwarding_backend" , [get_es_test_backend , get_mongo_test_backend ]
0 commit comments