Exemplo n.º 1
0
 def test_method_str(self):
     """Test method str"""
     new = State()
     self.assertEqual(new.__str__(), "[{}] ({}) {}".format
                                     (new.__class__.__name__,
                                      new.id, new.__dict__))
     self.assertTrue(type(new.__str__()), str)
     self.assertTrue(len(new.__str__()))
Exemplo n.º 2
0
 def test_str(self):
     """
     Check str method.
     """
     new_state = State()
     string = "[State] ({}) {}".format(new_state.id, new_state.__dict__)
     self.assertIsInstance(new_state.__str__(), str)
     self.assertEqual(new_state.__str__(), string)
Exemplo n.º 3
0
 def test_str(self):
     """Test State str representation.
     """
     new = State()
     trex = r"\[State\] \(.*\) .*"
     self.assertIsInstance(new, State)
     self.assertTrue(type(new.__str__()) == str)
     self.assertTrue(search(trex, new.__str__()))
     args = ["hola", 2, 3.2, "poads"]
     new = State(*args)
     self.assertIsInstance(new, State)
     new = State("hola", 2, 3.2, "poads")
     self.assertIsInstance(new, State)
Exemplo n.º 4
0
 def test_4_str_method(self):
     """is the string representation is wrong"""
     model_1 = State()
     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)
Exemplo n.º 5
0
 def test_str(self):
     """ review format: [<class name>] (<self.id>) <self.__dict__>
     """
     my_class = State()
     string = "[{:s}] ({:s}) {}".format(my_class.__class__.__name__,
                                        my_class.id, my_class.__dict__)
     self.assertEqual(string, my_class.__str__())
Exemplo n.º 6
0
 def test_str_method(self):
     """str"""
     s = "[State] ({}) {}"
     my_state14 = State()
     my_state14printed = my_state14.__str__()
     self.assertEqual(my_state14printed,
                      s.format(my_state14.id, my_state14.__dict__))
Exemplo n.º 7
0
 def test_str(self):
     """tests __str__ method inherited from BaseModel class"""
     tests = State()
     test_str = tests.__str__()
     test_str = test_str.split()
     self.assertEqual(test_str[0], "[{}]".format(tests.__class__.__name__))
     self.assertEqual(test_str[1], "({})".format(tests.id))
Exemplo n.º 8
0
    def test_str(self):
        """Test __str__ method"""

        st = State()
        string = '[' + st.__class__.__name__ + ']' + ' (' + st.id + ') ' + str(
            st.__dict__)
        self.assertEqual(string, st.__str__())
Exemplo n.º 9
0
    def test_3_str(self):
        '''If str method work as expected'''

        my_model_0 = State()
        my_model_1 = State()
        my_model_2 = State()

        str_model_0 = "[" + str(type(my_model_0).__name__) + "] (" + \
                      str(my_model_0.id) + ") " + str(my_model_0.__dict__)
        str_model_1 = "[" + str(type(my_model_1).__name__) + "] (" + \
                      str(my_model_1.id) + ") " + str(my_model_1.__dict__)
        str_model_2 = "[" + str(type(my_model_2).__name__) + "] (" + \
                      str(my_model_2.id) + ") " + str(my_model_2.__dict__)

        self.assertEqual(str(my_model_0), str_model_0)
        self.assertEqual(my_model_1.__str__(), str_model_1)
        self.assertEqual(my_model_2.__str__(), str_model_2)
Exemplo n.º 10
0
 def test_state_str_method(self):
     """State str method creates accurate representation"""
     state = State()
     state_str = state.__str__()
     self.assertIsInstance(state_str, str)
     self.assertEqual(state_str[:7], '[State]')
     self.assertEqual(state_str[8:46], '({})'.format(state.id))
     self.assertDictEqual(eval(state_str[47:]), state.__dict__)
Exemplo n.º 11
0
    def test_str(self):
        """ test print """

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

        s = "[{}] ({}) {}".format("State", u2.id, u2.__dict__)
        self.assertEqual(print(s), print(u2))
