当前位置: 首页>>代码示例>>Python>>正文


Python state.State类代码示例

本文整理汇总了Python中app.models.state.State的典型用法代码示例。如果您正苦于以下问题:Python State类的具体用法?Python State怎么用?Python State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了State类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

    def setUp(self):
        # disabling logs
        logging.disable(logging.CRITICAL)
        self.app = app.test_client()
        # connecting to the database
        db.connect()
        # creating tables
        db.create_tables([User], safe=True)
        db.create_tables([State], safe=True)
        db.create_tables([City], safe=True)
        db.create_tables([Place], safe=True)
        db.create_tables([PlaceBook], safe=True)

        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        # Creating a new users
        user1 = User(first_name='Jon',
                     last_name='Snow',
                     email='[email protected]',
                     password='toto1234')
        user1.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:35,代码来源:place_book.py

示例2: test_city_state

 def test_city_state(self):
     new_state = State(name="California")
     new_state.save()
     new_city = City(name="San Francisco", state=1)
     new_city.save()
     get_cities = self.app.get('/states/1/cities/1')
     assert get_cities.status_code == 200
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:7,代码来源:city.py

示例3: setUp

 def setUp(self):
     #connect to db and delete everyone in the users table
     PlaceBook.delete().execute()
     Place.delete().execute()
     User.delete().execute()
     City.delete().execute()
     State.delete().execute()
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:7,代码来源:place_book.py

示例4: tearDown

 def tearDown(self):
     #delete all from users
     PlaceBook.delete().execute()
     Place.delete().execute()
     User.delete().execute()
     City.delete().execute()
     State.delete().execute()
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:7,代码来源:place_book.py

示例5: handle_states

def handle_states():
    '''Returns all the states from the database as JSON objects with a GET
    request, or adds a new state to the database with a POST request. Refer to
    exception rules of peewee `get()` method for additional explanation of
    how the POST request is handled:
    http://docs.peewee-orm.com/en/latest/peewee/api.html#SelectQuery.get
    '''
    if request.method == 'GET':
        list = ListStyle().list(State.select(), request)
        return jsonify(list), 200

    elif request.method == 'POST':
        params = request.values

        '''Check that all the required parameters are made in request.'''
        required = set(["name"]) <= set(request.values.keys())
        if required is False:
            return jsonify(msg="Missing parameter."), 400

        try:
            State.select().where(State.name == request.form['name']).get()
            return jsonify(code=10001, msg="State already exists"), 409
        except State.DoesNotExist:
            state = State.create(name=request.form['name'])
            return jsonify(state.to_dict()), 201
开发者ID:Siphan,项目名称:airbnb_clone,代码行数:25,代码来源:state.py

示例6: test_review_place2

    def test_review_place2(self):
        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()

        # Creating a review for a place that exist
        new_review = self.app.post('/places/1/reviews',
                                   data=dict(message="I like it",
                                             stars=5))
        assert new_review.status_code == 200
        # checking the review id, should be 1
        assert json.loads(new_review.data)["id"] == 1
        # Creating a review for a place that does not exist
        new_review = self.app.post('/places/3/reviews',
                                   data=dict(message="I like it",
                                             user_id=1,
                                             stars=5))
        assert new_review.status_code == 404
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:31,代码来源:review.py

示例7: create_database

def create_database():
    try:
         User.create_table()
    except peewee.OperationalError:
        pass

    try:
         State.create_table()
    except peewee.OperationalError:
        pass

    try:
         City.create_table()
    except peewee.OperationalError:
        pass

    try:
         Place.create_table()
    except peewee.OperationalError:
        pass

    try:
         PlaceBook.create_table()
    except peewee.OperationalError:
        pass

    try:
         Amenity.create_table()
    except peewee.OperationalError:
        pass

    try:
         PlaceAmenities.create_table()
    except peewee.OperationalError:
        pass
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:35,代码来源:migrate.py

示例8: handle_state_id

def handle_state_id(state_id):
    '''Select the state with the id from the database and store as the variable
    `state` with a GET request method. Update the data of the particular state
    with a PUT request method. This will take the parameters passed and update
    only those values. Remove the state with this id from the database with
    a DELETE request method.

    Keyword arguments:
    state_id: The id of the state from the database.
    '''
    try:
        state = State.select().where(State.id == state_id).get()
    except State.DoesNotExist:
        return jsonify(msg="There is no state with this id."), 404

    if request.method == 'GET':
        return jsonify(state.to_dict()), 200

    elif request.method == 'DELETE':
        try:
            state = State.delete().where(State.id == state_id)
        except State.DoesNotExist:
            raise Exception("There is no state with this id.")
        state.execute()
        return jsonify(msg="State deleted successfully."), 200
