Пример #1
0
 def test_03_adding_extra_parameters(self):
     """Test for manually adding parameters"""
     b = BaseModel()
     b.first_name = "Ophelie"
     b.age = 24
     self.assertTrue(hasattr(b, "first_name"))
     self.assertTrue(hasattr(b, "age"))
     self.assertEqual(type(b.first_name), str)
     self.assertEqual(type(b.age), int)
Пример #2
0
    def testUpdateBaseModel(self):
        """Tests the update command"""
        b1 = BaseModel()
        b1.first_name = "foo"

        self.assertEqual(b1.first_name, "foo")
        with unittest.mock.patch("sys.stdout", new=StringIO()) as f:
            HBNBCommand().onecmd("update BaseModel {} first_name\
                                 \"bar\"".format(b1.id))

        self.assertEqual(b1.first_name, "bar")
Пример #3
0
 def test_04_to_dict(self):
     """Test to validate to_dict"""
     b = BaseModel()
     b.first_name = "Huy"
     b.age = 18
     d = b.to_dict()
     self.assertTrue('first_name' in d)
     self.assertTrue('age' in d)
     self.assertTrue('id' in d)
     self.assertTrue('created_at' in d)
     self.assertTrue('updated_at' in d)
     self.assertTrue('__class__' in d)
Пример #4
0
    def testUpdateExtraData(self):
        """Tests the update command with extra arguments"""
        b1 = BaseModel()
        b1.first_name = "Ben"
        b1.last_name = "Keener"

        with unittest.mock.patch("sys.stdout", new=StringIO()) as f:
            HBNBCommand().onecmd("update BaseModel {} first_name \"Drew\"\
                                 last_name \"foo\"".format(b1.id))
            self.assertEqual(f.getvalue().rstrip(), "")

        self.assertEqual(b1.first_name, "Drew")
        self.assertEqual(b1.last_name, "Keener")