Пример #1
0
 def test_method_str(self):
     """Test method str"""
     new = Amenity()
     self.assertEqual(new.__str__(), "[{}] ({}) {}".format
                                     (new.__class__.__name__,
                                      new.id, new.__dict__))
     self.assertTrue(type(new.__str__()), str)
     self.assertTrue(len(new.__str__()))
Пример #2
0
 def test_str(self):
     """Test Amenity str representation.
     """
     new = Amenity()
     trex = r"\[Amenity\] \(.*\) .*"
     self.assertIsInstance(new, Amenity)
     self.assertTrue(type(new.__str__()) == str)
     self.assertTrue(search(trex, new.__str__()))
     args = ["hola", 2, 3.2, "poads"]
     new = Amenity(*args)
     self.assertIsInstance(new, Amenity)
     new = Amenity("hola", 2, 3.2, "poads")
     self.assertIsInstance(new, Amenity)
Пример #3
0
 def test_str(self):
     """ review format: [<class name>] (<self.id>) <self.__dict__>
     """
     my_class = Amenity()
     string = "[{:s}] ({:s}) {}".format(my_class.__class__.__name__,
                                        my_class.id, my_class.__dict__)
     self.assertEqual(string, my_class.__str__())
Пример #4
0
 def test_4_str_method(self):
     """is the string representation is wrong"""
     model_1 = Amenity()
     model_1.save()
     str_model = "[" + str(model_1.__class__.__name__) + "] (" + \
                 str(model_1.id) + ") " + str(model_1.__dict__)
     self.assertEqual(model_1.__str__(), str_model)
Пример #5
0
    def test_str(self):
        """Test __str__ method"""

        am = Amenity()
        string = '[' + am.__class__.__name__ + ']' + ' (' + am.id + ') ' + str(
            am.__dict__)
        self.assertEqual(string, am.__str__())
Пример #6
0
 def test_amenity_str_method(self):
     """Amenity str method creates accurate representation"""
     amenity = Amenity()
     amenity_str = amenity.__str__()
     self.assertIsInstance(amenity_str, str)
     self.assertEqual(amenity_str[:9], '[Amenity]')
     self.assertEqual(amenity_str[10:48], '({})'.format(amenity.id))
     self.assertDictEqual(eval(amenity_str[49:]), amenity.__dict__)
Пример #7
0
    def test_str(self):
        """ test print """

        u1 = Amenity()
        u2 = Amenity(id='Betty')
        s = "[{}] ({}) {}".format("Amenity", u1.id, u1.__dict__)
        self.assertEqual(print(s), print(u1))
        self.assertIsInstance(u1.__str__(), str)

        s = "[{}] ({}) {}".format("Amenity", u2.id, u2.__dict__)
        self.assertEqual(print(s), print(u2))
Пример #8
0
 def test_str_representation(self):
     dt = datetime.today()
     dt_repr = repr(dt)
     am = Amenity()
     am.id = "123456"
     am.created_at = am.updated_at = dt
     amstr = am.__str__()
     self.assertIn("[Amenity] (123456)", amstr)
     self.assertIn("'id': '123456'", amstr)
     self.assertIn("'created_at': " + dt_repr, amstr)
     self.assertIn("'updated_at': " + dt_repr, amstr)
Пример #9
0
 def test_Amenity(self):
     """Test instance of amenity class"""
     new = Amenity()
     new2 = Amenity()
     self.assertIsInstance(new, BaseModel)
     self.assertNotEqual(new, new2)
     self.assertNotEqual(new.id, new2.id)
     self.assertEqual(issubclass(new.__class__, BaseModel), True)
     self.assertIs(type(new), Amenity)
     self.assertTrue(hasattr(new, "id"))
     self.assertEqual(new.__str__(), "[{}] ({}) {}".format
                                   (new.__class__.__name__,
                                   new.id, new.__dict__))
     self.assertEqual(type(new.id), str)
     self.assertEqual(Amenity, type(Amenity()))
