def test_verify_attr(self): ''' check for attributes ''' obj = state.State() self.assertTrue(hasattr(obj, 'name')) self.assertTrue(hasattr(obj, 'id')) self.assertTrue(hasattr(obj, 'created_at')) self.assertTrue(hasattr(obj, 'updated_at')) self.assertEqual(obj.__class__.__name__, 'State')
def test_typos(self): ''' check for attributes ''' obj = state.State() self.assertEqual(type(obj.name), 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__, 'State')
def create_state(): """Returns the new State with the status code 201""" if not request.json: abort(400, 'Not a JSON') if 'name' not in request.json: abort(400, 'Missing name') my_state = state.State(name=request.json.get('name', "")) storage.new(my_state) my_state.save() return make_response(jsonify(my_state.to_dict()), 201)
def createstate(): """Create a state""" s = request.get_json(silent=True) if s is None: abort(400, "Not a JSON") elif "name" not in s.keys(): abort(400, "Missing name") else: new_s = state.State(**s) storage.new(new_s) storage.save() return jsonify(new_s.to_dict()), 201
def post_obj(): """add new state object""" dic = {} dic = request.get_json(silent=True) if dic is None: abort(400, "Not a JSON") if "name" not in dic.keys(): abort(400, "Missing name") new_state = state.State() for k, v in dic.items(): setattr(new_state, k, v) storage.new(new_state) storage.save() return jsonify(new_state.to_dict()), 201
def do_create_state(request): """ Creates a state object Return: new state object """ body_request = request.get_json() if (body_request is None): abort(400, 'Not a JSON') try: state_name = body_request['name'] except KeyError: abort(400, 'Missing name') new_state = state.State(name=state_name) storage.new(new_state) storage.save() return jsonify(new_state.to_dict())
print("-- Create a new User --") my_user = user.User() my_user.first_name = "Betty" my_user.last_name = "Holberton" my_user.email = "*****@*****.**" my_user.password = "******" 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)
def test_kwargs(self): """Test the class - BaseModel passing kwargs """ dictionary = {'id': '662a23b3-abc7-4f43-81dc-64c000000c00'} user1 = state.State(**dictionary) self.assertTrue(issubclass(user1.__class__, BaseModel))
def test_subClass(self): '''Check if object have inheritance of the superclass''' obj = state.State() self.assertTrue(issubclass(type(obj), BaseModel))