Skip to content

Commit 48b6205

Browse files
fix: fixing failing test cases
1 parent a4fd56a commit 48b6205

File tree

2 files changed

+81
-53
lines changed

2 files changed

+81
-53
lines changed

Access/tests/features/process_individual_request.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
""" Test for individual pending requests"""
2+
13
Scenario: No pending requests
24
Given individual_pending_requests is empty
35
When process_individual_requests is called

Access/tests/test_process_individual_request.py

Lines changed: 79 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
when,
88
)
99

10+
1011
import pytest
1112
from .. import accessrequest_helper
1213
import Access
@@ -16,46 +17,54 @@
1617
from django.db.models.query import QuerySet
1718
from datetime import datetime, timedelta
1819

20+
1921
@pytest.fixture
2022
def user(mocker):
2123
user = mocker.MagicMock()
2224
user.email = "[email protected]"
2325
user.user.username = "test-user"
2426
return user
2527

28+
2629
@pytest.fixture
2730
def context(mocker):
2831
context = mocker.MagicMock()
2932
return context
3033

34+
3135
@pytest.fixture
3236
def new_request(mocker):
3337
req = mocker.MagicMock()
34-
# req.user.user = mocker.MagicMock(spec=Access.models.User)
35-
# req.user.email = "[email protected]"
3638
return req
3739

3840

39-
40-
@scenario('./features/process_individual_request.feature', 'Multiple pending requests for a club')
41+
@scenario(
42+
"./features/process_individual_request.feature",
43+
"Multiple pending requests for a club",
44+
)
4145
def test_multiple_pending_requests_for_a_club():
4246
"""Multiple pending requests for a club."""
4347
pass
4448

4549

46-
@scenario('./features/process_individual_request.feature', 'Multiple pending requests for multiple clubs')
50+
@scenario(
51+
"./features/process_individual_request.feature",
52+
"Multiple pending requests for multiple clubs",
53+
)
4754
def test_multiple_pending_requests_for_multiple_clubs():
4855
"""Multiple pending requests for multiple clubs."""
4956
pass
5057

5158

52-
@scenario('./features/process_individual_request.feature', 'No pending requests')
59+
@scenario("./features/process_individual_request.feature", "No pending requests")
5360
def test_no_pending_requests():
5461
"""No pending requests."""
5562
pass
5663

5764

58-
@scenario('./features/process_individual_request.feature', 'Single pending request for a club')
65+
@scenario(
66+
"./features/process_individual_request.feature", "Single pending request for a club"
67+
)
5968
def test_single_pending_request_for_a_club():
6069
"""Single pending request for a club."""
6170
pass
@@ -73,25 +82,25 @@ def step_impl(context):
7382
context.club_id = "123"
7483

7584

76-
@given('individual_pending_requests contains a single pending request for a club')
77-
def step_impl(context,mocker):
85+
@given("individual_pending_requests contains a single pending request for a club")
86+
def step_impl(context, mocker):
7887
"""individual_pending_requests contains a single pending request for a club."""
79-
context.individual_pending_requests = [{
80-
"requestId": "123_request_1",
81-
"club_id": "123",
82-
"userEmail": "[email protected]",
83-
"accessReason": "test_reason",
84-
"access_desc": "test_access_desc",
85-
"access_tag": "access-tag-1",
86-
"requested_on": datetime.now().isoformat(),
87-
"accessCategory": "test_access_category",
88-
"accessMeta": "test_access_meta"
89-
}]
90-
91-
92-
93-
94-
@given('individual_pending_requests contains multiple pending requests for a club')
88+
context.individual_pending_requests = [
89+
{
90+
"requestId": "123_request_1",
91+
"club_id": "123",
92+
"userEmail": "[email protected]",
93+
"accessReason": "test_reason",
94+
"access_desc": "test_access_desc",
95+
"access_tag": "access-tag-1",
96+
"requested_on": datetime.now().isoformat(),
97+
"accessCategory": "test_access_category",
98+
"accessMeta": "test_access_meta",
99+
}
100+
]
101+
102+
103+
@given("individual_pending_requests contains multiple pending requests for a club")
95104
def step_impl(context):
96105
"""individual_pending_requests contains multiple pending requests for a club."""
97106
context.individual_pending_requests = [
@@ -103,7 +112,7 @@ def step_impl(context):
103112
"access_tag": "tag 1",
104113
"requested_on": datetime(2023, 5, 1, 10, 0, 0),
105114
"accessCategory": "category 1",
106-
"accessMeta": "meta 1"
115+
"accessMeta": "meta 1",
107116
},
108117
{
109118
"requestId": "123_2",
@@ -113,12 +122,14 @@ def step_impl(context):
113122
"access_tag": "tag 2",
114123
"requested_on": datetime(2023, 5, 1, 11, 0, 0),
115124
"accessCategory": "category 2",
116-
"accessMeta": "meta 2"
117-
}
125+
"accessMeta": "meta 2",
126+
},
118127
]
119128

