forked from DIRACGrid/DIRAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (diracx): Add an equivalent forwardDISET for DiracX
- Loading branch information
Showing
6 changed files
with
167 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pytest | ||
from DIRAC.Core.Utilities.ReturnValues import convertToReturnValue | ||
from DIRAC.Core.Security.DiracX import addRPCStub, executeRPCStub, FutureClient | ||
|
||
|
||
class BadClass: | ||
"""This class does not inherit from FutureClient | ||
So we should not be able to execute its stub""" | ||
|
||
@addRPCStub | ||
@convertToReturnValue | ||
def sum(self, *args, **kwargs): | ||
"""Just sum whatever is given as param""" | ||
return sum(args + tuple(kwargs.values())) | ||
|
||
|
||
class Fake(FutureClient): | ||
@addRPCStub | ||
@convertToReturnValue | ||
def sum(self, *args, **kwargs): | ||
"""Just sum whatever is given as param""" | ||
return sum(args + tuple(kwargs.values())) | ||
|
||
|
||
def test_rpcStub(): | ||
b = BadClass() | ||
res = b.sum(1, 2, 3) | ||
assert res["OK"] | ||
assert "rpcStub" in res | ||
stub = res["rpcStub"] | ||
# Cannot execute this stub as it does not come | ||
# from a FutureClient | ||
with pytest.raises(TypeError): | ||
executeRPCStub(stub) | ||
|
||
def test_sum(f, *args, **kwargs): | ||
"""Test that the original result is the same as the stub""" | ||
|
||
res = f.sum(*args, **kwargs) | ||
stub = res["rpcStub"] | ||
replay_res = executeRPCStub(stub) | ||
|
||
assert res["OK"] == replay_res["OK"] | ||
assert res.get("Value") == replay_res.get("Value") | ||
assert res.get("Message") == replay_res.get("Message") | ||
|
||
# Test some success cases | ||
|
||
f = Fake() | ||
test_sum(f, 1, 2, 3) | ||
test_sum(f, a=3, b=4) | ||
test_sum(f, 1, 2, a=3, b=4) | ||
|
||
# Test error case | ||
|
||
test_sum(f, "a", None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/DIRAC/WorkloadManagementSystem/FutureClient/test/Test_JobStateUpdateClient.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from DIRAC.WorkloadManagementSystem.FutureClient.JobStateUpdateClient import JobStateUpdateClient | ||
|
||
|
||
def test_setJobStatusBulk_hasStub(): | ||
"""Makes sure that the setJobStatusBulk call return an RPC stub""" | ||
client = JobStateUpdateClient() | ||
res = client.setJobAttribute(123, "toto", "pipo") | ||
assert not res["OK"] | ||
assert "rpcStub" not in res | ||
|
||
res = client.setJobStatusBulk(123, {}) | ||
assert not res["OK"] | ||
assert "rpcStub" in res |
Empty file.