Exemple #1
0
 def test_father(self):
     """Test the class - BaseModel """
     place1 = Place()
     self.assertTrue(issubclass(place1.__class__, BaseModel))
 def test_ID(self):
     """
     Make sure that the ID is unique
     """
     place2 = Place()
     self.assertNotEqual(self.place.id, place2.id)
 def test_user_id(self):
     """testing if a subclass had a ins(user_id) and if this is empty"""
     s = Place()
     self.assertEqual(s.user_id, "")
     self.assertTrue(hasattr(s, "user_id"))
Exemple #4
0
 def test_new_instance_stored_in_objects(self):
     self.assertIn(Place(), models.storage.all().values())
Exemple #5
0
 def setUp(self):
     """instance setup"""
     self.place = Place()
def places(city_id=None, place_id=None):
    """handles HTTP requests related to places"""
    if city_id is not None:
        # /cities/<city_id>/places GET method
        if request.method == 'GET':
            city = storage.get(City, city_id)
            if city is None:
                abort(404)
            return jsonify([place.to_dict() for place in city.places])

        # /cities/<city_id>/places POST method
        if request.method == 'POST':
            new_json = request.get_json(silent=True)
            city = storage.get(City, city_id)
            if city is None:
                abort(404)
            if new_json is None:
                abort(400, 'Not a JSON')
            if 'user_id' not in new_json.keys():
                abort(400, 'Missing user_id')
            if 'name' not in new_json:
                abort(400, 'Missing name')
            if storage.get(User, new_json['user_id']) is None:
                abort(404)
            new_place = Place(**new_json)
            new_place.city_id = city_id
            storage.new(new_place)
            storage.save()
            return jsonify(new_place.to_dict()), 201

    else:
        # /places/<place_id> GET method
        if request.method == 'GET':
            place = storage.get(Place, place_id)
            if place is not None:
                return jsonify(place.to_dict())
            abort(404)

        # places/<place_id> DELETE method
        if request.method == 'DELETE':
            place = storage.get(Place, place_id)
            if place is not None:
                place.delete()
                storage.save()
                return jsonify({}), 200
            abort(404)

        # places/<place_id> PUT method
        if request.method == 'PUT':
            place = storage.get(Place, place_id)
            if place is None:
                abort(404)
            new_json = request.get_json(silent=True)
            if new_json is None:
                abort(400, 'Not a JSON')
            for k, v in new_json.items():
                if k not in [
                        'id', 'user_id', 'city_id', 'created_at', 'updated_at'
                ]:
                    setattr(place, k, v)
            place.save()
            return jsonify(place.to_dict()), 200
Exemple #7
0
 def setUp(self):
     self.model = Place()
     self.model.save()
Exemple #8
0
 def test_two_models_are_unique(self):
     """Test that different Place instances are unique."""
     us = Place()
     self.assertNotEqual(self.place.id, us.id)
     self.assertLess(self.place.created_at, us.created_at)
     self.assertLess(self.place.updated_at, us.updated_at)
Exemple #9
0
 def test_init_args_kwargs(self):
     """Test initialization with args and kwargs."""
     dt = datetime.utcnow()
     st = Place("1", id="5", created_at=dt.isoformat())
     self.assertEqual(st.id, "5")
     self.assertEqual(st.created_at, dt)
Exemple #10
0
 def setUpClass(cls):
     """Define all attributes for test the class methods
     """
     cls.place1 = Place()
 def test_delete_city_file(self):
     """test if delete works"""
     self.place = Place()
     self.place.name = 'Holberton'
     self.place.save()
     del self.place
Exemple #12
0
 def test_type(self):
     """Test Place value type."""
     place1 = Place()
     self.assertEqual(type(place1.name), str)
     self.assertNotEqual(type(place1.name), list)
Exemple #13
0
 def test_Place(self):
     """Test attributes of the class."""
     my_Place = Place()
     my_Place.name = "LA"
     self.assertEqual(my_Place.name, 'LA')
Exemple #14
0
 def test_father_kwargs(self):
     """Test the class - BaseModel passing kwargs """
     dictonary = {'id': '662a23b3-abc7-4f43-81dc-64c000000c00'}
     place1 = Place(**dictonary)
     self.assertTrue(issubclass(place1.__class__, BaseModel))
 def test_id(self):
     '''test if the id of two instances are different'''
     instance1 = Place()
     instance2 = Place()
     self.assertNotEqual(instance1.id, instance2.id)
Exemple #16
0
    def setUp(self):
        '''Creates an instance for place.'''

        self.new_place = Place()
Exemple #17
0
 def test_place_type(self):
     """ place value type test """
     self.one = Place()
     self.assertEqual(type(self.one.user_id), str)
     self.assertEqual(type(self.one.number_rooms), int)
     self.assertEqual(type(self.one.amenity_ids), list)
Exemple #18
0
 def test_instance(self):
     """
     instance test
     """
     hi = Place()
     self.assertIsInstance(hi, Place)
Exemple #19
0
 def setUp(self):
     """ setUp init for tests"""
     self.my_model = Place()
     self.my_model2 = Place()
     self.my_model.name = "Vale"
     self.my_model.age = 28
Exemple #20
0
 def test_id(self):
     """
     tests id
     """
     hi = Place()
     self.assertEqual("", hi.city_id)
Exemple #21
0
 def test_no_args(self):
     self.assertEqual(Place, type(Place()))
Exemple #22
0
 def test_user_id(self):
     """
     tests user id
     """
     hi = Place()
     self.assertEqual("", hi.user_id)
Exemple #23
0
 def test_inheritance(self):
     '''test that user inherits from basemodel'''
     new = Place()
     self.assertIsInstance(new, BaseModel)
Exemple #24
0
 def test_name(self):
     """
     tests name
     """
     hi = Place()
     self.assertEqual("", hi.name)
 def setUp(self):
     """
     Create a new instance of Place
     """
     self.place = Place()
Exemple #26
0
 def setUp(self):
     """
     objects for testing
     """
     self.model1_test = Place()
     self.model2_test = Place()
Exemple #27
0
 def setUp(self):
     self.my_model = Place()
 def setUp(self):
     '''Object created from a class'''
     self.my_object = Place()
 def test_description(self):
     """testing if a subclass had a ins(user_id) and if this is empty"""
     x = Place()
     self.assertTrue(hasattr(x, "description"))
     self.assertEqual(x.description, "")
Exemple #30
0
    def setUpClass(cls):
        """ first set up
        check = style.check_files([file_place, file_test_place])

        """
        cls.ins = Place()