예제 #1
0
def return_city(city_id):
    """return a city"""
    city = storage.get('City', city_id)
    if city is None:
        abort(404)
    else:
        return jsonify(city.to_dict())
예제 #2
0
 def test_create_to_dict(self):
     """
     test to verified if the dic is created
     """
     city = City()
     dict_new = city.to_dict()
     self.assertEqual(type(dict_new), dict)
예제 #3
0
 def test_values_to_dict(self):
     """test to verified de values in a dic"""
     city = City()
     dict_new = city.to_dict()
     self.assertEqual(dict_new["__class__"], "City")
     self.assertEqual(type(dict_new["created_at"]), str)
     self.assertEqual(type(dict_new["updated_at"]), str)
     self.assertEqual(type(dict_new["id"]), str)
예제 #4
0
def return_cities(state_id):
    """return json City objects"""
    state = storage.get('State', state_id)
    if state is None:
        abort(404)
    cities = []
    for city in storage.all('City').values():
        if city.state_id == state_id and state_id == state.id:
            cities.append(city.to_dict())
    return jsonify(cities)
예제 #5
0
 def test_to_dict_values(self):
     """test the values in dict"""
     time = "%Y-%m-%dT%H:%M:%S.%f"
     city = City()
     new_dict = city.to_dict()
     self.assertEqual(new_dict["__class__"], "City")
     self.assertEqual(type(new_dict[c]), str)
     self.assertEqual(type(new_dict[u]), str)
     self.assertEqual(new_dict[c], city.created_at.strftime(time))
     self.assertEqual(new_dict[u], city.updated_at.strftime(time))
예제 #6
0
def update_city(city_id):
    """update a city"""
    city = {}
    city = storage.get('City', city_id)
    if city is None:
        abort(404)
    data = request.get_json(silent=True)
    if data is None:
        abort(400, "Not a JSON")
    for k, v in data.items():
        setattr(city, k, v)
    storage.save()
    return jsonify(city.to_dict()), 200
예제 #7
0
 def test_str(self):
     """test that the str method has the correct output"""
     city = City()
     string = "[City] ({}) {}".format(city.id, city.to_dict())
     self.assertEqual(string, str(city))