Пример #1
0
 def test_verify_attr(self):
     ''' check for attributes '''
     obj = review.Review()
     self.assertTrue(hasattr(obj, 'place_id'))
     self.assertTrue(hasattr(obj, 'user_id'))
     self.assertTrue(hasattr(obj, 'text'))
     self.assertTrue(hasattr(obj, 'id'))
     self.assertTrue(hasattr(obj, 'created_at'))
     self.assertTrue(hasattr(obj, 'updated_at'))
     self.assertEqual(obj.__class__.__name__, 'Review')
Пример #2
0
 def test_typos(self):
     ''' check for attributes '''
     obj = review.Review()
     self.assertEqual(type(obj.place_id), str)
     self.assertEqual(type(obj.user_id), str)
     self.assertEqual(type(obj.text), str)
     self.assertEqual(type(obj.id), str)
     self.assertEqual(type(obj.created_at), datetime)
     self.assertEqual(type(obj.updated_at), datetime)
     self.assertEqual(obj.__class__.__name__, 'Review')
Пример #3
0
def add_review(place_id=None):
    """add a review of place"""
    data = request.get_json(silent=True)
    place_obj = storage.get("Place", place_id)
    if place_obj is None:
        abort(404)
    if data is None:
        abort(400, jsonify({"message": "Not a JSON"}))
    if 'user_id' not in data.keys():
        abort(400, jsonify({"message": "Missing user_id"}))
    if storage.get("User", data.get('user_id')) is None:
        abort(404)
    if data.get('text') is None:
        abort(400, jsonify({"message": "Missing text"}))
    new_review = review.Review(user_id=data.get('user_id'),
                               place_id=place_id,
                               text=data.get('text'))
    storage.new(new_review)
    storage.save()
    return jsonify(new_review.to_dict()), 201
Пример #4
0
def create_review(place_id):
    """Creates a Review object"""
    my_place = storage.get('Place', place_id)
    if my_place is None:
        abort(404)
    if not request.json:
        abort(400, 'Not a JSON')
    if 'user_id' not in request.json:
        abort(400, 'Missing user_id')
    if 'text' not in request.json:
        abort(400, 'Missing text')
    my_user = storage.get('User', request.json.get('user_id', ""))
    if my_user is None:
        abort(404)
    req = request.get_json(silent=True)
    req['place_id'] = place_id
    my_review = review.Review(**req)
    storage.new(my_review)
    my_review.save()
    return make_response(jsonify(my_review.to_dict()), 201)
Пример #5
0
def post_review(place_id):
    """ Add a new review based in place_id """
    content = request.get_json()
    if content is None:
        abort(400, 'Not a JSON')
    if 'user_id' not in content:
        abort(400, 'Missing user_id')
    if 'text' not in content:
        abort(400, 'Missing text')
    one_place = storage.get(place.Place, place_id)
    if one_place is None:
        abort(404)
    one_user = storage.get(user.User, content['user_id'])
    if one_user is None:
        abort(404)
    new_review = review.Review()
    new_review.text = content['text']
    new_review.user_id = content['user_id']
    new_review.place_id = place_id
    storage.new(new_review)
    storage.save()
    return (jsonify(new_review.to_dict()), 201)
Пример #6
0
def add_review(place_id):
    """add a review"""
    data = {}
    place = storage.get('Place', place_id)
    if place is None:
        abort(404)
    data = response.get_json(silent=True)
    if data is None:
        abort(400, "Not a JSON")
    if 'user_id' not in data.keys():
        abort(400, "Missing user_id")
    user_id = data['user_id']
    user = storage.get('User', user_id)
    if user is None:
        abort(404)
    if 'text' not in data.keys():
        abort(400, "Missing text")
    new_review = review.Review(place_id=place.id)
    for k, v in data.items():
        setattr(new_review, k, v)
    storage.new(new_review)
    storage.save()
    return jsonify(new_review.to_dict()), 201
Пример #7
0
def do_create_review(request, place_id):
    """
        Creates a review object
        Return: new review object
    """
    do_check_id(place.Place, place_id)
    body_request = request.get_json(silent=True)
    if (body_request is None):
        abort(400, 'Not a JSON')
    try:
        user_id = body_request['user_id']
    except KeyError:
        abort(400, 'Missing user_id')
    do_check_id(user.User, user_id)
    try:
        review_text = body_request['text']
    except KeyError:
        abort(400, 'Missing text')
    new_review = review.Review(text=review_text,
                               place_id=place_id,
                               user_id=user_id)
    storage.new(new_review)
    storage.save()
    return jsonify(new_review.to_dict())
Пример #8
0
my_user.save()
print(my_user)

my_city = city.City()
my_city.name = "San Francisco"
my_city.state_id = "101"
my_city.save()
print(my_city)

my_state = state.State()
my_state.name = "california"
my_state.save()
print(my_state)

my_place = place.Place()
my_place.number_rooms = 3
my_place.max_guest = 2
my_place.price_by_night = 100
my_place.save()
print(my_place)

my_amenity = amenity.Amenity()
my_amenity.name = "House Keeping"
my_amenity.save()
print(my_amenity)

my_review = review.Review()
my_review.text = "Its a good place."
my_review.save()
print(my_review)
Пример #9
0
 def test_kwargs(self):
     """Test the class - BaseModel passing kwargs """
     dictionary = {'id': '662a23b3-abc7-4f43-81dc-64c000000c00'}
     user1 = review.Review(**dictionary)
     self.assertTrue(issubclass(user1.__class__, BaseModel))
Пример #10
0
 def test_subClass(self):
     '''Check if object have inheritance of the superclass'''
     obj = review.Review()
     self.assertTrue(issubclass(type(obj), BaseModel))