def test_creat_vendor_ok_response( self, mock_new_vendor, mock_request_params, mock_get_location ): '''Test create_vendor OK response. ''' mock_get_location.return_value = 1 mock_request_params.return_value = ( self.fake.name(), self.fake.phone_number(), self.fake.address(), True, self.fake.name() ) mock_new_vendor.return_value = self.mock_vendor vendor_controller = VendorController(self.request_context) # Act result = vendor_controller.create_vendor() # Assert assert result.status_code == 201 assert result.get_json()['msg'] == 'OK'
def index(): if request.method == 'GET': text_query = request.args.get('q', None) vendors = None if text_query != None: vendors = VendorController.find_by_name(text_query) else: vendors = VendorController.get_all_vendors() return {"vendors": vendors} if request.method == 'POST': req_body = request.json res = VendorController.create_vendor(req_body) return { 'vendor': res.get('value'), 'success': res.get('success', False), 'message': res.get('message') } if request.method == 'DELETE': success = VendorController.delete_all_vendors() return {"success": success}