Exemplo n.º 12
0
 def test_str_representation(self):
     dt = datetime.today()
     dt_repr = repr(dt)
     st = State()
     st.id = "123456"
     st.created_at = st.updated_at = dt
     ststr = st.__str__()
     self.assertIn("[State] (123456)", ststr)
     self.assertIn("'id': '123456'", ststr)
     self.assertIn("'created_at': " + dt_repr, ststr)
     self.assertIn("'updated_at': " + dt_repr, ststr)
Exemplo n.º 13
0
 def test_State(self):
     """Test instance of amenity class"""
     new = State()
     new2 = State()
     self.assertIsInstance(new, BaseModel)
     self.assertEqual(issubclass(new.__class__, BaseModel), True)
     self.assertIs(type(new), State)
     self.assertTrue(hasattr(new, "id"))
     self.assertNotEqual(new, new2)
     self.assertNotEqual(new.id, new2.id)
     self.assertEqual(new.__str__(), "[{}] ({}) {}".format
                                     (new.__class__.__name__,
                                      new.id, new.__dict__))
     self.assertEqual(type(new.id), str)
     self.assertEqual(State, type(State()))
Exemplo n.º 14
0
class TestAmenity(unittest.TestCase):
    def setUp(self):
        '''method to set up instance of State/json file'''
        self.state = State()

    def tearDown(self):
        '''method to tear down instance of State/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.state)

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

    def test_to_json(self):
        '''method to check that the to_json function returns'''
        example_tojson = State.to_json(self.state)
        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.state), print(example))

    def test__repr__(self):
        '''method to print attributes of dictionary'''
        self.assertIsNotNone(self.state.__str__())
Exemplo n.º 15
0
class TestState(unittest.TestCase):
    """Class test
    """
    def setUp(self):
        """ setUp init for tests"""
        self.my_model = State()
        self.my_model2 = State()
        self.my_model.name = "Vale"
        self.my_model.age = 28

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

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

    def test_state(self):
        """Test for State
        """
        self.assertIsInstance(self.my_model, State)
        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),
            "[State] ({}) {}".format(self.my_model.id, self.my_model.__dict__))
        self.assertEqual(
            self.my_model.__str__(),
            "[State] ({}) {}".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 = State(**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)
Exemplo n.º 16
0
class Test_State(unittest.TestCase):
    """ Class to test
    """
    def setUp(self):
        """Function that execute before of each test function
        """
        self.obj = State()

    def test_createState(self):
        """Test that is instance
        """
        self.assertIsInstance(self.obj, State)

    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(State.__doc__)

    def test_pep8_state(self):
        """ Test for PEP8
        """
        pep8style = pep8.StyleGuide(quiet=True)
        result = pep8style.check_files(['models/state.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['State.' + 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__'], "State")
        self.assertEqual(type(self.obj).__name__, "State")
Exemplo n.º 17
0
 def test_str(self):
     """ Tests the str repr. of an object """
     base = State()
     base_str = base.__str__()
     self.assertTrue(isinstance(base_str, str))
Exemplo n.º 18
0
 def test_str_method(self):
     """Tests to see if each method is printing accurately"""
     b1 = State()
     b1printed = b1.__str__()
     self.assertEqual(b1printed,
                      "[State] ({}) {}".format(b1.id, b1.__dict__))
Exemplo n.º 19
0
class TestBaseModel(unittest.TestCase):
    """Unit test for State class"""
    @classmethod
    def setUp(cls):
        print('SetupClass')

    @classmethod
    def tearDown(cls):
        print('TearDownClass')

    def setUp(self):
        """Unit test setup"""
        print('setUp')
        self.s1 = State()
        self.s2 = State()

    def tearDown(self):
        """Unit test tear down"""
        del self.s1
        del self.s2

    def test_init(self):
        """Test for init method"""
        print("testing init...")
        self.assertIsNotNone(self.s1)
        self.assertIsInstance(self.s1, BaseModel)
        self.assertIs(type(self.s1), State)

    def test_uuid(self):
        """Test for uuid attribute"""
        print("testing uuid...")
        self.assertTrue(hasattr(self.s1, "id"))
        self.assertNotEqual(self.s1.id, self.s2.id)
        self.assertIsInstance(self.s1.id, str)

    def test_name(self):
        """Test for name attribute"""
        print("testing name...")
        self.assertTrue(hasattr(self.s1, "name"))
        self.assertEqual(self.s1.name, "")
        self.assertIsInstance(self.s1.name, str)

    def test_str(self):
        """Test for __str__ method"""
        print("testing __str__method...")
        result = len(self.s1.__str__())
        self.assertTrue(result, 172)

    def test_save(self):
        """Test for save method"""
        print("testing save method...")
        prechange = self.s1.updated_at
        self.s1.save()
        postchange = self.s1.updated_at
        self.assertNotEqual(prechange, postchange)

    def test_created_at(self):
        """Test for created at time"""
        print("Testing the created at time attr")
        self.assertTrue(hasattr(self.s1, "created_at"))

    def test_updated_at(self):
        """Test for the updated at time attr"""
        print("Testing the updated at time attr")
        prechange = self.s1.updated_at
        self.s1.save()
        postchange = self.s1.updated_at
        self.assertNotEqual(prechange, postchange)

    def test_kwargs(self):
        """Test for kwargs"""
        print("Testing for kwargs")
        self.s1.name = "Holberton"
        self.s1.my_number = 89
        s1_json = self.s1.to_dict()

        s2 = State(**s1_json)
        self.assertEqual(self.s1.id, s2.id)
        self.assertEqual(self.s1.created_at, s2.created_at)
        self.assertEqual(self.s1.updated_at, s2.updated_at)
        self.assertEqual(self.s1.name, s2.name)
        self.assertEqual(self.s1.my_number, s2.my_number)

    def test_module_docstring(self):
        """Test for existence of module docstring"""
        print("testing module docstring...")
        result = len(__import__('models.state').__doc__)
        self.assertTrue(result > 0, True)

    def test_class_docstring(self):
        """State Class Docstring Test"""
        print("test_class_docstring")
        result = len(State.__doc__)
        self.assertTrue(result > 0, True)

    def test_init_docstring(self):
        """State init Docstring Test"""
        print("test_init_docstring")
        result = len(self.__init__.__doc__)
        self.assertTrue(result > 0, True)

    def test__str__docstring(self):
        """State __str__ Docstring Test"""
        print("testing __str__ docstring...")
        result = len(State.__str__.__doc__)
        self.assertTrue(result > 0, True)

    def test_save_docstring(self):
        """State save method Docstring Test"""
        print("testing save docstring...")
        result = len(State.save.__doc__)
        self.assertTrue(result > 0, True)

    def test_to_dict_docstring(self):
        """State to_dict Docstring Test"""
        print("testing to_dict docstring...")
        result = len(State.to_dict.__doc__)
        self.assertTrue(result > 0, True)

    if __name__ == "__main__":
        unittest.main()
Exemplo n.º 20
0
 def test_str_method(self):
     """Tests to see if each method is printing accurately"""
     i = State()
     printed = i.__str__()
     self.assertEqual(printed, "[State] ({}) {}".format(i.id, i.__dict__))
Exemplo n.º 21
0
 def test_str_(self):
     """ testing to see if the method is printing """
     b1 = State()
     b1_str = b1.__str__()
     self.assertEqual(b1_str, "[State] ({}) {}".format(b1.id, b1.__dict__))
Exemplo n.º 22
0
 def test_str_method(self):
     """test that each method is printing accurately"""
     s3 = State()
     s3printed = s3.__str__()
     self.assertEqual(s3printed,
                      "[State] ({}) {}".format(s3.id, s3.__dict__))
Exemplo n.º 23
0
 def test_str_method(self):
     """Tests to see if each method is printing accurately"""
     obj = State()
     objprinted = obj.__str__()
     self.assertEqual(objprinted,
                      "[State] ({}) {}".format(obj.id, obj.__dict__))