17
17
# Mock Objects
18
18
mockReply = MagicMock ()
19
19
mockReply1 = MagicMock ()
20
+ mockGetDNForUsername = MagicMock ()
21
+ mockGetVomsAttr = MagicMock ()
22
+ mockGetProxy = MagicMock ()
20
23
mockOperations = MagicMock ()
21
24
mockTornadoClient = MagicMock ()
22
25
mockDataManager = MagicMock ()
@@ -48,19 +51,16 @@ def plaBase(mocker):
48
51
mocker .patch (
49
52
"DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.Operations.getOptionsDict" , side_effect = mockReply1
50
53
)
54
+ mocker .patch (
55
+ "DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.getDNForUsername" , side_effect = mockGetDNForUsername
56
+ )
57
+ mocker .patch ("DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.getProxy" , side_effect = mockGetProxy )
51
58
pla = PilotLoggingAgent ()
52
59
pla .log = gLogger
53
60
pla ._AgentModule__configDefaults = mockAM
54
61
return pla
55
62
56
63
57
- @pytest .fixture
58
- def pla_initialised (mocker , plaBase ):
59
- mocker .patch ("DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.PilotLoggingAgent.executeForVO" )
60
- plaBase .initialize ()
61
- return plaBase
62
-
63
-
64
64
@pytest .fixture
65
65
def pla (mocker , plaBase ):
66
66
mocker .patch (
@@ -72,42 +72,60 @@ def pla(mocker, plaBase):
72
72
"DIRAC.WorkloadManagementSystem.Agent.PilotLoggingAgent.DataManager" ,
73
73
side_effect = mockDataManager ,
74
74
)
75
- plaBase .initialize ()
76
75
return plaBase
77
76
78
77
79
- def test_initialize (plaBase ):
78
+ @pytest .mark .parametrize (
79
+ "remoteLogging, options, getDN, getVOMS, getProxy, resDict, expectedRes" ,
80
+ [
81
+ ([True , False ], upDict , S_OK (["myDN" ]), S_OK (), S_OK ("proxyfilename" ), {"gridpp" : "proxyfilename" }, S_OK ()),
82
+ ([False , False ], upDict , S_OK (["myDN" ]), S_OK (), S_OK (), {}, S_OK ()),
83
+ ([True , False ], upDict , S_ERROR ("Could not obtain a DN" ), S_OK (), S_OK (), {}, S_OK ()),
84
+ ([True , False ], upDict , S_ERROR ("Could not download proxy" ), S_OK (), S_ERROR ("Failure" ), {}, S_OK ()),
85
+ ],
86
+ )
87
+ def test_initialize (plaBase , remoteLogging , options , getDN , getVOMS , getProxy , resDict , expectedRes ):
88
+ """
89
+ After a successful initialisation the proxyDict should contain proxy filenames key by a VO name.
90
+ test loops: gridpp enabled, lz disabled, proxy obtained, result proxyDict contains a proxy filename.
91
+ both VOs disabled => proxyDict empty
92
+ gridpp enabled, by getDNForUsername fails => proxyDict empty
93
+ gridpp enabled, lz disabled, getProxy fails => proxyDict empty
94
+
95
+ """
96
+ mockReply .side_effect = remoteLogging # Operations.getValue("/Pilot/RemoteLogging", False)
97
+ mockReply1 .return_value = options # Operations.getOptionsDict("Shifter/DataManager")
98
+ mockGetDNForUsername .return_value = getDN
99
+ mockGetVomsAttr .return_value = getVOMS
100
+ mockGetProxy .return_value = getProxy
101
+
80
102
res = plaBase .initialize ()
103
+
81
104
assert plaBase .voList == plaModule .getVOs ()["Value" ]
82
- assert res == S_OK ()
105
+ assert resDict == plaBase .proxyDict
106
+ assert res == expectedRes
83
107
84
108
85
109
@pytest .mark .parametrize (
86
- "mockReplyInput, expected, expectedExecOut, expected2 " ,
110
+ "proxyDict, execVORes, expectedResult " ,
87
111
[
88
- ("/Pilot/RemoteLogging" , [True , False ], S_OK (), upDict ),
89
- ("/Pilot/RemoteLogging" , [False , False ], S_OK (), upDict ),
90
- ("/Pilot/RemoteLogging" , [True , False ], S_ERROR ("Execute for VO failed" ), upDict ),
112
+ ({}, S_OK (), S_OK ()),
113
+ ({"gridpp" : "gridpp_proxyfile" }, S_OK (), S_OK ()),
114
+ (
115
+ {"gridpp" : "gridpp_proxyfile" },
116
+ S_ERROR ("Execute for VO failed" ),
117
+ S_ERROR ("Agent cycle for some VO finished with errors" ),
118
+ ),
91
119
],
92
120
)
93
- def test_execute (pla_initialised , mockReplyInput , expected , expectedExecOut , expected2 ):
121
+ def test_execute (plaBase , proxyDict , execVORes , expectedResult ):
94
122
"""Testing a thin version of execute (executeForVO is mocked)"""
95
- assert pla_initialised .voList == plaModule .getVOs ()["Value" ]
96
- mockReply .side_effect = expected
97
- mockReply1 .return_value = expected2
98
- # remote pilot logging on (gridpp only) and off.
99
- pla_initialised .executeForVO .return_value = expectedExecOut
100
- res = pla_initialised .execute ()
101
- if not any (expected ):
102
- pla_initialised .executeForVO .assert_not_called ()
103
- else :
104
- assert pla_initialised .executeForVO .called
105
- pla_initialised .executeForVO .assert_called_with (
106
- "gridpp" ,
107
- proxyUserName = upDict ["Value" ]["User" ],
108
- proxyUserGroup = upDict ["Value" ]["Group" ],
109
- )
110
- assert res ["OK" ] == expectedExecOut ["OK" ]
123
+
124
+ plaBase .executeForVO = MagicMock ()
125
+ plaBase .proxyDict = proxyDict
126
+ plaBase .executeForVO .return_value = execVORes
127
+ res = plaBase .execute ()
128
+ assert res ["OK" ] == expectedResult ["OK" ]
111
129
112
130
113
131
@pytest .mark .parametrize (
0 commit comments