def test_update_vendor_ok_response( self, mock_vendor_repo_get, mock_request_params ): '''Test update_vendor OK response. ''' # Arrange with self.app.app_context(): mock_request_params.return_value = ( self.fake.name(), self.fake.phone_number(), self.fake.address(), True, self.fake.name() ) mock_vendor_repo_get.return_value = self.mock_vendor vendor_controller = VendorController(self.request_context) # Act result = vendor_controller.update_vendor(1) # Assert assert result.status_code == 200 assert result.get_json()['msg'] == 'OK'
def test_update_vendor_when_vendor_doesnot_exist( self, mock_vendor_repo_get, mock_request_params ): '''Test update_vendor when vendor doesnot exist. ''' # Arrange with self.app.app_context(): mock_request_params.return_value = ( self.fake.name(), self.fake.phone_number(), self.fake.address(), True, self.fake.name() ) mock_vendor_repo_get.return_value = None vendor_controller = VendorController(self.request_context) # Act result = vendor_controller.update_vendor(1) # Assert assert result.status_code == 400 assert result.get_json()['msg'] == 'Invalid or incorrect ' \ 'vendor_id provided'
def vendor_by_id(vendor_id=None): if request.method == 'GET': message = 'vendor not found' vendor = VendorController.find_by_id(vendor_id) return { 'vendor': vendor, 'success': True if vendor else False, 'message': None if vendor else message } if request.method == 'PUT': req_body = request.json res = VendorController.update_vendor(vendor_id, req_body) return { 'vendor': res.get('value'), 'success': res.get('success', False), 'message': res.get('message') } if request.method == 'DELETE': res = VendorController.delete_vendor(vendor_id) return { 'success': res.get('success', False), 'message': res.get('message') }