I am mocking in some unit tests, and I am wondering whether is fine or recommended to use real data (I am dealing with non-sensitive data) when mocking.
For instance, I am testing the user's members which are allowed to authenticate in an application by using an azure service principal here:
def create_mock(status_code, data):
def mocked_requests(*args, **kwargs):
class MockResponse:
def __init__(self, status_code, json_data):
self.json_data = json_data
self.status_code = status_code
def json(self):
return self.json_data
return MockResponse(status_code, data)
return mocked_requests
class RolesTestCase(unittest.TestCase):
@mock.patch('requests.get',
side_effect=create_mock(
200,
# HERE MY OBJECT OR DATA MOCKED.
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals('99999')/appRoleAssignedTo",
"value": [{
"id": "99999",
"deletedDateTime": "null",
"appRoleId": "00000000-0000-0000-0000-000000000000",
"createdDateTime": "2021-03-21T17:15:40.516616Z",
"principalDisplayName": "Bernardo Garcia Loaiza",
"principalId": "99999",
"principalType": "User",
"resourceDisplayName": "my-service-principal-name",
"resourceId": "99999"
}]
}
)
)
@mock.patch('roles.get_sp_object_id')
def test_get_user_role_assignments(self, get_sp_object_id, mock):
token = "FOOBAR"
get_user_role_assignments(token, {"id": "123", "name": "group_name"})
get_sp_object_id.assert_called_with(token, {"id": "123", "name": "group_name"})
At the @mock.patch('requests.get, ...'
code section above, is ok if instead of 99999
values on the JSON doc, I put the real values?