120129

121-
@given('individual_pending_requests contains multiple pending requests for multiple clubs')
130+
@given(
131+
"individual_pending_requests contains multiple pending requests for multiple clubs"
132+
)
122133
def step_impl(context):
123134
"""individual_pending_requests contains multiple pending requests for multiple clubs."""
124135
context.individual_pending_requests = [
@@ -131,7 +142,7 @@ def step_impl(context):
131142
"access_tag": "access-tag-1",
132143
"requested_on": "2023-04-29T00:00:00Z",
133144
"accessCategory": "cat1",
134-
"accessMeta": "meta1"
145+
"accessMeta": "meta1",
135146
},
136147
{
137148
"requestId": "123_request2",
@@ -142,7 +153,7 @@ def step_impl(context):
142153
"access_tag": "access-tag-1",
143154
"requested_on": "2023-04-28T00:00:00Z",
144155
"accessCategory": "cat2",
145-
"accessMeta": "meta2"
156+
"accessMeta": "meta2",
146157
},
147158
{
148159
"requestId": "456_request1",
@@ -153,29 +164,32 @@ def step_impl(context):
153164
"access_tag": "access-tag-1",
154165
"requested_on": "2023-04-27T00:00:00Z",
155166
"accessCategory": "cat3",
156-
"accessMeta": "meta3"
157-
}
167+
"accessMeta": "meta3",
168+
},
158169
]
159170

160171

161-
@given('individual_pending_requests is empty')
172+
@given("individual_pending_requests is empty")
162173
def step_impl(context):
163174
"""individual_pending_requests is empty."""
164175
context.individual_pending_requests = []
165176
context.access_tag = "access-tag-1"
166177

167178

168-
@when('process_individual_requests is called')
169-
def step_impl(context,mocker):
179+
@when("process_individual_requests is called")
180+
def step_impl(context, mocker):
170181
"""process_individual_requests is called."""
171182
context.individual_requests = []
172183
access_tag = context.access_tag
173-
mocker.patch("Access.helpers.sla_breached",return_value=True)
174-
accessrequest_helper.process_individual_requests(context.individual_pending_requests, context.individual_requests, access_tag)
175-
184+
mocker.patch("Access.helpers.sla_breached", return_value=True)
185+
accessrequest_helper.process_individual_requests(
186+
context.individual_pending_requests, context.individual_requests, access_tag
187+
)
176188

177189

178-
@then('each entry should have club_id, userEmail, accessReason, accessType, requested_on, sla_breached, accessData')
190+
@then(
191+
"each entry should have club_id, userEmail, accessReason, accessType, requested_on, sla_breached, accessData"
192+
)
179193
def step_impl(context):
180194
"""each entry should have club_id, userEmail, accessReason, accessType, requested_on, sla_breached, accessData."""
181195
for request in context.individual_requests:
@@ -188,14 +202,18 @@ def step_impl(context):
188202
assert club_request["sla_breached"]
189203

