Exemplo n.º 1
0
 def test_update_no_id(self):
     """test update no id"""
     answer = "** instance id missing **"
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("update BaseModel")
         self.assertEqual(answer, f.getvalue().strip())
Exemplo n.º 2
0
 def test_empty(self):
     """ test emplty """
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("")
     self.assertEqual(f.getvalue(), "")
Exemplo n.º 3
0
 def test_quit(self):
     """ Test for quit """
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("quit")
     self.assertTrue(bool(f))
Exemplo n.º 4
0
 def test_do_EOF(self):
     """ test if command EOF exit the program """
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("EOF")
     self.assertTrue(f.getvalue() == "\n")
Exemplo n.º 5
0
    def test_do_update(self):
        """ test command
        'update <class name> <id> <attribute name> <attribute value>'
        and '<class name>.update(<id>, <attribute name>, <attribute value>)'
        and <class name>.update(<id>, <dictionary representation>) """

        for className, Cls in self.classes().items():
            u = Cls()

            """ 'update <class name> <id> <attr name> <attr value>' """
            with patch('sys.stdout', new=StringIO()) as f:
                HBNBCommand().onecmd('update {} {} string "text"'
                                     .format(className, u.id))
            self.assertTrue(u.string == "text")
            self.assertIsInstance(u.string, str)

            """ '<class name>.update(<id>, <attr name>, <attr value>)' """
            with patch('sys.stdout', new=StringIO()) as f:
                HBNBCommand().onecmd('{}.update("{}", string, "text")'
                                     .format(className, u.id))
            self.assertTrue(u.string == "text")
            self.assertIsInstance(u.string, str)

            """ <class name>.update(<id>, <dictionary representation>) """
            dic = {'first_name': "John", "age": 89}
            with patch('sys.stdout', new=StringIO()) as f:
                HBNBCommand().onecmd('{}.update("{}", {})'
                                     .format(className, u.id, dic))
            self.assertTrue(u.first_name == "John")
            self.assertTrue(u.age == 89)

            """ test if the value of type int is correctly stored """
            with patch('sys.stdout', new=StringIO()) as f:
                HBNBCommand().onecmd('update {} {} int 100'
                                     .format(className, u.id))
            self.assertTrue(u.int == 100)
            self.assertIsInstance(u.int, int)

            """ test if the value of type float is correctly stored """
            with patch('sys.stdout', new=StringIO()) as f:
                HBNBCommand().onecmd('update {} {} float 98.5'
                                     .format(className, u.id))
            self.assertTrue(u.float == 98.5)
            self.assertIsInstance(u.float, float)

            """ test if the value of type str is correctly stored
            (the value starts whith integers. ex: "98.5caraji")"""
            with patch('sys.stdout', new=StringIO()) as f:
                HBNBCommand().onecmd('update {} {} fake 98.5caraji'
                                     .format(className, u.id))
            self.assertTrue(u.fake == "98.5caraji")
            self.assertIsInstance(u.fake, str)

            """ test if the values sended with kwargs have the correct type """
            with patch('sys.stdout', new=StringIO()) as f:
                dic = {'first_name': "John", "age": 89}
                HBNBCommand().onecmd("{}.update({}, {})"
                                     .format(className, u.id, dic))
            self.assertTrue(u.first_name == "John")
            self.assertTrue(u.age == 89)

        """ test error message when <class name> is missing """
        with patch('sys.stdout', new=StringIO()) as f:
            HBNBCommand().onecmd("update")
        self.assertEqual(f.getvalue(), "** class name missing **\n")

        """ test error message when <class name> doesn't exist """
        with patch('sys.stdout', new=StringIO()) as f:
            HBNBCommand().onecmd("update NotExistClass")
        self.assertEqual(f.getvalue(), "** class doesn't exist **\n")

        """ test error message when <id> is missing """
        with patch('sys.stdout', new=StringIO()) as f:
            HBNBCommand().onecmd("update User")
        self.assertEqual(f.getvalue(), "** instance id missing **\n")

        """ test error message when no instance found """
        with patch('sys.stdout', new=StringIO()) as f:
            HBNBCommand().onecmd("update User 000")
        self.assertEqual(f.getvalue(), "** no instance found **\n")

        """ test error message when <attribute name> is missing """
        user = self.classes()['User']()
        with patch('sys.stdout', new=StringIO()) as f:
            HBNBCommand().onecmd("update User {}".format(user.id))
        self.assertEqual(f.getvalue(), "** attribute name missing **\n")

        """ test error message when <value> is missing """
        with patch('sys.stdout', new=StringIO()) as f:
            HBNBCommand().onecmd("update User {} attribute".format(user.id))
        self.assertEqual(f.getvalue(), "** value missing **\n")
Exemplo n.º 6
0
 def test_help(self):
     with patch("sys.stdout", new=StringIO()) as filer:
         self.assertFalse(HBNBCommand().onecmd("help"))
Exemplo n.º 7
0
 def setUp(cls):
     """Set up testing environment"""
     cls.consol = HBNBCommand()
