Skip to content

Commit

Permalink
[@adrilene/@denisousa] Issue #73 - Iniciando testes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrilene committed Jun 22, 2020
1 parent 34cc1a0 commit 198ad29
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions api/v2/controllers/service_orders_many_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ def get(self):
service_orders = ServiceOrderService().fetch_active()

return get_response(service_orders, deleted_included)

def post(self):

return ''
1 change: 0 additions & 1 deletion api/v2/migrations/items_from_diagnostico_service_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def fetch_items_from_diagnostico(self):
items[reference_key] = item
continue
items[reference_key]['quantidade'] += item['quantidade']
print(items)
return items

def generate_reference_key(self, item):
Expand Down
28 changes: 22 additions & 6 deletions tests/v2/controllers/test_service_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
from mockito import when, mock
from api.v2.services.service_order_service import ServiceOrderService
from http import HTTPStatus
from bson.objectid import ObjectId


class ServiceOrdersController(TestCase):
def setUp(self):
self.client = app.test_client()

# GET tests
def test_returns_service_orders_on_successful_request(self):
service_orders = [{'equipamento_id': 1, 'numero_ordem_servico': '0400'}]
service_orders = [
{'equipamento_id': 1, 'numero_ordem_servico': '0400'}]
when(ServiceOrderService).fetch_active().thenReturn(service_orders)

response = self.client.get('/v2/service_orders')
Expand All @@ -21,8 +24,8 @@ def test_returns_service_orders_on_successful_request(self):
self.assertEqual(type(content), list)
self.assertIn('content', response.json)
self.assertIn('equipamento_id', content[0])
self.assertEqual(content[0]['equipamento_id'], service_orders[0]['equipamento_id'])

self.assertEqual(content[0]['equipamento_id'],
service_orders[0]['equipamento_id'])

def test_returns_empty_list(self):
service_orders = []
Expand All @@ -34,16 +37,29 @@ def test_returns_empty_list(self):
self.assertEqual(response.json['content'], [])

def test_returns_deleted_service_orders_on_successful_request(self):
service_orders = [{'equipamento_id': 1, 'numero_ordem_servico': '0400'}]
service_orders = [
{'equipamento_id': 1, 'numero_ordem_servico': '0400'}]
when(ServiceOrderService).fetch_all().thenReturn(service_orders)

response = self.client.get('/v2/service_orders?deleted=true')

self.assertEqual(response.status_code, HTTPStatus.OK)
content = response.json['content']
self.assertEqual(content[0]['equipamento_id'], service_orders[0]['equipamento_id'])
self.assertEqual(content[0]['equipamento_id'],
service_orders[0]['equipamento_id'])

def test_return_invalid_param_error(self):
response = self.client.get('/v2/service_orders?deleted=trueee')
self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
self.assertEqual(response.json['error'], 'Parameter deleted is not equal true.')
self.assertEqual(response.json['error'],
'Parameter deleted is not equal true.')

# POST tests
def test_returns_list_id(self):
service_order_id = '5ee37c19d86b6a8893d1a3a7' # Fake Id
when(ServiceOrderService).register().thenReturn(service_order_id)

response = self.client.post('/v2/service_orders')
self.assertEqual(type(response.json['content']), list)
for id in response.json['content']:
self.assertEqual(ObjectId.is_valid(id), True)

0 comments on commit 198ad29

Please sign in to comment.