Esempio n. 1
0
    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='jon@snow',
                     password='******')
        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()
Esempio n. 2
0
    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
Esempio n. 3
0
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 = []
        for record in State.select():
            hash = record.to_hash()
            list.append(hash)
        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")
Esempio n. 4
0
 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
Esempio n. 5
0
    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
Esempio n. 6
0
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"
                )
Esempio n. 7
0
    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='jon@snow',
                     password='******')
        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()
Esempio n. 8
0
    def createStateViaPeewee(self):
        """
        Create a state record using the API's database/Peewee models.

        createStateViaPeewee returns the Peewee object for the record. This
        method will not work if the database models are not written correctly.
        """
        record = State(name='namestring')
        record.save()
        return record
Esempio n. 9
0
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create placebook table in airbnb_test database.
        """
        self.app = app.test_client()  # set up test client
        self.app.testing = True  # set testing to True
        logging.disable(logging.CRITICAL)  # disable logs

        # connect to airbnb_test database and create tables
        database.connect()
        database.create_tables([User, State, City, Place, PlaceBook],
                               safe=True)

        # create user record for route
        user_record = User(email='anystring',
                           password='******',
                           first_name='anystring2',
                           last_name='anystring3')
        user_record.save()

        # create state record for route
        state_record = State(name="foo-state")
        state_record.save()

        # create city record for route
        city_record = City(name="foo-city", state="1")
        city_record.save()

        # create place records for route
        place_record = Place(owner=1,
                             city=1,
                             name="foo",
                             description="foo description",
                             number_rooms=1,
                             number_bathrooms=1,
                             max_guest=1,
                             price_by_night=1,
                             latitude=20.0,
                             longitude=22.0)
        place_record.save()

        place_record2 = Place(owner=1,
                              city=1,
                              name="foo",
                              description="foo description",
                              number_rooms=1,
                              number_bathrooms=1,
                              max_guest=1,
                              price_by_night=1,
                              latitude=20.0,
                              longitude=22.0)
        place_record2.save()
Esempio n. 10
0
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create placebook table in airbnb_test database.
        """
        self.app = app.test_client()        # set up test client
        self.app.testing = True             # set testing to True
        logging.disable(logging.CRITICAL)   # disable logs

        # connect to airbnb_test database and create tables
        database.connect()
        database.create_tables([User, State, City, Place, PlaceBook], safe=True)

        # create user record for route
        user_record = User( email='anystring',
                            password='******',
                            first_name='anystring2',
                            last_name='anystring3'  )
        user_record.save()

        # create state record for route
        state_record = State(name="foo-state")
        state_record.save()

        # create city record for route
        city_record = City(name="foo-city", state="1")
        city_record.save()

        # create place records for route
        place_record = Place(   owner=1,
                                city=1,
                                name="foo",
                                description="foo description",
                                number_rooms=1,
                                number_bathrooms=1,
                                max_guest=1,
                                price_by_night=1,
                                latitude=20.0,
                                longitude=22.0    )
        place_record.save()

        place_record2 = Place(  owner=1,
                                city=1,
                                name="foo",
                                description="foo description",
                                number_rooms=1,
                                number_bathrooms=1,
                                max_guest=1,
                                price_by_night=1,
                                latitude=20.0,
                                longitude=22.0    )
        place_record2.save()
Esempio n. 11
0
def create_state():
    """
    Create a state
    Creates a state based on post parameters.
    ---
    tags:
      - state
    parameters:
      - name: name
        in: query
        type: string
        description: name of the state to create
    responses:
      200:
        description: Success message
        schema:
          id: success_message
          properties:
            status:
              type: number
              description: status code
              default: 200
            msg:
              type: string
              description: Status message
              default: 'Success'
      400:
          description: Error message
          schema:
            id: error_message
            properties:
              status:
                type: number
                description: status code
                default: 40000
              msg:
                type: string
                description: Status message
                default: 'Missing parameters'
    """
    content = request.get_json(force=True)
    if not all(param in content.keys() for param in ["name"]):
        #ERROR
        return error_msg(400, 40000, "Missing parameters")
    try:
        state = State()
        state.name = content["name"]
        state.save()
    except Exception as e:
        return error_msg(400, 400, "Error")
    return error_msg(200, 200, "Success")