Пример #10
0
class TestAmenity(unittest.TestCase):

    def setUp(self):
        '''method to set up instance of BaseModel/json file'''
        self.amenity = Amenity()

    def tearDown(self):
        '''method to tear down instance of BaseModel/json file'''
        if os.path.exists("file.json"):
            try:
                os.remove("file.json")
            except:
                pass

    def test___init__(self):
        '''method to check if instance initializes'''
        self.assertIsNotNone(self.amenity)

    def test_attributes(self):
        '''method to test if updates take place in save'''
        self.assertEqual(self.amenity.name, "")
        self.assertTrue(hasattr(self.amenity, "created_at"))
        self.assertFalse(hasattr(self.amenity, "updated_at"))
        self.assertTrue(hasattr(self.amenity, "id"))
        self.amenity.save()
        self.assertTrue(hasattr(self.amenity, "updated_at"))

    def test_to_json(self):
        '''method to check that the to_json function returns'''
        example_tojson = Amenity.to_json(self.amenity)
        self.assertEqual(type(example_tojson), dict)

    def test___str__(self):
        '''method to check that dict printing instance'''
        example = "[{}] ({}) {}".format(self.__class__.__name__,
                                        self.id, self.__dict__)
        self.assertEqual(print(self.amenity), print(example))

    def test__repr__(self):
        '''method to print attributes of dictionary'''
        self.assertIsNotNone(self.amenity.__str__())
Пример #11
0
 def test_str_method(self):
     """Tests to see if each method is printing accurately"""
     i = Amenity()
     printed = i.__str__()
     self.assertEqual(printed,
                      "[Amenity] ({}) {}".format(i.id, i.__dict__))
Пример #12
0
class Test_Amenity(unittest.TestCase):
    """ Class to test
    """

    def setUp(self):
        """Function that execute before of each test function
        """
        self.obj = Amenity()

    def test_createBaseModel(self):
        """Test that is instance
        """
        self.assertIsInstance(self.obj, Amenity)

    def test_Id_Is_String(self):
        """Id is string
        """
        self.assertEqual(type(self.obj.id), str)

    def test_add_Atrribute(self):
        self.obj.name = "Holberton"
        self.obj.my_number = 89
        self.assertTrue(self.obj.name)
        self.assertTrue(self.obj.my_number)

    def test_docString(self):
        """Test if function and class have docString
        """
        self.assertIsNotNone(Amenity.__doc__)

    def test_pep8_base_model(self):
        """ Test for PEP8
        """
        pep8style = pep8.StyleGuide(quiet=True)
        result = pep8style.check_files(['models/amenity.py'])
        self.assertEqual(result.total_errors, 0, "Please fix pep8")

    def test_id_uuid_v4(self):
        """Test version 4 of UUID
        """
        test__version = uuid.UUID(self.obj.id).version
        self.assertEqual(test__version, 4, "Error: Different version")

    def test_created_at_Is_datatime(self):
        """Test that created_at is instance of datetime
        """
        self.assertIsInstance(self.obj.created_at, datetime)

    def test_updated_at_Is_datatime(self):
        """Test that updated_at is instance of datetime
        """
        self.assertIsInstance(self.obj.updated_at, datetime)

    def test_str(self):
        """ Test function __str__
        """
        s = "[{}] ({}) {}".format(
            self.obj.__class__.__name__, self.obj.id, self.obj.__dict__)
        self.assertEqual(self.obj.__str__(), s)

    def test_save(self):
        """Test save objects in a json file
        """
        self.obj.save()
        key = self.obj.__class__.__name__+"."+self.obj.id
        self.assertEqual(self.obj, models.storage.all()[key])
        self.assertNotEqual(self.obj.created_at, self.obj.updated_at)
        self.assertTrue(os.path.exists("file.json"))

    def test_save_content(self):
        """Test to compare the saved in json file with to_dic()"""
        self.obj.save()
        dict_to_load = {}
        with open("file.json", 'r') as f:
                dict_to_load = json.loads(f.read())
        self.assertDictEqual(
            self.obj.to_dict(), dict_to_load['Amenity.' + self.obj.id])

    def test_to_dict(self):
        """Test to compare to two dictonary
        """
        new_dict = self.obj.__dict__.copy()
        new_dict["__class__"] = self.obj.__class__.__name__
        new_dict["created_at"] = new_dict["created_at"].isoformat()
        new_dict["updated_at"] = new_dict["updated_at"].isoformat()
        self.assertDictEqual(new_dict, self.obj.to_dict())
        self.assertEqual(self.obj.to_dict()['__class__'], "Amenity")
        self.assertEqual(type(self.obj).__name__, "Amenity")
Пример #13
0
 def test_str_method(self):
     """Tests to see if each method is printing accurately"""
     b1 = Amenity()
     b1printed = b1.__str__()
     self.assertEqual(b1printed,
                      "[Amenity] ({}) {}".format(b1.id, b1.__dict__))
