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


Python city.City类代码示例

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


在下文中一共展示了City类的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: 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

示例4: test_get

    def test_get(self):
        """
        Test proper representation of a city record upon GET requests via city
        ID to API
        """
        # set-up for tests
        # ----------------------------------------------------------------------
        # create city record in city table; should have ID 1
        city_record = self.createCityViaPeewee()

        # test for handling of GET request for user record by user id which
        # exists
        # ----------------------------------------------------------------------
        # make GET request for record in table
        GET_request1 = self.app.get('/states/1/cities/1')
        GET_data = json.loads(GET_request1.data)

        # test that status of response is 200
        self.assertEqual(GET_request1.status[:3], '200')

        # test that values of response correctly reflect record in database
        self.assertEqual(city_record.id, GET_data['id'])
        self.assertEqual(city_record.created_at.strftime('%d/%m/%Y %H:%M'), GET_data['created_at'][:-3])
        self.assertEqual(city_record.updated_at.strftime('%d/%m/%Y %H:%M'), GET_data['updated_at'][:-3])
        self.assertEqual(City.get(City.id == 1).name, GET_data['name'])
        self.assertEqual(City.get(City.id == 1).state.id, GET_data['state_id'])

        # test for handling of GET request for city record by city id which
        # does not exist
        # ----------------------------------------------------------------------
        GET_request2 = self.app.get('/states/1/cities/1000')
        self.assertEqual(GET_request2.status[:3], '404')
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:32,代码来源:city.py

示例5: 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

示例6: 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

示例7: handle_city

def handle_city(state_id):
    '''Returns all the cities in the state with the id passed as `state_id`
    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((City
                                 .select()
                                 .where(City.state == state_id)),
                                request)
        return jsonify(list), 200

    elif request.method == 'POST':
        try:
            City.select().where((City.name == request.form['name']) &
                                (City.state == state_id)
                                ).get()
            return jsonify(code=10002, msg="City already exists in this " +
                           "state"), 409
        except City.DoesNotExist:
            '''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
            city = City.create(name=request.form['name'], state=state_id)
            return jsonify(city.to_dict()), 200
开发者ID:Siphan,项目名称:airbnb_clone,代码行数:29,代码来源:city.py

示例8: handle_city_id

def handle_city_id(state_id, city_id):
    '''Select the city with the id from the database and store as the variable
    `city` with a GET request method. Remove the city with this id from the
    database with a DELETE request method.

    Keyword arguments:
    state_id: The state of the city from the database.
    city_id: The id of the city from the database.
    '''
    try:
        city = City.select().where((City.id == city_id) &
                                   (City.state == state_id)
                                   ).get()
    except City.DoesNotExist:
        raise jsonify(msg="There is no city with this id in this state."), 400

    if request.method == 'GET':
        return jsonify(city.to_dict())

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

示例9: 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

示例10: city

def city(state_id):
    """Handle GET and POST requests to /states/<state_id>/cities route.

    Return a list of all cities in state (according to database) in the case of
    a GET request.
    Create a new city record in the given state in the database in the case of
    a POST request.
    """
    # handle GET requests:
    # --------------------------------------------------------------------------
    if request.method == 'GET':
        list = ListStyle.list(City.select().where(City.state == state_id), request)
        return jsonify(list)

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

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

示例11: test_create

    def test_create(self):
        """
        Test proper creation (or non-creation) of city records upon POST
        requests to API.
        """
        # test creation of city with all parameters provided in POST request

        POST_request1 = self.app.post('/states/1/cities', data=dict(
            name='namestring'
        ))

        now = datetime.now().strftime('%d/%m/%Y %H:%M')

        self.assertEqual(City.get(City.id == 1).name, 'namestring')
        self.assertEqual(City.get(City.id == 1).state.id, 1)
        self.assertEqual(City.get(City.id == 1).created_at.strftime('%d/%m/%Y %H:%M'), now)
        self.assertEqual(City.get(City.id == 1).updated_at.strftime('%d/%m/%Y %H:%M'), now)

        # test creation of city in all cases of a parameter missing in POST request
        POST_request2 = self.app.post('/states/1/cities', data=dict())
        self.assertEqual(POST_request2.status[:3], '400')

        # test that city ID for sole record in database is correct
        self.assertEqual(City.select().get().id, 1)

        # test that a post request with a duplicate name value is rejected
        POST_request3 = self.app.post('/states/1/cities', data=dict(
            name='namestring'
        ))

        self.assertEqual(POST_request3.status[:3], '409')
        self.assertEqual(json.loads(POST_request3.data), {'code': 10002, 'msg': 'City already exists in this state'})
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:32,代码来源:city.py

示例12: 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

示例13: 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

示例14: 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

示例15: createCityViaPeewee

    def createCityViaPeewee(self):
        """
        Create a city record using the API's database/Peewee models.

        createCityViaPeewee returns the Peewee object for the record. This
        method will not work if the database models are not written correctly.
        """
        record = City(name='namestring', state=1)
        record.save()
        return record
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:10,代码来源:city.py


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