Esempio n. 12
0
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create review table in airbnb_test database.
        """
        self.app = app.test_client()        # set up test client
        self.app.testing = True             # set testing to True
        logging.disable(logging.CRITICAL)   # disable logs

        database.connect()                          # connect to airbnb_test db
        database.create_tables(                     # create tables
            [User, State, City, Place, Review, ReviewUser, ReviewPlace],
            safe=True
        )

        # create user record for routes
        user_record = User(
            email='anystring',
            password='******',
            first_name='anystring2',
            last_name='anystring3'
        )
        user_record.save()

        user_record2 = User(
            email='anystring-2',
            password='******',
            first_name='anystring2',
            last_name='anystring3'
        )
        user_record2.save()

        # create place records (and dependencies) for routes
        state_record = State(name='foo-statee')
        state_record.save()
        city_record = City(name='foo-city', state=1)
        city_record.save()
        place_record = Place(
            owner_id=1,
            city_id=1,
            name="foo",
            description="foo description",
            number_rooms=1,
            number_bathrooms=1,
            max_guest=1,
            price_by_night=1,
            latitude=20.0,
            longitude=22.0
        )
        place_record.save()
Esempio n. 13
0
def list_of_states():
    if request.method == 'GET':
        list = ListStyle.list(State.select(), request)
        return jsonify(list)

    if request.method == 'POST':
        # name_state = request.form['name']
        try:
            new_state = State(name=request.form['name'])
            # saving the changes
            new_state.save()
            # returning the new information in hash form
            return "New State entered! -> %s\n" % (new_state.name)
        except:
            return make_response(jsonify({'code': 10000,
                                          'msg': 'State already exist'}), 409)
Esempio n. 14
0
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create city table in airbnb_test database.
        """
        self.app = app.test_client()        # set up test client
        self.app.testing = True             # set testing to True
        logging.disable(logging.CRITICAL)   # disable logs

        # connect to airbnb_test db and create tables
        database.connect()
        database.create_tables([State, City], safe=True)

        # create state record for route
        state_record = State(name='namestring')
        state_record.save()
Esempio n. 15
0
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create city table in airbnb_test database.
        """
        self.app = app.test_client()  # set up test client
        self.app.testing = True  # set testing to True
        logging.disable(logging.CRITICAL)  # disable logs

        # connect to airbnb_test db and create tables
        database.connect()
        database.create_tables([State, City], safe=True)

        # create state record for route
        state_record = State(name='namestring')
        state_record.save()
Esempio n. 16
0
    def test_delete2(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 by an user 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 how many reviews there are before deleting
        get_review = self.app.get('/places/1/reviews/1')
        assert get_review.status_code == 200

        # delition of a review that does not exist
        deleting_review = self.app.delete('/places/1/reviews/3')
        assert deleting_review.status_code == 404

        # delition of a review that does not exist
        deleting_review = self.app.delete('/places/13/reviews/1')
        assert deleting_review.status_code == 404

        # delition of a review that does not exist
        deleting_review = self.app.delete('/places/1/reviews/1')
        assert deleting_review.status_code == 200

        # checking how many reviews there are after deleting
        get_review = self.app.get('/places/1/reviews/1')
        assert get_review.status_code == 404
Esempio n. 17
0
def list_of_states():
    if request.method == 'GET':
        list = ListStyle.list(State.select(), request)
        return jsonify(list)

    if request.method == 'POST':
        # name_state = request.form['name']
        try:
            new_state = State(name=request.form['name'])
            # saving the changes
            new_state.save()
            # returning the new information in hash form
            return "New State entered! -> %s\n" % (new_state.name)
        except:
            return make_response(
                jsonify({
                    'code': 10000,
                    'msg': 'State already exist'
                }), 409)
Esempio n. 18
0
def states():
	if request.method == 'GET':
		query = State.select()

		return ListStyle.list(query, request), 200

	elif request.method == 'POST':
		try:
			if "name" not in request.form:
				return json_response(status_=400, msg="missing parameters", code=40000)

			insert = State(name=str(request.form["name"]))
			insert.save()
			return jsonify(insert.to_dict()), 201

		except IntegrityError:
			return json_response(status_=409,
								code=10001,
								msg="State already exists")
Esempio n. 19
0
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create place table in airbnb_test database.
        """
        self.app = app.test_client()
        self.app.testing = True
        logging.disable(logging.CRITICAL) # disable logs

        # connect to airbnb_test database and create Place table
        database.connect()
        database.create_tables([User, State, City, Place], safe=True)
        user_record = User( email='anystring',
                            password='******',
                            first_name='anystring2',
                            last_name='anystring3'  )
        user_record.save()
        state_record = State(name='foo-state')
        state_record.save()
        city_record = City(name='foo-city', state=1)
        city_record.save()
        city_record2 = City(name='foo-city2', state=1)
        city_record2.save()
