Skip to content

Commit cefd2fc

Browse files
authored
Merge pull request #127 from browserstack/test-validate_approver_permissions
test:bdd tests for validate approver permissions
2 parents 8eeb5e4 + 7ff5254 commit cefd2fc

File tree

2 files changed

+279
-0
lines changed

2 files changed

+279
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Feature: Validate Approver Permission
2+
3+
Scenario: User who made the request has primary approver access & access_mapping is not in pending state & module does not need secondary approval
4+
Given User who made request has primary approver access
5+
And access_mapping is not in pending state
6+
And Modules does not need secondary approval
7+
When validate_approver_permissions function is called
8+
Then Return value should be empty json
9+
10+
Scenario: _get_approver_permissions raises an Exception, the function should return error message as json
11+
Given _get_approver_permissions raises an exception when called
12+
When validate_approver_permissions function is called
13+
Then Return value should be error json
14+
15+
Scenario: User who made the request does not have any approver access & access_mapping is not in pending state & module does not need secondary approval
16+
Given User who made request not have any approver access
17+
And access_mapping is in pending state
18+
And Modules does not need secondary approval
19+
When validate_approver_permissions function is called
20+
Then Return value should be permission denied json
21+
22+
Scenario: User who made the request has secondary approver access & access_mapping is not in pending state & module supports secondary approval
23+
Given User who made request has secondary approver access
24+
And access_mapping is not in pending state
25+
And Modules supports secondary approval
26+
When validate_approver_permissions function is called
27+
Then Return value should be empty json
28+
29+
Scenario: User who made the request has primary approver access & access_mapping is not in pending state & module supports secondary approval
30+
Given User who made request has primary approver access with false response
31+
And access_mapping is not in pending state
32+
And Modules supports secondary approval
33+
When validate_approver_permissions function is called
34+
Then Return value should be permission denied json
35+
36+
37+
Scenario: When the user who made the request has primary approver access & access_mapping is in pending state & module does not need secondary approval
38+
Given User who made request has primary approver access
39+
And access_mapping is in pending state
40+
And Modules does not need secondary approval
41+
When validate_approver_permissions function is called
42+
Then Return value should be empty json
43+
44+
Scenario: When the user who made the request has primary approver access & access_mapping is in pending state & module does needs secondary approval
45+
Given User who made request has primary approver access
46+
And access_mapping is in pending state
47+
And Modules supports secondary approval
48+
When validate_approver_permissions function is called
49+
Then Return value should be empty json
50+
51+
Scenario: When the user who made the request has secondary approver access & access_mapping is in primary pending state & module does needs secondary approval
52+
Given User who made request has only secondary approver access with false response
53+
And access_mapping is in pending state
54+
And Modules does not need secondary approval
55+
When validate_approver_permissions function is called
56+
Then Return value should be permission denied json
57+
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
"""Validate Approver Permission feature tests."""
2+
3+
from pytest_bdd import (
4+
given,
5+
scenario,
6+
then,
7+
when,
8+
)
9+
from Access.accessrequest_helper import validate_approver_permissions
10+
import pytest
11+
12+
13+
@pytest.fixture
14+
def context(mocker):
15+
context = mocker.MagicMock()
16+
return context
17+
18+
19+
@pytest.fixture
20+
def access_mapping(mocker):
21+
access_mapping = mocker.MagicMock()
22+
access_mapping.access.access_lable = "test-lable"
23+
return access_mapping
24+
25+
26+
@pytest.fixture
27+
def request_1(mocker):
28+
request_1 = mocker.MagicMock()
29+
return request_1
30+
31+
32+
@pytest.fixture
33+
def access_type(mocker):
34+
access_type = mocker.MagicMock()
35+
return access_type
36+
37+
38+
@scenario(
39+
"features/validate_approver_permissions.feature",
40+
"User who made the request does not have any approver access & access_mapping is not in pending state & module does not need secondary approval",
41+
)
42+
def test_user_who_made_the_request_does_not_have_any_approver_access__access_mapping_is_not_in_pending_state__module_does_not_need_secondary_approval():
43+
"""User who made the request does not have any approver access & access_mapping is not in pending state & module does not need secondary approval."""
44+
pass
45+
46+
47+
@scenario(
48+
"features/validate_approver_permissions.feature",
49+
"User who made the request has primary approver access & access_mapping is not in pending state & module does not need secondary approval",
50+
)
51+
def test_user_who_made_the_request_has_primary_approver_access__access_mapping_is_not_in_pending_state__module_does_not_need_secondary_approval():
52+
"""User who made the request has primary approver access & access_mapping is not in pending state & module does not need secondary approval."""
53+
pass
54+
55+
56+
@scenario(
57+
"features/validate_approver_permissions.feature",
58+
"User who made the request has primary approver access & access_mapping is not in pending state & module supports secondary approval",
59+
)
60+
def test_user_who_made_the_request_has_primary_approver_access__access_mapping_is_not_in_pending_state__module_supports_secondary_approval():
61+
"""User who made the request has primary approver access & access_mapping is not in pending state & module supports secondary approval."""
62+
pass
63+
64+
65+
@scenario(
66+
"features/validate_approver_permissions.feature",
67+
"User who made the request has secondary approver access & access_mapping is not in pending state & module supports secondary approval",
68+
)
69+
def test_user_who_made_the_request_has_secondary_approver_access__access_mapping_is_not_in_pending_state__module_supports_secondary_approval():
70+
"""User who made the request has secondary approver access & access_mapping is not in pending state & module supports secondary approval."""
71+
pass
72+
73+
74+
@scenario(
75+
"features/validate_approver_permissions.feature",
76+
"When the user who made the request has primary approver access & access_mapping is in pending state & module does needs secondary approval",
77+
)
78+
def test_when_the_user_who_made_the_request_has_primary_approver_access__access_mapping_is_in_pending_state__module_does_needs_secondary_approval():
79+
"""When the user who made the request has primary approver access & access_mapping is in pending state & module does needs secondary approval."""
80+
pass
81+
82+
83+
@scenario(
84+
"features/validate_approver_permissions.feature",
85+
"When the user who made the request has primary approver access & access_mapping is in pending state & module does not need secondary approval",
86+
)
87+
def test_when_the_user_who_made_the_request_has_primary_approver_access__access_mapping_is_in_pending_state__module_does_not_need_secondary_approval():
88+
"""When the user who made the request has primary approver access & access_mapping is in pending state & module does not need secondary approval."""
89+
pass
90+
91+
92+
@scenario(
93+
"features/validate_approver_permissions.feature",
94+
"When the user who made the request has secondary approver access & access_mapping is in primary pending state & module does needs secondary approval",
95+
)
96+
def test_when_the_user_who_made_the_request_has_secondary_approver_access__access_mapping_is_in_primary_pending_state__module_does_needs_secondary_approval():
97+
"""When the user who made the request has secondary approver access & access_mapping is in primary pending state & module does needs secondary approval."""
98+
pass
99+
100+
101+
@scenario(
102+
"features/validate_approver_permissions.feature",
103+
"_get_approver_permissions raises an Exception, the function should return error message as json",
104+
)
105+
def test__get_approver_permissions_raises_an_exception_the_function_should_return_error_message_as_json():
106+
"""_get_approver_permissions raises an Exception, the function should return error message as json."""
107+
pass
108+
109+
110+
@given("Modules does not need secondary approval")
111+
def step_impl(access_mapping):
112+
"""Modules does not need secondary approval."""
113+
access_mapping.is_secondary_pending.return_value = True
114+
115+
116+
@given("Modules supports secondary approval")
117+
def step_impl(access_mapping):
118+
"""Modules supports secondary approval."""
119+
access_mapping.is_secondary_pending.return_value = True
120+
121+
122+
@given("User who made request has primary approver access")
123+
def step_impl(context, mocker, access_mapping, request_1):
124+
"""User who made request has primary approver access."""
125+
mock_permissions = {"approver_permissions": {"1": "ACCESS_APPROVE", "2": ""}}
126+
mocker.patch(
127+
"Access.accessrequest_helper._get_approver_permissions",
128+
return_value=mock_permissions,
129+
)
130+
request_1.user.user.has_permission.return_value = True
131+
132+
133+
@given("User who made request has primary approver access with false response")
134+
def step_impl(context, mocker, access_mapping, request_1):
135+
"""User who made request has primary approver access."""
136+
mock_permissions = {"approver_permissions": {"1": "ACCESS_APPROVE", "2": ""}}
137+
mocker.patch(
138+
"Access.accessrequest_helper._get_approver_permissions",
139+
return_value=mock_permissions,
140+
)
141+
request_1.user.user.has_permission.return_value = False
142+
143+
144+
@given("User who made request has secondary approver access")
145+
def step_impl(mocker, context, access_mapping, request_1):
146+
mock_permissions = {"approver_permissions": {"1": "", "2": "ACCESS_APPROVE"}}
147+
mocker.patch(
148+
"Access.accessrequest_helper._get_approver_permissions",
149+
return_value=mock_permissions,
150+
)
151+
request_1.user.user.has_permission.return_value = True
152+
153+
154+
@given("User who made request has only secondary approver access with false response")
155+
def step_impl(mocker, context, access_mapping, request_1):
156+
mock_permissions = {"approver_permissions": {"1": "", "2": "ACCESS_APPROVE"}}
157+
mocker.patch(
158+
"Access.accessrequest_helper._get_approver_permissions",
159+
return_value=mock_permissions,
160+
)
161+
request_1.user.user.has_permission.return_value = False
162+
163+
164+
@given("User who made request not have any approver access")
165+
def step_impl(mocker, request_1):
166+
mock_permissions = {"approver_permissions": {"1": "", "2": ""}}
167+
mocker.patch(
168+
"Access.accessrequest_helper._get_approver_permissions",
169+
return_value=mock_permissions,
170+
)
171+
request_1.user.user.has_permission.return_value = False
172+
173+
174+
@given("_get_approver_permissions raises an exception when called")
175+
def step_impl(mocker):
176+
"""_get_approver_permissions raises an exception when called."""
177+
mock_response = {"error": "Error in request not found OR Invalid request type"}
178+
mocker.patch(
179+
"Access.accessrequest_helper.process_error_response", return_value=mock_response
180+
)
181+
mock_exception = Exception("Error in request not found OR Invalid request type")
182+
mocker.patch(
183+
"Access.accessrequest_helper._get_approver_permissions",
184+
side_effect=mock_exception,
185+
)
186+
187+
188+
@given("access_mapping is in pending state")
189+
def step_impl(access_mapping, mocker):
190+
"""access_mapping is in pending state."""
191+
print("here in pending true")
192+
access_mapping.is_pending.return_value = True
193+
194+
195+
@given("access_mapping is not in pending state")
196+
def step_impl(access_mapping, mocker):
197+
"""access_mapping is not in pending state."""
198+
access_mapping.is_pending.return_value = False
199+
200+
201+
@when("validate_approver_permissions function is called", target_fixture="response")
202+
def step_impl(mocker, access_mapping, context, access_type, request_1):
203+
"""validate_approver_permissions function is called."""
204+
return validate_approver_permissions(access_mapping, access_type, request_1)
205+
206+
207+
@then("Return value should be empty json")
208+
def step_impl(response):
209+
"""Return value should be empty json."""
210+
assert response == {}
211+
212+
213+
@then("Return value should be error json")
214+
def step_impl(response):
215+
"""Return value should be error json."""
216+
assert response == {"error": "Error in request not found OR Invalid request type"}
217+
218+
219+
@then("Return value should be permission denied json")
220+
def step_impl(response):
221+
"""Return value should be permission denied json."""
222+
assert response == {"error": "Permission Denied!"}

0 commit comments

Comments
 (0)