190204

191-
@then('individual_requests should contain a single entry with module_tag "access-tag-1"')
205+
@then(
206+
'individual_requests should contain a single entry with module_tag "access-tag-1"'
207+
)
192208
def step_impl(context):
193209
"""individual_requests should contain a single entry with module_tag "access-tag-1"."""
194210
assert len(context.individual_requests) == 1
195211
assert context.individual_requests[0]["module_tag"] == "access-tag-1"
196212

197213

198-
@then('individual_requests should contain one entry for each club with module_tag "access-tag-1"')
214+
@then(
215+
'individual_requests should contain one entry for each club with module_tag "access-tag-1"'
216+
)
199217
def step_impl(context):
200218
"""individual_requests should contain one entry for each club with module_tag "access-tag-1"."""
201219
assert len(context.individual_requests[0]["requests"]) == 2
@@ -208,13 +226,15 @@ def step_impl(context):
208226
club_ids.remove(club_id)
209227

210228

211-
@then('individual_requests should remain unchanged')
229+
@then("individual_requests should remain unchanged")
212230
def step_impl(context):
213231
"""individual_requests should remain unchanged."""
214232
assert len(context.individual_requests) == 0
215233

216234

217-
@then('the accessData for each entry should contain all the pending requests for the corresponding club.')
235+
@then(
236+
"the accessData for each entry should contain all the pending requests for the corresponding club."
237+
)
218238
def step_impl(context):
219239
"""the accessData for each entry should contain all the pending requests for the corresponding club.."""
220240
for request in context.individual_requests:
@@ -223,17 +243,23 @@ def step_impl(context):
223243
access_data = club_request["accessData"]
224244
for pending_request in context.individual_pending_requests:
225245
if pending_request["club_id"] == club_id:
226-
assert len(pending_request)== 9
227-
246+
assert len(pending_request) == 9
247+
228248
assert len(context.individual_pending_requests) == 3
229-
230249

231-
@then('the accessData should contain all the pending requests for the club')
250+
251+
@then("the accessData should contain all the pending requests for the club")
232252
def step_impl(context):
233253
"""the accessData should contain all the pending requests for the club."""
234254
assert len(context.individual_requests[0]["requests"][0]["accessData"]) == 2
235-
assert context.individual_requests[0]["requests"][0]["accessData"][0]["requestId"] == "123_1"
236-
assert context.individual_requests[0]["requests"][0]["accessData"][1]["requestId"] == "123_2"
255+
assert (
256+
context.individual_requests[0]["requests"][0]["accessData"][0]["requestId"]
257+
== "123_1"
258+
)
259+
assert (
260+
context.individual_requests[0]["requests"][0]["accessData"][1]["requestId"]
261+
== "123_2"
262+
)
237263

238264

239265
@then('the entry should have club_id "123"')
@@ -242,8 +268,9 @@ def step_impl(context):
242268
assert context.individual_requests[0]["requests"][0]["club_id"] == "123"
243269

244270

245-
246-
@then('the entry should have userEmail, accessReason, accessType, requested_on, sla_breached, accessData')
271+
@then(
272+
"the entry should have userEmail, accessReason, accessType, requested_on, sla_breached, accessData"
273+
)
247274
def step_impl(context):
248275
"""the entry should have userEmail, accessReason, accessType, requested_on, sla_breached, accessData."""
249276
request = context.individual_requests[0]["requests"][0]
@@ -257,4 +284,3 @@ def step_impl(context):
257284
assert request["accessData"][0]["accessCategory"] == "test_access_category"
258285
assert request["accessData"][0]["accessMeta"] == "test_access_meta"
259286
assert request["accessData"][0]["requestId"] == "123_request_1"
260-

0 commit comments

Comments
 (0)