-
Notifications
You must be signed in to change notification settings - Fork 176
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
4 changed files
with
154 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