Exemplo n.º 8
0
 def test_prompt(self):
     """test prompt"""
     self.assertEqual('(hbnb) ', HBNBCommand().prompt)
Exemplo n.º 9
0
 def create(self):
     '''
         Create HBNBCommand()
     '''
     return HBNBCommand()
Exemplo n.º 10
0
 def test_create(self):
     """test create"""
     answer = "** class name missing **"
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("create")
         self.assertEqual(answer, f.getvalue().strip())
Exemplo n.º 11
0
 def test_create_fake_class(self):
     """test create fakeClass"""
     answer = "** class doesn't exist **"
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("create fakeClass")
         self.assertEqual(answer, f.getvalue().strip())
Exemplo n.º 12
0
 def test_help_create(self):
     """test help create"""
     answer = "USAGE: create [class], creates an instance of given class"
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("help create")
         self.assertEqual(answer, f.getvalue().strip())
Exemplo n.º 13
0
 def test_cmdPrompt(self):
     """idk"""
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("help show")
Exemplo n.º 14
0
 def test_update_wrong_id(self):
     """test update wrong_id"""
     answer = "** attribute name missing **"
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("update BaseModel 1234")
         self.assertEqual(answer, f.getvalue().strip())
Exemplo n.º 15
0
 def test_quit(self):
     with patch("sys.stdout", new=StringIO()) as filer:
         self.assertTrue(HBNBCommand().onecmd("quit"))
Exemplo n.º 16
0
 def create(self, server=None):
     return HBNBCommand(stdin=self.mock_stdin, stdout=self.mock_stdout)
Exemplo n.º 17
0
 def test_EOF_exits(self):
     with patch("sys.stdout", new=StringIO()) as filer:
         self.assertTrue(HBNBCommand().onecmd("EOF"))
Exemplo n.º 18
0
 def test_quit(self):
     """ test quit function"""
     with patch("sys.stdout", new=StringIO) as out:
         self.assertTrue(HBNBCommand().onecmd("quit"))
Exemplo n.º 19
0
 def test_create(self):
     with patch("sys.stdout", new=StringIO()) as output:
         self.assertFalse(HBNBCommand().onecmd("create BaseModel"))
         self.assertLess(0, len(output.getvalue().strip()))
         testKey = "BaseModel.{}".format(output.getvalue().strip())
         self.assertIn(testKey, storage.all().keys())
Exemplo n.º 20
0
 def test_all(self):
     """ test all function"""
     string = "** class doesn't exist **"
     with patch("sys.stdout", new=StringIO()) as out:
         self.assertFalse(HBNBCommand().onecmd("all Model"))
         self.assertEqual(string, out.getvalue().strip())
Exemplo n.º 21
0
 def test_emptyline(self):
     """ empty line + ENTER shouldn’t execute anything """
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("\n")
     self.assertTrue(f.getvalue() == "")
Exemplo n.º 22
0
 def test_help_quit(self):
     """ test quit from help function"""
     string = "Quit command to exit the console"
     with patch("sys.stdout", new=StringIO()) as out:
         self.assertFalse(HBNBCommand().onecmd("help quit"))
         self.assertEqual(string, out.getvalue().strip())
Exemplo n.º 23
0
 def test_do_quit(self):
     """ test if command 'quit' exit the program """
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("quit")
     print(f.getvalue())
     self.assertTrue(f.getvalue() == "")
Exemplo n.º 24
0
 def test_help_EOF(self):
     """ test EOF from help"""
     string = "EOF command to exit the console"
     with patch("sys.stdout", new=StringIO()) as out:
         self.assertFalse(HBNBCommand().onecmd("help EOF"))
         self.assertEqual(string, out.getvalue().strip())
Exemplo n.º 25
0
 def test_unknown_sintax(self):
     """ test invalid commands """
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("helppp")
     self.assertEqual(f.getvalue(), "*** Unknown syntax: helppp\n")
Exemplo n.º 26
0
 def test_create(self):
     """test create from console"""
     string = "** class name missing **"
     with patch("sys.stdout", new=StringIO()) as out:
         self.assertFalse(HBNBCommand().onecmd("create"))
         self.assertEqual(string, out.getvalue().strip())
Exemplo n.º 27
0
 def test_tab(self):
     """ test tab """
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("\t")
     self.assertEqual(f.getvalue(), "")
Exemplo n.º 28
0
 def setUpClass(cls):
     '''set up before every test method'''
     cls.console1 = HBNBCommand()
Exemplo n.º 29
0
 def setUpClass(cls):
     """setup console class for test"""
     cls.consol = HBNBCommand()
Exemplo n.º 30
0
 def test_destroy_wrong_id(self):
     """test destroy wrong_id"""
     answer = "** no instance found **"
     with patch('sys.stdout', new=StringIO()) as f:
         HBNBCommand().onecmd("destroy BaseModel 1234")
         self.assertEqual(answer, f.getvalue().strip())