-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_get_grant_failure_requests.py
More file actions
100 lines (82 loc) · 3.44 KB
/
test_get_grant_failure_requests.py
File metadata and controls
100 lines (82 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""test get_grant_fail_requests feature tests."""
from pytest_bdd import (
given,
scenario,
then,
when,
)
import pytest
from .. import accessrequest_helper
from Access import helpers
import Access
from Access.models import User
from Access.models import UserAccessMapping
from django.db.models.query import QuerySet
@pytest.fixture
def user(mocker):
user = mocker.MagicMock()
user.email = "test@test.com"
user.user.username = "test-user"
return user
@pytest.fixture
def context(mocker):
context = mocker.MagicMock()
return context
@pytest.fixture
def new_request(mocker):
req = mocker.MagicMock()
return req
@scenario('./features/get_grant_failed_requests.feature', 'Handling errors')
def test_handling_errors():
"""Handling errors."""
pass
@scenario('./features/get_grant_failed_requests.feature', 'Retrieving all grant failure requests')
def test_retrieving_all_grant_failure_requests():
"""Retrieving all grant failure requests."""
pass
@given('an error occurs while executing the method')
def step_impl(mocker,context):
"""an error occurs while executing the method."""
mock_response = {"error": "Error in request not found OR Invalid request type"}
context.mock_user_access_mapping = mocker.MagicMock(spec=UserAccessMapping)
context.mock_user = mocker.MagicMock(spec=User)
orderByPatch = mocker.MagicMock()
mock_response = {"error": "Error in request not found OR Invalid request type"}
mocker.patch(
"Access.accessrequest_helper.process_error_response", return_value=mock_response
)
mock_exception = Exception("Error in request not found OR Invalid request type")
orderByPatch.order_by.return_value = mocker.MagicMock()
mocker.patch(
"Access.models.UserAccessMapping.objects.filter", side_effect=mock_exception,
)
@given('there are grant failure requests in the database')
@pytest.mark.django_db
def step_impl(mocker,context):
"""there are grant failure requests in the database."""
context.mock_user_access_mapping = mocker.MagicMock(spec=UserAccessMapping)
context.mock_user = mocker.MagicMock(spec=User)
orderByPatch = mocker.MagicMock()
orderByPatch.order_by.return_value = mocker.MagicMock()
mocker.patch(
"Access.models.UserAccessMapping.objects.filter", return_value=orderByPatch
)
queryset_mock = mocker.MagicMock()
context.request.GET.get.return_value = False
mocker.patch("Access.models.User.objects.get",return_value=mocker.MagicMock())
queryset_mock.filter.order_by.return_value="request_1"
@when('the get_grant_failed_requests method is called')
def step_impl(mocker,new_request,context):
"""the get_grant_failed_requests method is called."""
context.request = mocker.MagicMock()
context.result = accessrequest_helper.get_grant_failed_requests(context.request)
@then('it should return a context containing all grant failure requests sorted by requested_on date in descending order')
def step_impl(mocker,context):
"""it should return a context containing all grant failure requests sorted by requested_on date in descending order."""
assert context.result['failures'] is not None
@then('it should return an error response with details of the error.')
def step_impl(mocker,context):
"""it should return an error response with details of the error.."""
assert context.result == {
"error": "Error in request not found OR Invalid request type"
}