Пример #14
0
 def test_str_(self):
     """ testing to see if the method is printing """
     b1 = Amenity()
     b1_str = b1.__str__()
     self.assertEqual(b1_str,
                      "[Amenity] ({}) {}".format(b1.id, b1.__dict__))
Пример #15
0
 def test_str(self):
     """ Tests the str repr. of an object """
     base = Amenity()
     base_str = base.__str__()
     self.assertTrue(isinstance(base_str, str))
Пример #16
0
 def test_str(self):
     z = Amenity()
     stringA = str(z)
     stringB = z.__str__()
     self.assertTrue(stringA, stringB)
Пример #17
0
 def test_str_method(self):
     """Tests to see if each method is printing accurately"""
     obj = Amenity()
     objprinted = obj.__str__()
     self.assertEqual(objprinted,
                      "[Amenity] ({}) {}".format(obj.id, obj.__dict__))
Пример #18
0
 def test_str_method(self):
     """test that each method is printing accurately"""
     a3 = Amenity()
     a3printed = a3.__str__()
     self.assertEqual(a3printed,
                      "[Amenity] ({}) {}".format(a3.id, a3.__dict__))
Пример #19
0
class TestAmanity(unittest.TestCase):
    """Class test
    """
    def setUp(self):
        """ setUp init for tests"""
        self.my_model = Amenity()
        self.my_model2 = Amenity()
        self.my_model.name = "Vale"
        self.my_model.age = 28

    def test_pep8_conformance_Amenity(self):
        """Test that we conform to PEP8."""
        pep8style = pep8.StyleGuide(quiet=True)
        result = pep8style.check_files(['models/amenity.py'])
        self.assertEqual(result.total_errors, 0)

    def test_docstrings(self):
        """Test docstrings"""
        self.assertIsNotNone(Amenity.__doc__)
        self.assertIsNotNone(Amenity.__init__.__doc__)
        self.assertIsNotNone(Amenity.__str__.__doc__)
        self.assertIsNotNone(Amenity.save.__doc__)
        self.assertIsNotNone(Amenity.to_dict.__doc__)

    def test_base(self):
        """Test for BaseModel
        """
        self.assertIsInstance(self.my_model, Amenity)
        self.assertEqual(self.my_model.name, "Vale")
        self.assertEqual(self.my_model.age, 28)
        self.assertTrue(hasattr(self.my_model, "id"))
        self.assertTrue(hasattr(self.my_model, "created_at"))
        self.assertTrue(hasattr(self.my_model, "updated_at"))
        self.assertTrue(hasattr(self.my_model, "__class__"))
        model1 = self.my_model.created_at
        model2 = self.my_model2.created_at
        self.assertTrue(model1 != model2)
        model1 = self.my_model.id
        model2 = self.my_model2.id
        self.assertNotEqual(model1, model2)

    def test_to_dict(self):
        """test_to_dict - test the return of a dict containing
            all the key/values of __dict__"""

        dict_json = self.my_model.to_dict()
        self.assertEqual(type(dict_json), dict)
        self.assertTrue(type(dict_json['created_at']) is str)
        self.assertTrue(type(dict_json['updated_at']) is str)

    def test_save(self):
        """Test for save method
        """
        previous_update = self.my_model.updated_at
        self.my_model.save()
        self.assertNotEqual(previous_update, self.my_model.updated_at)

    def test_str(self):
        """Test for __str__ method
        """
        self.assertEqual(
            str(self.my_model),
            "[Amenity] ({}) {}".format(self.my_model.id,
                                       self.my_model.__dict__))
        self.assertEqual(
            self.my_model.__str__(),
            "[Amenity] ({}) {}".format(self.my_model.id,
                                       self.my_model.__dict__))

    def test_kwargs(self):
        """Test for recreate instance from a instance old
        """
        dict_json = self.my_model.to_dict()
        my_model2 = Amenity(**dict_json)
        self.assertFalse(my_model2 is self.my_model)
        self.assertEqual(self.my_model.id, my_model2.id)
        self.assertEqual(self.my_model.created_at, my_model2.created_at)
        self.assertEqual(self.my_model.updated_at, my_model2.updated_at)
Пример #20
0
 def test_str_(self):
     """ tests str method """
     b1 = Amenity()
     b1_str = b1.__str__()
     self.assertEqual(b1_str,
                      "[Amenity] ({}) {}".format(b1.id, b1.__dict__))