开发者ID:Siphan,项目名称:airbnb_clone,代码行数:25,代码来源:state.py

示例9: test_review_place3

    def test_review_place3(self):
        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()

        # Creating a review for a place that exist
        new_review = self.app.post('/places/1/reviews',
                                   data=dict(message="I like it",
                                             stars=5))
        assert new_review.status_code == 200

        # Checking for a review that does not exist
        new_review_get = self.app.get('/places/1/reviews/5')
        assert new_review_get.status_code == 404

        # Checking for a place that does not exist
        new_review_get = self.app.get('/places/2/reviews/2')
        assert new_review_get.status_code == 404

        # Checking for a review that does exist
        new_review_get = self.app.get('/places/1/reviews/1')
        assert new_review_get.status_code == 200
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:35,代码来源:review.py

示例10: states

def states():
    """Handle GET and POST requests to /states route.

     Return a list of all states in the database in the case of a GET request.
     Create a new state in the database in the case of a POST request
    """
    # handle GET requests:
    # --------------------------------------------------------------------------
    if request.method == 'GET':
        list = ListStyle.list(State.select(), request)
        return jsonify(list)

    # handle POST requests:
    # --------------------------------------------------------------------------
    elif request.method == 'POST':
        try:
            record = State(name=request.form["name"])
            record.save()
            return jsonify(record.to_hash())

        # return 409 state with given name already exists
        except IntegrityError:
                return json_response(
                    add_status_=False,
                    status_=409,
                    code=10001,
                    msg="State already exists"
                )
开发者ID:ronachong,项目名称:airbnb_clone,代码行数:28,代码来源:state.py

示例11: del_state

def del_state(id):
    id_check = State.select().where(State.id == id)
    if not id_check:
        return {'code': 404, 'msg': 'State not found'}, 404

    item = State.delete().where(State.id == id)
    item.execute()
    return {'code': 200, 'msg': 'Deleted successfully'}, 200
开发者ID:havk64,项目名称:airbnb_clone,代码行数:8,代码来源:state.py

示例12: tearDown

 def tearDown(self):
     """
     Remove city table from airbnb_test database upon completion of test
     case.
     """
     # drop tables from database
     City.drop_table()
     State.drop_table()
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:8,代码来源:city.py

示例13: get_state

def get_state(state_id):
    """
    Get the given state
    Returns the given state in the database.
    ---
    tags:
    	- State
    parameters:
    	-
    		in: path
    		name: state_id
    		type: integer
    		required: True
    		description: ID of the state
    responses:
        200:
            description: State returned successfully
            schema:
                id: State
                required:
                    - name
                    - id
                    - created_at
                    - updated_at
                properties:
                    name:
                        type: string
                        description: name of the given state
                        default: None
                    id:
                        type: integer
                        description: id of the state
                        default: 1
                    created_at:
                        type: datetime string
                        description: date and time the state was created in the database
                        default: '2016-08-11 20:30:38'
                    updated_at:
                        type: datetime string
                        description: date and time the state was updated in the database
                        default: '2016-08-11 20:30:38'
        404:
            description: State was not found
        500:
            description: Request could not be processed
    """
    try:
        ''' Check that state_id exists '''
        query = State.select().where(State.id == state_id)
        if not query.exists():
            raise LookupError('state_id')

        state = State.get(State.id == state_id)
        return state.to_dict(), 200
    except LookupError as e:
        abort(404)
    except Exception as e:
        abort(500)
开发者ID:rickharris-dev,项目名称:airbnb_clone,代码行数:58,代码来源:state.py

示例14: create_state

def create_state():
    data = request.form
    name_check = State.select().where(State.name == data['name'])
    if name_check:
        return {'code': 10001, 'msg': 'State already exists'}, 409
    state = State.create(
        name = data['name']
    )
    return {'code': 201,'msg': 'State was created successfully'}, 201
开发者ID:havk64,项目名称:airbnb_clone,代码行数:9,代码来源:state.py

示例15: tearDown

 def tearDown(self):
     """
     Remove place table from airbnb_test database upon completion of test
     case.
     """
     Place.drop_table()
     City.drop_table()
     State.drop_table()
     User.drop_table()
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:9,代码来源:place.py


注:本文中的app.models.state.State类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。