"name": fields.String(readonly=True, description="Role's name", max_length=64, example="God"), "description": fields.String(readonly=True, max_length=255, example="Just a god", description="Role's description"), }) user_model = user_api.model("User", { "id": fields.Integer(readonly=True, description="User's ID", example=1), "email": fields.String(required=True, description="User's email", pattern=email_regex, max_length=64, example="*****@*****.**"), "fullname": fields.String(required=True, description="User's fullname", max_length=64, example="Marshall Bruce Mathers III"), "birthday": fields.Date(description="User's birthday", example="1990-01-01"), "sex": fields.String(description="User's sex", enum=["m", "f"], example="m"), "password": PasswordFormat(required=True, description="User's password", example="TheRealSl1mShady"), "active": fields.Boolean(readonly=True, description="User's active sign", default=True), "avatar": fields.String(description="User's avatar", readonly=True, attribute=lambda x: x.avatar(100), example="https://www.gravatar.com/avatar/" "e0d49368f68cc49767b1eb09a2e9c4ca?" "d=identicon&s=100"), "roles": fields.List(fields.Nested(role_model), readonly=True, description="User's roles"), "posts": fields.List(fields.Nested(post_model), readonly=True, description="User's posts"),
def test_value(self, value, expected): self.assert_field(fields.Date(), value, expected)
get_posts_parser.add_argument('sort', choices=('time', 'activity'), default='time', location='args', help='Sort by time or latest activity') get_posts_parser.add_argument('start_date', location='args', help='Return posts on or after given date') get_posts_parser.add_argument('end_date', location='args', help='Return posts before and not on given date') new_post_marshal_model = api.model('New Post Model', { 'title': fields.String(required=True, description='Post title'), 'content': fields.String(required=True, description='Post content'), 'due_date': fields.Date(required=False, description='The post due date'), 'category': fields.Nested(category_marshal_model, description='Only checking for id'), 'course': fields.Nested(course_marshal_model, description='Only checking for id') }) post_marshal_model = api.model('Post', { 'id': fields.String(required=True, description='The post id'), 'title': fields.String(required=True, description='The post title'), 'due_date': fields.Date(required=False, description='The post due date, if it makes sense'), 'content': fields.String(required=True, description='The post content'), 'cheers': fields.Nested(model=basic_user_marshal_model, required=True,
def test_min_exlusive(self): field = fields.Date(min='1984-06-07', exclusiveMin=True) assert 'minimum' in field.__schema__ assert field.__schema__['minimum'] == '1984-06-07' assert 'exclusiveMinimum' in field.__schema__ assert field.__schema__['exclusiveMinimum'] is True
def test_max_as_datetime(self): field = fields.Date(max=datetime(1984, 6, 7, 1, 2, 0)) assert 'maximum' in field.__schema__ assert field.__schema__['maximum'] == '1984-06-07' assert 'exclusiveMaximum' not in field.__schema__
class UserProfile: api_model = create_model( 'User Profile', { 'username': fields.String(description='The user name.'), 'screen_name': fields.String(description='The name shown on profile screen.'), 'bio': fields.String(description='The biography of the user'), 'birth_date': fields.Date(description='The birth date of the user'), 'created_at': fields.DateTime(description='Time created at'), 'followers_count': fields.Integer( description='Integer indicates number of people follow you.'), 'following_count': fields.Integer( description='Integer indicates number of people you follow.'), 'kweeks_count': fields.Integer( description= 'Integer indicates number of tweets which called kweeks.'), 'likes_count': fields.Integer(description='Integer indicates number of likes.'), 'profile_banner_url': fields.String( description='Url for profile banner which is cover photo.'), 'profile_image_url': fields.String(description='Url for profile image.'), 'following': fields.Boolean( description= 'Nullable. Does the authorized user follow this user? ' 'Null if the authorized user is the same as the user in the query.' ), 'follows_you': fields.Boolean( description= 'Nullable. Does this user follow the authorized user? ' 'Null if the authorized user is the same as the user in the query.' ), 'blocked': fields.Boolean( description= 'Nullable. Is this user blocked by the authorized user? ' 'Null if the authorized user is the same as the user in the query.' ), 'muted': fields.Boolean( description= 'Nullable. Is this user muted by the authorized user? ' 'Null if the authorized user is the same as the user in the query.' ) }) def __init__(self, json): self.username = json["username"] self.screen_name = json["screen_name"] self.bio = json["bio"] self.birth_date = json["birth_date"] self.created_at = json["created_at"] self.followers_count = json["followers_count"] self.following_count = json["following_count"] self.kweeks_count = json["kweeks_count"] self.likes_count = json["likes_count"] self.profile_banner_url = json["profile_banner_url"] self.profile_image_url = json["profile_image_url"] self.following = json["following"] self.follows_you = json["follows_you"] self.blocked = json["blocked"] self.muted = json["muted"] def to_json(self): return { 'username': self.username, 'screen_name': self.screen_name, 'bio': self.bio, 'birth_date': self.birth_date, 'created_at': self.created_at, 'followers_count': self.followers_count, 'following_count': self.following_count, 'kweeks_count': self.kweeks_count, 'likes_count': self.likes_count, 'profile_banner_url': self.profile_banner_url, 'profile_image_url': self.profile_image_url, 'following': self.following, 'follows_you': self.follows_you, 'blocked': self.blocked, 'muted': self.muted }
def test_defaults(self): field = fields.Date() assert not field.required assert field.__schema__ == {'type': 'string', 'format': 'date'}
from flask_restplus import Namespace, Resource, fields from app import db from app.models import Tweet api = Namespace('tweets') tweet_model = api.model( 'Tweet', { 'id': fields.Integer(readonly=True, description='The tweet unique identifier'), 'text': fields.String(required=True, description='The tweet details'), 'created_at': fields.Date(required=True, description='The tweet details') }) tweet_model_lite = api.model( 'Tweet', { 'text': fields.String(required=True, description='The tweet details'), }) @api.route('/') class TweetResourceRacine(Resource): @api.doc('create_todo') @api.expect(tweet_model) @api.marshal_with(tweet_model_lite, code=201) def post(self): if api.payload is None: api.abort(422, '{"error": "input data error""}')
'raw': RawOutput(), # 原样输出, 返回值可以不携带该属性 'status': UnreadItem(attribute='flags'), # flags字段值自动传入format函数中进行计算并返回 'random': RandomNumber, 'url': fields.Url('todo_ep', absolute=True), # 接收一个端点名并返回该端点对应 URL 'name': fields.String(default='bifeng'), # 设置默认值 'id': fields.Integer(), # ID 测试 'datetime': fields.DateTime(), # 时间格式 'date': fields.Date(), # 日期 'bool': fields.Boolean(skip_none=True), # 布尔型(可以在models或者expect中定义skip_none) 'contact': fields.Nested(sub_model), # 内嵌字典类型 'friends': fields.List(fields.Nested(friend_model)) # 内嵌列表 }) person_model = api.clone( 'Person', resp_model, { # clone继承(api方式继承) 'weight': fields.Float(), # 体重 })
def test_max_as_datetime(self): field = fields.Date(max=datetime(1984, 6, 7, 1, 2, 0)) assert_in('maximum', field.__schema__) assert_equal(field.__schema__['maximum'], '1984-06-07') assert_not_in('exclusiveMaximum', field.__schema__)
def test_max_exclusive(self): field = fields.Date(max='1984-06-07', exclusiveMax=True) assert_in('maximum', field.__schema__) assert_equal(field.__schema__['maximum'], '1984-06-07') assert_in('exclusiveMaximum', field.__schema__) assert_equal(field.__schema__['exclusiveMaximum'], True)
def test_min_exlusive(self): field = fields.Date(min='1984-06-07', exclusiveMin=True) assert_in('minimum', field.__schema__) assert_equal(field.__schema__['minimum'], '1984-06-07') assert_in('exclusiveMinimum', field.__schema__) assert_equal(field.__schema__['exclusiveMinimum'], True)
def test_min_as_date(self): field = fields.Date(min=date(1984, 6, 7)) assert_in('minimum', field.__schema__) assert_equal(field.__schema__['minimum'], '1984-06-07') assert_not_in('exclusiveMinimum', field.__schema__)
'deaths': fields.Integer(required=True, description='Deaths') }) city_cases_response_list = data_endpoints.model( 'City Cases Response List', { 'cases': fields.Nested( city_cases, required=True, as_list=True, description='Cases') }) datasus_list = data_endpoints.model( 'SUS Data', { 'id': fields.Integer(required=True, description='Id'), 'region': fields.String(required=True, description='Region'), 'state': fields.String(required=True, description='State'), 'date': fields.Date(required=True, description='Date'), 'newcases': fields.Integer(required=True, description='New cases'), 'totalcases': fields.Integer(required=True, description='Total cases'), 'newdeaths': fields.Integer(required=True, description='New Deaths'), 'totaldeaths': fields.Integer(required=True, description='Total Deaths'), 'update': fields.DateTime(required=False, description='Update Date') }) predictcases_list = data_endpoints.model( 'Predict Cases', { 'id': fields.Integer(required=True, description='Id'), 'state': fields.String(required=True, description='State'), 'date': fields.Date(required=True, description='Date'), 'predictcases': fields.Integer(required=True, description='Predict Cases'),
registration_data = api.model( 'Registration Data', { 'username': fields.String(readOnly=True, required=True, description="Username"), 'password': fields.String(readOnly=True, required=True, description="Password"), 'confirm_password': fields.String( readOnly=True, required=True, description="Confirm Password"), 'full_name': fields.String(readOnly=True, required=True, description="Full Name"), 'gender': fields.Integer(readOnly=True, required=True, description="Gender"), 'date_of_birth': fields.Date(readOnly=True, required=True, description="Date of Birth"), }) qr_data = api.model('QR Data', { 'code': fields.String(readOnly=True, required=True, description="QR code") }) user_data = api.model( 'User Data', { 'full_name': fields.String(readOnly=True, required=True, description="Full Name"), 'date_of_birth': fields.String( readOnly=True, required=True, description="Date of Birth"), 'gender':
from http import HTTPStatus from flask_restplus import Namespace, fields, Resource from src.models.ply import Ply PLIES = Namespace(name="plies", description="Endpoints for plies.") MODEL = PLIES.model(name="user_model", model={ "id": fields.String(), "current_position": fields.String(), "next_position": fields.String(), "algebraic_notation": fields.Date(), "game_id": fields.String() }) @PLIES.route("/") class Plies(Resource): def get(self): results = Ply.query.all() return Ply.serialize_list(results), HTTPStatus.OK
from flask_restplus import fields from server.instance import server api = server.api bike = api.model('bike', { 'owner': fields.String(required=True, description='bike owner', example='Ali Kalan'), 'phone': fields.String(required=True, description='owner phone number', example='09122222222'), 'license_number': fields.Integer(required=True, description='bike license number', example='008462'), 'color': fields.String(description='bike color', example='silver'), 'bike_type': fields.String(enum=['Road', 'Touring', 'Mountain', 'TimeTrial', 'Hybrid', 'Other'], description='bike type'), 'theft_date': fields.Date(dt_format='iso8601', description='The date of the robbery', example="2020-04-01"), })
from src.server.instance import server from flask_restplus import fields reservation = server.api.model( 'Reservation', { 'id': fields.Integer(required=False, description='Id'), 'date_from': fields.Date(required=True, description='Start Date: dd.mm.YY.hh:mm'), 'date_to': fields.Date(required=True, description='End Date: dd.mm.YY.hh:mm'), 'bike_ids': fields.String(required=True, description='Bike_IDS: 1###2###3###4'), 'confirmed': fields.Boolean(required=False, description='Confirmed'), 'email': fields.String(required=True, description='Email of customer') })
class RankingEntryDto: api = Namespace('ranking_entry', description='An entry with the predictions for a given patent.') ranking_entry = api.model('entry_details', { 'patente': fields.String(), 'step_id_week': fields.Integer(), 'starting_date': fields.Date(), 'predicted_relevance': fields.Float(), 'predicted_rank': fields.Integer(), 'previous_rank': fields.Integer(), 'ten_day_mean_speed' : fields.Float(), 'ten_day_pre_alert_low_count' : fields.Float(), 'ten_day_pre_alert_mid_count' : fields.Float(), 'ten_day_pre_alert_high_count' : fields.Float(), 'ten_day_alert_low_count' : fields.Float(), 'ten_day_alert_mid_count' : fields.Float(), 'ten_day_alert_high_count' : fields.Float(), 'ten_day_sum_distance' : fields.Float(), 'instance_json': fields.String(), 'geo_fence_0' : fields.Integer(), 'geo_fence_1' : fields.Integer(), 'geo_fence_2' : fields.Integer(), 'geo_fence_3' : fields.Integer(), 'geo_fence_4' : fields.Integer(), 'geo_fence_5' : fields.Integer(), 'geo_fence_6' : fields.Integer(), 'geo_fence_7' : fields.Integer(), 'geo_fence_8' : fields.Integer(), 'geo_fence_9' : fields.Integer(), 'geo_fence_10' : fields.Integer(), 'geo_fence_11' : fields.Integer(), 'geo_fence_12' : fields.Integer(), 'geo_fence_13' : fields.Integer(), 'geo_fence_14' : fields.Integer(), 'geo_fence_15' : fields.Integer(), 'geo_fence_16' : fields.Integer(), 'geo_fence_17' : fields.Integer(), 'geo_fence_18' : fields.Integer(), 'geo_fence_19' : fields.Integer(), 'geo_fence_20' : fields.Integer(), 'geo_fence_21' : fields.Integer(), 'geo_fence_22' : fields.Integer(), 'geo_fence_23' : fields.Integer(), 'geo_fence_24' : fields.Integer(), 'geo_fence_25' : fields.Integer(), 'geo_fence_26' : fields.Integer(), 'geo_fence_27' : fields.Integer(), 'geo_fence_28' : fields.Integer(), 'geo_fence_29' : fields.Integer(), 'geo_fence_30' : fields.Integer(), 'geo_fence_31' : fields.Integer(), 'geo_fence_32' : fields.Integer(), 'geo_fence_33' : fields.Integer(), 'geo_fence_34' : fields.Integer(), 'geo_fence_35' : fields.Integer(), 'geo_fence_36' : fields.Integer(), 'geo_fence_37' : fields.Integer(), 'geo_fence_38' : fields.Integer(), 'geo_fence_39' : fields.Integer(), 'geo_fence_40' : fields.Integer(), 'geo_fence_41' : fields.Integer(), 'geo_fence_42' : fields.Integer(), 'geo_fence_43' : fields.Integer(), 'geo_fence_44' : fields.Integer(), 'geo_fence_45' : fields.Integer(), 'geo_fence_46' : fields.Integer(), 'geo_fence_47' : fields.Integer(), 'geo_fence_48' : fields.Integer(), 'geo_fence_49' : fields.Integer(), 'geo_fence_50' : fields.Integer(), 'geo_fence_51' : fields.Integer(), 'geo_fence_52' : fields.Integer(), 'geo_fence_53' : fields.Integer(), 'geo_fence_54' : fields.Integer(), 'geo_fence_55' : fields.Integer(), 'geo_fence_56' : fields.Integer(), 'geo_fence_57' : fields.Integer(), 'geo_fence_58' : fields.Integer(), 'geo_fence_59' : fields.Integer() })
'SYCAMORE', 'TANOAK', 'TRUECEDAR', 'TRUEFIR', 'WALNUT', 'WHITECEDAR', 'WILLOW', 'YELLOWPOPLAR', 'YEW' ] tree = server.api.model( 'Tree', { 'tid': fields.Integer(description='Tree ID'), 'species': fields.String(required=True, example='CEDAR', description='Scientific name', enum=tree_species), 'planted_date': fields.Date( required=True, example='2015-02-26', description='Date when tree was planted at its current location'), 'geog_loc': fields.String(required=True, example='(1.0,2.0)', description='Geographic location of the tree'), 'mid': fields.String( required=True, example='169', description='ID of the municipality in which the tree is located'), 'pid': fields.String( example='6', description='ID of the parc in which the tree is located'), 'civid':
def test_min_as_date(self): field = fields.Date(min=date(1984, 6, 7)) assert 'minimum' in field.__schema__ assert field.__schema__['minimum'] == '1984-06-07' assert 'exclusiveMinimum' not in field.__schema__
from flask_restplus import Namespace, fields api = Namespace('Packages', 'Packages Related APIs', path='/packages') packageDetails = api.model( 'packages', { 'id': fields.Integer(), 'destination': fields.String(), 'price': fields.Decimal(), 'days': fields.Integer(), 'intenerary': fields.String(), 'inclusions': fields.String(), 'remainingSlots': fields.Integer(), 'expirationDate': fields.Date(), 'note': fields.String(), 'hotel': fields.String(), 'flight': fields.String(), 'isExpired': fields.Boolean() }) packageInsert = api.model( 'packages', { 'destination': fields.String(), 'price': fields.Decimal(), 'days': fields.Integer(), 'intenerary': fields.String(), 'inclusions': fields.String(), 'remainingSlots': fields.Integer(), 'expirationDate': fields.Date(), 'note': fields.String(), 'hotel': fields.String(),
def test_max(self): field = fields.Date(max='1984-06-07') assert 'maximum' in field.__schema__ assert field.__schema__['maximum'] == '1984-06-07' assert 'exclusiveMaximum' not in field.__schema__
Module contains API resource for exposing catering menus """ from datetime import datetime from flask_restplus import Resource, fields, abort from flask import g from .decorators import authenticate, admin_required from . import api from . import parsers from .common import validate_meals_list from ..models import Menu, Meal MENU_MODAL = api.model( 'Menu', { 'title': fields.String(max_length=64), 'menu_date': fields.Date(), 'description': fields.String(max_length=200), 'meals': fields.List(fields.Integer) }) class MenusResource(Resource): """ MenusResource. for exposing menus as API endpoints """ @authenticate @admin_required @api.header('Authorization', type=str, description='Authentication token') def get(self): """ Allows a business to retrieve all menus
def test_max_exclusive(self): field = fields.Date(max='1984-06-07', exclusiveMax=True) assert 'maximum' in field.__schema__ assert field.__schema__['maximum'] == '1984-06-07' assert 'exclusiveMaximum' in field.__schema__ assert field.__schema__['exclusiveMaximum'] is True
class PersonalDetailSubmit(Resource): post_payload_model = api.model( 'POST_personal_details', { 'enrollment_key': fields.String(required=True), 'name': fields.String(required=True), 'mobile_number': fields.String(required=True), 'dob': fields.Date(required=True), 'gender': fields.String( required=True, choices=[attr.value for attr in app.config['GENDER']]) }) post_response = api.model('POST_enrollment_key_status_response', { 'success': fields.Boolean, 'enrollment_key_status': fields.String }) PERSONAL_DETAILS_DESCRIPTION = """ Description: Response will comprise of two JSON keys. `success` and `enrollment_key_status` Possible values of both are explained below: 'success': { True : when the data is added, False : when we can't data can't be added } 'enrollment_key_status':{ 'NOT_USED' : The key is not used and but has been generated, 'DOES_NOT_EXIST' : The key have not been generated or doesn't exist in the platform, 'ALREADY_IN_USED' : A Student is already using to give the test but you can't post the data to it, 'EXPIRED' : Time to generate a new key } Possible values of different JSON keys which can be passed: - 'enrollment_key': 'SFD190', - 'name': 'Amar Kumar Sinha', - 'dob': '1997-09-18', [YYYY-MM--DD] - 'mobile_number': '7896121314', - 'gender': 'MALE', ['MALE', 'FEMALE', 'OTHER'] """ @api.marshal_with(post_response) @api.doc(description=PERSONAL_DETAILS_DESCRIPTION) @api.expect(post_payload_model) def post(self): # parse the arguments args = api.payload args['gender'] = app.config['GENDER'](args['gender']) mobile_number = args['mobile_number'] enrollment_key = args['enrollment_key'] # check the validity of enrollment key result, enrollment = check_enrollment_key(enrollment_key) # student record shall be updated only when the key is not used and valid if result['valid'] and result['reason'] == 'NOT_USED': # updating student data student_id = enrollment.student_id student = Student.query.filter_by(id=student_id).first() student.update_data(args, [mobile_number]) student.change_stage('PDS') return {'success': True, 'enrollment_key_status': result['reason']} # when the key is used but somehow student went to the this route instead of test elif result['valid'] and result['reason'] == 'ALREADY_IN_USED': return {'success': True, 'enrollment_key_status': result['reason']} # when the key is not valid return { 'success': False, 'enrollment_key_status': result['reason'], }
def test_unsupported_value_format(self): self.assert_field_raises(fields.Date(), 'xxx')
from autofit.app.restplus import api from flask_restplus import fields slot = api.model('Slot model', {'sid': fields.String(required=False, description='The unique slot identifier'), 'name': fields.String(required=True, description="Slot's name"), 'keys': fields.String(required=True, description="Slot's keys"), 'date': fields.Date(required=True, description="Slot's valuation date"), 'priority': fields.Integer(required=True, description="Slot's priority"), 'state': fields.String(required=False, description="Slot's state"), 'updated_at': fields.DateTime(required=False, description="Slot's update time"), 'dbid': fields.String(required=True, description="DB id for the Slot's data")} ) inputslot = api.model('InputSlot model', {'id_': fields.Integer(required=True, description="Table's primary key"), 'pname': fields.String(required=True, description="Producer's name"), 'sname': fields.String(required=True, description="Slot's name"), 'sid': fields.String(required=True, description="Slot's sid"), 'id1': fields.String(required=True, description="Asset1 id"), 'ccy1': fields.String(required=True, description="Asset1 currency"), 'id2': fields.String(required=True, description="Asset2 id"), 'ccy2': fields.String(required=True, description="Asset2 currency"), 'class_': fields.String(required=True, description="Asset class"), 'type_': fields.String(required=True, description="Asset type"), 'region': fields.String(required=True, description="region"), 'date': fields.Date(required=True, description="Slot's date"), 'last_updated': fields.DateTime(required=True, description="Last updated time"), 'state': fields.String(required=True, description="InputSlot's state")} )
class Customer: api = Namespace('customer', description='Operations related to customers') spouse = api.model( 'spouse', { 'name': fields.String, 'dob': fields.Date, 'phone': fields.String, 'email': fields.String, 'tfn': fields.String, }) address = api.model( 'address', { 'line': fields.String, 'street': fields.String, 'city': fields.String, 'state/territory': fields.String, 'post_code': fields.String, }) phone = api.model('phone', { 'mobile': fields.String, 'home': fields.String, 'work': fields.String, }) customer = api.model( 'customer', { 'salutation': fields.String(required=True), 'surname': fields.String, 'name': fields.String(required=True), 'dob': fields.Date(required=True), 'gender': fields.String(required=True), 'nationality': fields.String(required=True), "company_name": fields.String(required=True), 'date_of_joining': fields.Date(required=True), 'abn': fields.String(required=True), 'acn': fields.String(required=True), 'tfn': fields.String(required=True), 'bas_period': fields.String(required=True), 'preferred_bookkeeper': fields.String, 'preferred_accountant': fields.String, 'external_customer': fields.Boolean(required=True), 'phone': fields.Nested(phone, required=True), 'email': fields.String(required=True), 'address': fields.Nested(address, required=True), 'marital status': fields.String(required=True), 'spouse': fields.Nested(spouse), 'number_of_children': fields.Integer, '_id': fields.String, 'created_at': fields.DateTime, }) @classmethod def check_customer(cls, data): """Check the existance of a company """ customer = app.App.mongodb.db.customer.find_one({'tfn': data['tfn']}) if customer == None: return True else: return False @classmethod def create_customer(cls, data): """Create a customer""" data['_id'] = str(uuid.uuid4()) data['created_at'] = datetime.datetime.utcnow() created = app.App.mongodb.db.customer.insert_one(data) return created.acknowledged @classmethod def get_customer(cls, _id): """Get a customer""" return app.App.mongodb.db.customer.find_one({'_id': _id}) @classmethod def get_customers(cls): """List all customers""" cursor = app.App.mongodb.db.customer.find({}) resp = [doc for doc in cursor] return resp # @classmethod # def update_customer(cls, _id, data): # """Update a customer""" # app.App.mongodb.db.customer.update_one({'_id': _id}, {'$set': {'name': data['name']}}) @classmethod def delete_customer(cls, _id): """Delete a customer""" return app.App.mongodb.db.customer.delete_one({'_id': _id})
def test_with_default_as_datetime(self): field = fields.Date(default=datetime(2014, 8, 25)) assert field.__schema__ == {'type': 'string', 'format': 'date', 'default': '2014-08-25'}