Esempio n. 20
0
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create place table in airbnb_test database.
        """
        self.app = app.test_client()
        self.app.testing = True
        logging.disable(logging.CRITICAL)  # disable logs

        # connect to airbnb_test database and create Place table
        database.connect()
        database.create_tables([User, State, City, Place], safe=True)
        user_record = User(email='anystring',
                           password='******',
                           first_name='anystring2',
                           last_name='anystring3')
        user_record.save()
        state_record = State(name='foo-state')
        state_record.save()
        city_record = City(name='foo-city', state=1)
        city_record.save()
        city_record2 = City(name='foo-city2', state=1)
        city_record2.save()
Esempio n. 21
0
    def test_Place_amenities(self):
        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='jon@snow',
                     password='******')
        user1.save()
        # Creating Place
        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 an amenity
        new_amenity = Amenity(name="amenity1")
        new_amenity.save()

        # Creating a place amenity

        new_place_amenity = PlaceAmenities(place=1, amenity=1)
        new_place_amenity.save()

        # Creating amenity test for different user
        new_state = State(name='Oregon')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()

        # Creating a new users 2
        user1 = User(first_name='Jon',
                     last_name='Snow',
                     email='jon+1c@snow',
                     password='******')
        user1.save()

        # Creating Place 2
        new_place = Place(owner=2,
                          city=2,
                          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 an amenity 2
        new_amenity = Amenity(name="amenity2")
        new_amenity.save()

        # Creating a place amenity 1
        new_place_amenity = PlaceAmenities(place=1, amenity=2)
        new_place_amenity.save()

        # Creating a place amenity 2
        new_place_amenity = PlaceAmenities(place=2, amenity=2)
        new_place_amenity.save()

        # testing amenities for a different place
        get_place_amenity = self.app.get('/places/1/amenities')
        # assert get_place_amenity.status_code == 200
        print get_place_amenity.data

        # testing amenities for a different place
        get_place_amenity = self.app.get('/places/2/amenities')
        assert get_place_amenity.status_code == 200

        # testing amenities for a different place that does not exist
        get_place_amenity = self.app.get('/places/3/amenities')
        assert get_place_amenity.status_code == 404

        # creating a new amenity to a place
        add_amenity = self.app.post('/places/1/amenities/1')
        assert add_amenity.status_code == 200

        # creating a new amenity to a place that does not exist
        add_amenity = self.app.post('/places/3/amenities/1')
        assert add_amenity.status_code == 404

        # creating a new amenity that does not exist for a place
        add_amenity = self.app.post('/places/1/amenities/3')
        assert add_amenity.status_code == 404

        # deleting amenities from a place
        delete_amenity = self.app.delete('/places/1/amenities/1')
        assert delete_amenity.status_code == 200
Esempio n. 22
0
    def test_Place_amenities(self):
        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='jon@snow',
                     password='******')
        user1.save()
        # Creating Place
        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 an amenity
        new_amenity = Amenity(name="amenity1")
        new_amenity.save()

        # Creating a place amenity

        new_place_amenity = PlaceAmenities(place=1, amenity=1)
        new_place_amenity.save()

        # Creating amenity test for different user
        new_state = State(name='Oregon')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()

        # Creating a new users 2
        user1 = User(first_name='Jon',
                     last_name='Snow',
                     email='jon+1c@snow',
                     password='******')
        user1.save()

        # Creating Place 2
        new_place = Place(owner=2,
                          city=2,
                          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 an amenity 2
        new_amenity = Amenity(name="amenity2")
        new_amenity.save()

        # Creating a place amenity 1
        new_place_amenity = PlaceAmenities(place=1, amenity=2)
        new_place_amenity.save()

        # Creating a place amenity 2
        new_place_amenity = PlaceAmenities(place=2, amenity=2)
        new_place_amenity.save()

        # testing amenities for a different place
        get_place_amenity = self.app.get('/places/1/amenities')
        # assert get_place_amenity.status_code == 200
        print get_place_amenity.data

        # testing amenities for a different place
        get_place_amenity = self.app.get('/places/2/amenities')
        assert get_place_amenity.status_code == 200

        # testing amenities for a different place that does not exist
        get_place_amenity = self.app.get('/places/3/amenities')
        assert get_place_amenity.status_code == 404

        # creating a new amenity to a place
        add_amenity = self.app.post('/places/1/amenities/1')
        assert add_amenity.status_code == 200

        # creating a new amenity to a place that does not exist
        add_amenity = self.app.post('/places/3/amenities/1')
        assert add_amenity.status_code == 404

        # creating a new amenity that does not exist for a place
        add_amenity = self.app.post('/places/1/amenities/3')
        assert add_amenity.status_code == 404

        # deleting amenities from a place
        delete_amenity = self.app.delete('/places/1/amenities/1')
        assert delete_amenity.status_code == 200