-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@adrilene/@denisousa] issue #73 WIP testes do post
- Loading branch information
Showing
5 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from flask import make_response, jsonify | ||
from http import HTTPStatus | ||
|
||
def error_response(message, status=400): | ||
return make_response( | ||
jsonify({ | ||
"error": message, | ||
}), | ||
status | ||
) | ||
|
||
|
||
def get_response(content, deleted): | ||
response = {'content': content} | ||
|
||
response['deleted'] = True if deleted else False | ||
|
||
return make_response(jsonify(response), HTTPStatus.OK) | ||
|
||
|
||
def post_response(content): | ||
return make_response(jsonify({'content': content}), 201) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mock_service_orders = { | ||
'service_order_with_id': { | ||
'_id': '123' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import json | ||
from run import app | ||
from unittest import TestCase | ||
from mockito import when, mock | ||
from ...mocks.mock_service_orders import mock_service_orders | ||
from api.v2.models.schemas.service_order_schema import ServiceOrderSchema | ||
from http import HTTPStatus | ||
|
||
|
||
class ServiceOrdersSchema(TestCase): | ||
def setUp(self): | ||
self.client = app.test_client() | ||
|
||
def test_body_with_id_returns_error(self): | ||
erro_schema = [{'0': 'Id must not be sent'}] | ||
when(ServiceOrderSchema).validate_post( | ||
mock_service_orders['service_order_with_id'] | ||
).thenReturn(erro_schema) | ||
|
||
payload = json.dumps({'content': [mock_service_orders['service_order_with_id']]}) | ||
|
||
# response = self.client.post( | ||
# '/v2/service_orders', | ||
# headers={"Content-Type": "application/json"}, | ||
# data=payload) | ||
|
||
# error = response.json | ||
# # self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST) | ||
# self.assertIn('error', error) | ||
# self.assertEqual(type(error['error']), list) | ||
# self.assertIn('0', error['error'][0]) | ||
# self.assertEqual(error['error'][0]['0'], 'Id must not be sent') |