def get_legacy_params(): legacy_params = reqparse.RequestParser() legacy_params.add_argument('s', type=str, dest='source', required=True) legacy_params.add_argument('t', type=str, dest='target', required=True) legacy_params.add_argument( 'n', type=inputs.int_range(low=0, high=configuration.get_config_int( 'api', 'count_max')), dest='count', required=False, default=configuration.get_config_int('api', 'count_default')) legacy_params.add_argument('article', type=inputs.regex(r'^([^|]+(\|[^|]+)*)?$'), dest='seed', required=False) legacy_params.add_argument('pageviews', type=inputs.boolean, dest='include_pageviews', required=False, default=True) legacy_params.add_argument('search', type=str, required=False, default='morelike', choices=['morelike', 'wiki']) return legacy_params
def get_v1_params(): v1_params = reqparse.RequestParser() v1_params.add_argument('source', type=str, required=True) v1_params.add_argument('target', type=str, required=True) v1_params.add_argument( 'count', type=inputs.int_range(low=0, high=configuration.get_config_int( 'api', 'count_max')), required=False, default=configuration.get_config_int('api', 'count_default')) v1_params.add_argument('seed', type=inputs.regex(r'^([^|]+(\|[^|]+)*)?$'), required=False) v1_params.add_argument('include_pageviews', type=inputs.boolean, required=False, default=True) v1_params.add_argument( 'search', type=str, required=False, default='morelike', choices=['morelike', 'wiki', 'related_articles', 'category']) v1_params.add_argument('rank_method', type=str, required=False, default='default', choices=['default', 'sitelinks']) v1_params.add_argument('campaign', type=str, required=False, default='') return v1_params
def get_v1_articles_params(): v1_articles_params = reqparse.RequestParser() v1_articles_params.add_argument('source', type=str, required=True) v1_articles_params.add_argument( 'count', type=inputs.int_range(low=0, high=configuration.get_config_int( 'api', 'count_max')), required=False, default=configuration.get_config_int('api', 'count_default')) v1_articles_params.add_argument('seed', type=inputs.regex(r'^[^|]+(\|[^|]+)*$'), required=True) return v1_articles_params
def test_inclusive_range(self): int_range = inputs.int_range(1, 5) assert_equal(5, int_range(5))
def test_inclusive_range(self): int_range = inputs.int_range(1, 5) assert int_range(5) == 5
def test_higher(self): int_range = inputs.int_range(0, 5) with pytest.raises(ValueError): int_range(6)
def test_valid_range(self): int_range = inputs.int_range(1, 5) assert int_range(3) == 3
type=inputs.regex(position_regex), action='append') annons_complete_query.add_argument(settings.POSITION_RADIUS, type=int, action='append') annons_complete_query.add_argument(settings.EMPLOYER, action='append') annons_complete_query.add_argument(settings.FREETEXT_QUERY) annons_complete_query.add_argument(settings.FREETEXT_FIELDS, action='append', choices=QF_CHOICES) pb_query = annons_complete_query.copy() pb_query.add_argument(settings.MIN_RELEVANCE, type=float), pb_query.add_argument(settings.DETAILS, choices=[OPTIONS_FULL, OPTIONS_BRIEF]) pb_query.add_argument(settings.OFFSET, type=inputs.int_range(0, settings.MAX_OFFSET), default=0) pb_query.add_argument(settings.LIMIT, type=inputs.int_range(0, settings.MAX_LIMIT), default=10) # TODO: Remove sort_option 'id' in next major version pb_query.add_argument(settings.SORT, choices=list(fields.sort_options.keys()) + ['id']) pb_query.add_argument( settings.STATISTICS, action='append', choices=[taxonomy.OCCUPATION, taxonomy.GROUP, taxonomy.FIELD]) pb_query.add_argument(settings.STAT_LMT, type=inputs.int_range(0, 30), required=False)
@track_usage def delete(self): """Deletes a video game by a given ID""" args = idParser.parse_args() ID = args.get('ID') if ID not in vgs_df_global.index: api.abort(404, "Video game {} doesn't exist".format(ID)) vgs_df_global.drop(ID, inplace=True) return {"message": "Video game {} is removed.".format(ID)}, 200 GDPtoSalesParser = reqparse.RequestParser() GDPtoSalesParser.add_argument('year', required=True, type=inputs.int_range(1994,2018), help="Year to compare, between 1994-2018") GDPtoSalesParser.add_argument('country', required=True, choices=["US", "EU", "JP"], help="Region to compare") @api.route('/GDP_to_sales') class GDPtoSales(Resource): @api.response(500, 'Server Error') @api.response(404, 'Invalid year given') @api.response(400, 'Invalid country given') @api.response(200, 'Success') @api.expect(GDPtoSalesParser, validate=True) @key_required @track_usage def get(self): """Returns the percentage of a region's GDP to video games sales within a given year""" gdp_df = gdp_df_global.copy(deep=True) vgs_df = vgs_df_global.copy(deep=True)
def test_valid_range(self): int_range = inputs.int_range(1, 5) assert_equal(3, int_range(3))
from ASB_app.releases import Release, current_release for release in Release.__subclasses__(): api = release.api file_parser = api.parser() file_parser.add_argument('file', type=FileStorage, location='files') pagination_parser = api.parser() pagination_parser.add_argument('page', type=inputs.positive, help='Page number', default=1) pagination_parser.add_argument('size', type=inputs.int_range(1, 1200), help='Items per page, ≤1000') pagination_parser.add_argument('offset', type=inputs.natural, help='Skip first N items', default=0) pagination_parser.add_argument( 'filter', help='Comma-separated filters: field1 EQ "value1", field2 GE "value2"') pagination_parser.add_argument( 'order_by', help='ORDER BY criterion: "field1", "-field2"') search_parser = pagination_parser.copy() if int(release.version) >= 3: search_parser.add_argument('fdr', help='FDR threshold',
args = get_v1_articles_params().parse_args() recs = process_request(args) if len(recs) == 0: abort_no_candidates() return recs ItemSpec = collections.namedtuple('Item', ['wikidata_id', 'score']) v1_items_params = reqparse.RequestParser() v1_items_params.add_argument('seed', type=str, required=True) v1_items_params.add_argument( 'count', type=inputs.int_range(low=0, high=configuration.get_config_int( 'api', 'count_max')), required=False, default=configuration.get_config_int('api', 'count_default')) v1_items_model = v1.model( ItemSpec.__name__, ItemSpec(wikidata_id=fields.String(description='wikidata_id', required=True), score=fields.Float(description='score', required=True))._asdict()) v1_items_doc = dict( description= 'Gets recommendations of Wikidata items that are related to a seed item', params=dict(seed='Seed Wikidata item', count='Number of recommendations to fetch'))
def test_schema(self): assert inputs.int_range(1, 5).__schema__ == {'type': 'integer', 'minimum': 1, 'maximum': 5}
def test_lower(self): int_range = inputs.int_range(0, 5) with pytest.raises(ValueError): int_range(-1)
def test_lower(self): int_range = inputs.int_range(0, 5) with assert_raises(ValueError): int_range(-1)
def test_schema(self): self.assert_schema(inputs.int_range(1, 5), {'type': 'integer', 'minimum': 1, 'maximum': 5})
' current user. Must be admin to disable.', error='Specify a boolean value for assigned_only' ) # Shell server request schema shell_server_req = reqparse.RequestParser() shell_server_req.add_argument( 'name', required=True, type=str, location='json', help='Shell server display name.', error='Shell server display name is required') shell_server_req.add_argument( 'host', required=True, type=str, location='json', help='Shell server hostname.', error='Shell server hostname is required') shell_server_req.add_argument( 'port', required=True, type=inputs.int_range(1, 65535), location='json', help='Shell server port.', error='Shell server port is required (1-65535)') shell_server_req.add_argument( 'username', required=True, type=str, location='json', help='Username.', error='Shell server username is required') shell_server_req.add_argument( 'password', required=True, type=str, location='json', help='Password.', error='Shell server password is required') shell_server_req.add_argument( 'protocol', required=True, type=str, choices=['HTTP', 'HTTPS'], location='json', help='Protocol used to serve web resources.', error='Shell server protocol is required (HTTP/HTTPS)'
def test_higher(self): int_range = inputs.int_range(0, 5) with assert_raises(ValueError): int_range(6)
def test_schema(self): self.assert_schema(inputs.int_range(1, 5), { 'type': 'integer', 'minimum': 1, 'maximum': 5 })
description='An API for searching and retrieving job listings from the ' 'entire job market', default='market', default_label="An API for searching job listings.") # Namespace configuration ns_market = Namespace('All job ads', description='Search and retrieve ~97% of all job ads.') api.add_namespace(ns_market, '/') # Queries market_query = reqparse.RequestParser() market_query.add_argument(settings.APIKEY, location='headers', required=True) market_query.add_argument(settings.OFFSET, type=inputs.int_range(0, settings.MAX_OFFSET), default=0) market_query.add_argument(settings.LIMIT, type=inputs.int_range(0, settings.MAX_LIMIT), default=10) market_query.add_argument(settings.SHOW_EXPIRED, choices=['true', 'false']) market_query.add_argument(settings.FREETEXT_QUERY) market_query.add_argument(settings.PLACE, action='append') market_query.add_argument(settings.EMPLOYER, action='append') market_query.add_argument(settings.STATISTICS, choices=list(settings.auranest_stats_options.keys()), action='append') market_query.add_argument(settings.STAT_LMT, type=inputs.int_range(0, 100), default=10)
shell_server_req = reqparse.RequestParser() shell_server_req.add_argument('name', required=True, type=str, location='json', help='Shell server display name.', error='Shell server display name is required') shell_server_req.add_argument('host', required=True, type=str, location='json', help='Shell server hostname.', error='Shell server hostname is required') shell_server_req.add_argument('port', required=True, type=inputs.int_range(1, 65535), location='json', help='Shell server port.', error='Shell server port is required (1-65535)') shell_server_req.add_argument('username', required=True, type=str, location='json', help='Username.', error='Shell server username is required') shell_server_req.add_argument('password', required=True, type=str, location='json', help='Password.', error='Shell server password is required')
type=str, required=True ) item_params.add_argument( 'target', type=str, required=True ) item_params.add_argument( 'seed', type=str, required=False ) item_params.add_argument( 'count', type=inputs.int_range(0, 50), required=False, default=24 ) items_model = v1.model(ItemSpec.__name__, ItemSpec( title=fields.String(description='title', required=True), id=fields.String(description='wikidata_id', required=True), prediction=fields.Float(description='prediction', required=True) )._asdict()) items_doc = dict(description='Gets recommendations for translation', params=dict(target='Target language', count='Number of recommendations to fetch'))