Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Start integrating pytest #6827

Merged
merged 16 commits into from May 7, 2020
67 changes: 26 additions & 41 deletions tests/all/unit/api/helpers/test_errors.py
@@ -1,5 +1,3 @@
from unittest import TestCase

from app.api.helpers.errors import (
BadRequestError,
ErrorResponse,
Expand All @@ -10,42 +8,29 @@
)


class TestErrorDetails(TestCase):
"""Test for error responses"""

def test_error_response_dict_details(self):
"""To test details in the form of dict"""

error_response = ErrorResponse(source="test source", detail="test detail")
expected_dict = {
'status': error_response.status,
'source': error_response.source,
'title': error_response.title,
'detail': error_response.detail,
}
self.assertEqual(error_response.to_dict(), expected_dict)

def test_errors(self):
"""Method to test the status code of all errors"""

# Forbidden Error
forbidden_error = ForbiddenError({'source': ''}, 'Super admin access is required')
self.assertEqual(forbidden_error.status, 403)

# Not Found Error
not_found_error = NotFoundError({'source': ''}, 'Object not found.')
self.assertEqual(not_found_error.status, 404)

# Server Error
server_error = ServerError({'source': ''}, 'Internal Server Error')
self.assertEqual(server_error.status, 500)

# UnprocessableEntity Error
unprocessable_entity_error = UnprocessableEntityError(
{'source': ''}, 'Entity cannot be processed'
)
self.assertEqual(unprocessable_entity_error.status, 422)

# Bad Request Error
bad_request_error = BadRequestError({'source': ''}, 'Request cannot be served')
self.assertEqual(bad_request_error.status, 400)
def test_error_response_dict_details():
"""To test details in the form of dict"""
error_response = ErrorResponse(source="test source", detail="test detail")
expected_dict = {
'status': error_response.status,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-commit ran black

'source': error_response.source,
'title': error_response.title,
'detail': error_response.detail,
}
assert error_response.to_dict() == expected_dict


def test_errors():
"""Method to test the status code of all errors"""
forbidden_error = ForbiddenError({'source': ''}, 'Super admin access is required')
assert forbidden_error.status == 403
not_found_error = NotFoundError({'source': ''}, 'Object not found.')
assert not_found_error.status == 404
server_error = ServerError({'source': ''}, 'Internal Server Error')
assert server_error.status == 500
unprocessable_entity_error = UnprocessableEntityError(
{'source': ''}, 'Entity cannot be processed'
)
assert unprocessable_entity_error.status == 422
bad_request_error = BadRequestError({'source': ''}, 'Request cannot be served')
assert bad_request_error.status == 400