How to use assertFalse method in autotest

Best Python code snippet using autotest_python

test_console.py

Source:test_console.py Github

copy

Full Screen

...23 def test_prompt_string(self):24 self.assertEqual("(hbnb) ", HBNBCommand.prompt)25 def test_empty_line(self):26 with patch("sys.stdout", new=StringIO()) as output:27 self.assertFalse(HBNBCommand().onecmd(""))28 self.assertEqual("", output.getvalue().strip())29class TestHBNBCommand_help(unittest.TestCase):30 """Unittests for testing help messages of the HBNB command interpreter."""31 def test_help_quit(self):32 h = "Quit command to exit the program."33 with patch("sys.stdout", new=StringIO()) as output:34 self.assertFalse(HBNBCommand().onecmd("help quit"))35 self.assertEqual(h, output.getvalue().strip())36 def test_help_create(self):37 h = ("Usage: create <class>\n "38 "Create a new class instance and print its id.")39 with patch("sys.stdout", new=StringIO()) as output:40 self.assertFalse(HBNBCommand().onecmd("help create"))41 self.assertEqual(h, output.getvalue().strip())42 def test_help_EOF(self):43 h = "EOF signal to exit the program."44 with patch("sys.stdout", new=StringIO()) as output:45 self.assertFalse(HBNBCommand().onecmd("help EOF"))46 self.assertEqual(h, output.getvalue().strip())47 def test_help_show(self):48 h = ("Usage: show <class> <id> or <class>.show(<id>)\n "49 "Display the string representation of a class instance of"50 " a given id.")51 with patch("sys.stdout", new=StringIO()) as output:52 self.assertFalse(HBNBCommand().onecmd("help show"))53 self.assertEqual(h, output.getvalue().strip())54 def test_help_destroy(self):55 h = ("Usage: destroy <class> <id> or <class>.destroy(<id>)\n "56 "Delete a class instance of a given id.")57 with patch("sys.stdout", new=StringIO()) as output:58 self.assertFalse(HBNBCommand().onecmd("help destroy"))59 self.assertEqual(h, output.getvalue().strip())60 def test_help_all(self):61 h = ("Usage: all or all <class> or <class>.all()\n "62 "Display string representations of all instances of a given class"63 ".\n If no class is specified, displays all instantiated "64 "objects.")65 with patch("sys.stdout", new=StringIO()) as output:66 self.assertFalse(HBNBCommand().onecmd("help all"))67 self.assertEqual(h, output.getvalue().strip())68 def test_help_count(self):69 h = ("Usage: count <class> or <class>.count()\n "70 "Retrieve the number of instances of a given class.")71 with patch("sys.stdout", new=StringIO()) as output:72 self.assertFalse(HBNBCommand().onecmd("help count"))73 self.assertEqual(h, output.getvalue().strip())74 def test_help_update(self):75 h = ("Usage: update <class> <id> <attribute_name> <attribute_value> or"76 "\n <class>.update(<id>, <attribute_name>, <attribute_value"77 ">) or\n <class>.update(<id>, <dictionary>)\n "78 "Update a class instance of a given id by adding or updating\n "79 " a given attribute key/value pair or dictionary.")80 with patch("sys.stdout", new=StringIO()) as output:81 self.assertFalse(HBNBCommand().onecmd("help update"))82 self.assertEqual(h, output.getvalue().strip())83 def test_help(self):84 h = ("Documented commands (type help <topic>):\n"85 "========================================\n"86 "EOF all count create destroy help quit show update")87 with patch("sys.stdout", new=StringIO()) as output:88 self.assertFalse(HBNBCommand().onecmd("help"))89 self.assertEqual(h, output.getvalue().strip())90class TestHBNBCommand_exit(unittest.TestCase):91 """Unittests for testing exiting from the HBNB command interpreter."""92 def test_quit_exits(self):93 with patch("sys.stdout", new=StringIO()) as output:94 self.assertTrue(HBNBCommand().onecmd("quit"))95 def test_EOF_exits(self):96 with patch("sys.stdout", new=StringIO()) as output:97 self.assertTrue(HBNBCommand().onecmd("EOF"))98class TestHBNBCommand_create(unittest.TestCase):99 """Unittests for testing create from the HBNB command interpreter."""100 @classmethod101 def setUp(self):102 try:103 os.rename("file.json", "tmp")104 except IOError:105 pass106 FileStorage.__objects = {}107 @classmethod108 def tearDown(self):109 try:110 os.remove("file.json")111 except IOError:112 pass113 try:114 os.rename("tmp", "file.json")115 except IOError:116 pass117 def test_create_missing_class(self):118 correct = "** class name missing **"119 with patch("sys.stdout", new=StringIO()) as output:120 self.assertFalse(HBNBCommand().onecmd("create"))121 self.assertEqual(correct, output.getvalue().strip())122 def test_create_invalid_class(self):123 correct = "** class doesn't exist **"124 with patch("sys.stdout", new=StringIO()) as output:125 self.assertFalse(HBNBCommand().onecmd("create MyModel"))126 self.assertEqual(correct, output.getvalue().strip())127 def test_create_invalid_syntax(self):128 correct = "*** Unknown syntax: MyModel.create()"129 with patch("sys.stdout", new=StringIO()) as output:130 self.assertFalse(HBNBCommand().onecmd("MyModel.create()"))131 self.assertEqual(correct, output.getvalue().strip())132 correct = "*** Unknown syntax: BaseModel.create()"133 with patch("sys.stdout", new=StringIO()) as output:134 self.assertFalse(HBNBCommand().onecmd("BaseModel.create()"))135 self.assertEqual(correct, output.getvalue().strip())136 def test_create_object(self):137 with patch("sys.stdout", new=StringIO()) as output:138 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))139 self.assertLess(0, len(output.getvalue().strip()))140 testKey = "BaseModel.{}".format(output.getvalue().strip())141 self.assertIn(testKey, storage.all().keys())142 with patch("sys.stdout", new=StringIO()) as output:143 self.assertFalse(HBNBCommand().onecmd("create User"))144 self.assertLess(0, len(output.getvalue().strip()))145 testKey = "User.{}".format(output.getvalue().strip())146 self.assertIn(testKey, storage.all().keys())147 with patch("sys.stdout", new=StringIO()) as output:148 self.assertFalse(HBNBCommand().onecmd("create State"))149 self.assertLess(0, len(output.getvalue().strip()))150 testKey = "State.{}".format(output.getvalue().strip())151 self.assertIn(testKey, storage.all().keys())152 with patch("sys.stdout", new=StringIO()) as output:153 self.assertFalse(HBNBCommand().onecmd("create City"))154 self.assertLess(0, len(output.getvalue().strip()))155 testKey = "City.{}".format(output.getvalue().strip())156 self.assertIn(testKey, storage.all().keys())157 with patch("sys.stdout", new=StringIO()) as output:158 self.assertFalse(HBNBCommand().onecmd("create Amenity"))159 self.assertLess(0, len(output.getvalue().strip()))160 testKey = "Amenity.{}".format(output.getvalue().strip())161 self.assertIn(testKey, storage.all().keys())162 with patch("sys.stdout", new=StringIO()) as output:163 self.assertFalse(HBNBCommand().onecmd("create Place"))164 self.assertLess(0, len(output.getvalue().strip()))165 testKey = "Place.{}".format(output.getvalue().strip())166 self.assertIn(testKey, storage.all().keys())167 with patch("sys.stdout", new=StringIO()) as output:168 self.assertFalse(HBNBCommand().onecmd("create Review"))169 self.assertLess(0, len(output.getvalue().strip()))170 testKey = "Review.{}".format(output.getvalue().strip())171 self.assertIn(testKey, storage.all().keys())172class TestHBNBCommand_show(unittest.TestCase):173 """Unittests for testing show from the HBNB command interpreter"""174 @classmethod175 def setUp(self):176 try:177 os.rename("file.json", "tmp")178 except IOError:179 pass180 FileStorage.__objects = {}181 @classmethod182 def tearDown(self):183 try:184 os.remove("file.json")185 except IOError:186 pass187 try:188 os.rename("tmp", "file.json")189 except IOError:190 pass191 def test_show_missing_class(self):192 correct = "** class name missing **"193 with patch("sys.stdout", new=StringIO()) as output:194 self.assertFalse(HBNBCommand().onecmd("show"))195 self.assertEqual(correct, output.getvalue().strip())196 with patch("sys.stdout", new=StringIO()) as output:197 self.assertFalse(HBNBCommand().onecmd(".show()"))198 self.assertEqual(correct, output.getvalue().strip())199 def test_show_invalid_class(self):200 correct = "** class doesn't exist **"201 with patch("sys.stdout", new=StringIO()) as output:202 self.assertFalse(HBNBCommand().onecmd("show MyModel"))203 self.assertEqual(correct, output.getvalue().strip())204 with patch("sys.stdout", new=StringIO()) as output:205 self.assertFalse(HBNBCommand().onecmd("MyModel.show()"))206 self.assertEqual(correct, output.getvalue().strip())207 def test_show_missing_id_space_notation(self):208 correct = "** instance id missing **"209 with patch("sys.stdout", new=StringIO()) as output:210 self.assertFalse(HBNBCommand().onecmd("show BaseModel"))211 self.assertEqual(correct, output.getvalue().strip())212 with patch("sys.stdout", new=StringIO()) as output:213 self.assertFalse(HBNBCommand().onecmd("show User"))214 self.assertEqual(correct, output.getvalue().strip())215 with patch("sys.stdout", new=StringIO()) as output:216 self.assertFalse(HBNBCommand().onecmd("show State"))217 self.assertEqual(correct, output.getvalue().strip())218 with patch("sys.stdout", new=StringIO()) as output:219 self.assertFalse(HBNBCommand().onecmd("show City"))220 self.assertEqual(correct, output.getvalue().strip())221 with patch("sys.stdout", new=StringIO()) as output:222 self.assertFalse(HBNBCommand().onecmd("show Amenity"))223 self.assertEqual(correct, output.getvalue().strip())224 with patch("sys.stdout", new=StringIO()) as output:225 self.assertFalse(HBNBCommand().onecmd("show Place"))226 self.assertEqual(correct, output.getvalue().strip())227 with patch("sys.stdout", new=StringIO()) as output:228 self.assertFalse(HBNBCommand().onecmd("show Review"))229 self.assertEqual(correct, output.getvalue().strip())230 def test_show_missing_id_dot_notation(self):231 correct = "** instance id missing **"232 with patch("sys.stdout", new=StringIO()) as output:233 self.assertFalse(HBNBCommand().onecmd("BaseModel.show()"))234 self.assertEqual(correct, output.getvalue().strip())235 with patch("sys.stdout", new=StringIO()) as output:236 self.assertFalse(HBNBCommand().onecmd("User.show()"))237 self.assertEqual(correct, output.getvalue().strip())238 with patch("sys.stdout", new=StringIO()) as output:239 self.assertFalse(HBNBCommand().onecmd("State.show()"))240 self.assertEqual(correct, output.getvalue().strip())241 with patch("sys.stdout", new=StringIO()) as output:242 self.assertFalse(HBNBCommand().onecmd("City.show()"))243 self.assertEqual(correct, output.getvalue().strip())244 with patch("sys.stdout", new=StringIO()) as output:245 self.assertFalse(HBNBCommand().onecmd("Amenity.show()"))246 self.assertEqual(correct, output.getvalue().strip())247 with patch("sys.stdout", new=StringIO()) as output:248 self.assertFalse(HBNBCommand().onecmd("Place.show()"))249 self.assertEqual(correct, output.getvalue().strip())250 with patch("sys.stdout", new=StringIO()) as output:251 self.assertFalse(HBNBCommand().onecmd("Review.show()"))252 self.assertEqual(correct, output.getvalue().strip())253 def test_show_no_instance_found_space_notation(self):254 correct = "** no instance found **"255 with patch("sys.stdout", new=StringIO()) as output:256 self.assertFalse(HBNBCommand().onecmd("show BaseModel 1"))257 self.assertEqual(correct, output.getvalue().strip())258 with patch("sys.stdout", new=StringIO()) as output:259 self.assertFalse(HBNBCommand().onecmd("show User 1"))260 self.assertEqual(correct, output.getvalue().strip())261 with patch("sys.stdout", new=StringIO()) as output:262 self.assertFalse(HBNBCommand().onecmd("show State 1"))263 self.assertEqual(correct, output.getvalue().strip())264 with patch("sys.stdout", new=StringIO()) as output:265 self.assertFalse(HBNBCommand().onecmd("show City 1"))266 self.assertEqual(correct, output.getvalue().strip())267 with patch("sys.stdout", new=StringIO()) as output:268 self.assertFalse(HBNBCommand().onecmd("show Amenity 1"))269 self.assertEqual(correct, output.getvalue().strip())270 with patch("sys.stdout", new=StringIO()) as output:271 self.assertFalse(HBNBCommand().onecmd("show Place 1"))272 self.assertEqual(correct, output.getvalue().strip())273 with patch("sys.stdout", new=StringIO()) as output:274 self.assertFalse(HBNBCommand().onecmd("show Review 1"))275 self.assertEqual(correct, output.getvalue().strip())276 def test_show_no_instance_found_dot_notation(self):277 correct = "** no instance found **"278 with patch("sys.stdout", new=StringIO()) as output:279 self.assertFalse(HBNBCommand().onecmd("BaseModel.show(1)"))280 self.assertEqual(correct, output.getvalue().strip())281 with patch("sys.stdout", new=StringIO()) as output:282 self.assertFalse(HBNBCommand().onecmd("User.show(1)"))283 self.assertEqual(correct, output.getvalue().strip())284 with patch("sys.stdout", new=StringIO()) as output:285 self.assertFalse(HBNBCommand().onecmd("State.show(1)"))286 self.assertEqual(correct, output.getvalue().strip())287 with patch("sys.stdout", new=StringIO()) as output:288 self.assertFalse(HBNBCommand().onecmd("City.show(1)"))289 self.assertEqual(correct, output.getvalue().strip())290 with patch("sys.stdout", new=StringIO()) as output:291 self.assertFalse(HBNBCommand().onecmd("Amenity.show(1)"))292 self.assertEqual(correct, output.getvalue().strip())293 with patch("sys.stdout", new=StringIO()) as output:294 self.assertFalse(HBNBCommand().onecmd("Place.show(1)"))295 self.assertEqual(correct, output.getvalue().strip())296 with patch("sys.stdout", new=StringIO()) as output:297 self.assertFalse(HBNBCommand().onecmd("Review.show(1)"))298 self.assertEqual(correct, output.getvalue().strip())299 def test_show_objects_space_notation(self):300 with patch("sys.stdout", new=StringIO()) as output:301 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))302 testID = output.getvalue().strip()303 with patch("sys.stdout", new=StringIO()) as output:304 obj = storage.all()["BaseModel.{}".format(testID)]305 command = "show BaseModel {}".format(testID)306 self.assertFalse(HBNBCommand().onecmd(command))307 self.assertEqual(obj.__str__(), output.getvalue().strip())308 with patch("sys.stdout", new=StringIO()) as output:309 self.assertFalse(HBNBCommand().onecmd("create User"))310 testID = output.getvalue().strip()311 with patch("sys.stdout", new=StringIO()) as output:312 obj = storage.all()["User.{}".format(testID)]313 command = "show User {}".format(testID)314 self.assertFalse(HBNBCommand().onecmd(command))315 self.assertEqual(obj.__str__(), output.getvalue().strip())316 with patch("sys.stdout", new=StringIO()) as output:317 self.assertFalse(HBNBCommand().onecmd("create State"))318 testID = output.getvalue().strip()319 with patch("sys.stdout", new=StringIO()) as output:320 obj = storage.all()["State.{}".format(testID)]321 command = "show State {}".format(testID)322 self.assertFalse(HBNBCommand().onecmd(command))323 self.assertEqual(obj.__str__(), output.getvalue().strip())324 with patch("sys.stdout", new=StringIO()) as output:325 self.assertFalse(HBNBCommand().onecmd("create Place"))326 testID = output.getvalue().strip()327 with patch("sys.stdout", new=StringIO()) as output:328 obj = storage.all()["Place.{}".format(testID)]329 command = "show Place {}".format(testID)330 self.assertFalse(HBNBCommand().onecmd(command))331 self.assertEqual(obj.__str__(), output.getvalue().strip())332 with patch("sys.stdout", new=StringIO()) as output:333 self.assertFalse(HBNBCommand().onecmd("create City"))334 testID = output.getvalue().strip()335 with patch("sys.stdout", new=StringIO()) as output:336 obj = storage.all()["City.{}".format(testID)]337 command = "show City {}".format(testID)338 self.assertFalse(HBNBCommand().onecmd(command))339 self.assertEqual(obj.__str__(), output.getvalue().strip())340 with patch("sys.stdout", new=StringIO()) as output:341 self.assertFalse(HBNBCommand().onecmd("create Amenity"))342 testID = output.getvalue().strip()343 with patch("sys.stdout", new=StringIO()) as output:344 obj = storage.all()["Amenity.{}".format(testID)]345 command = "show Amenity {}".format(testID)346 self.assertFalse(HBNBCommand().onecmd(command))347 self.assertEqual(obj.__str__(), output.getvalue().strip())348 with patch("sys.stdout", new=StringIO()) as output:349 self.assertFalse(HBNBCommand().onecmd("create Review"))350 testID = output.getvalue().strip()351 with patch("sys.stdout", new=StringIO()) as output:352 obj = storage.all()["Review.{}".format(testID)]353 command = "show Review {}".format(testID)354 self.assertFalse(HBNBCommand().onecmd(command))355 self.assertEqual(obj.__str__(), output.getvalue().strip())356 def test_show_objects_space_notation(self):357 with patch("sys.stdout", new=StringIO()) as output:358 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))359 testID = output.getvalue().strip()360 with patch("sys.stdout", new=StringIO()) as output:361 obj = storage.all()["BaseModel.{}".format(testID)]362 command = "BaseModel.show({})".format(testID)363 self.assertFalse(HBNBCommand().onecmd(command))364 self.assertEqual(obj.__str__(), output.getvalue().strip())365 with patch("sys.stdout", new=StringIO()) as output:366 self.assertFalse(HBNBCommand().onecmd("create User"))367 testID = output.getvalue().strip()368 with patch("sys.stdout", new=StringIO()) as output:369 obj = storage.all()["User.{}".format(testID)]370 command = "User.show({})".format(testID)371 self.assertFalse(HBNBCommand().onecmd(command))372 self.assertEqual(obj.__str__(), output.getvalue().strip())373 with patch("sys.stdout", new=StringIO()) as output:374 self.assertFalse(HBNBCommand().onecmd("create State"))375 testID = output.getvalue().strip()376 with patch("sys.stdout", new=StringIO()) as output:377 obj = storage.all()["State.{}".format(testID)]378 command = "State.show({})".format(testID)379 self.assertFalse(HBNBCommand().onecmd(command))380 self.assertEqual(obj.__str__(), output.getvalue().strip())381 with patch("sys.stdout", new=StringIO()) as output:382 self.assertFalse(HBNBCommand().onecmd("create Place"))383 testID = output.getvalue().strip()384 with patch("sys.stdout", new=StringIO()) as output:385 obj = storage.all()["Place.{}".format(testID)]386 command = "Place.show({})".format(testID)387 self.assertFalse(HBNBCommand().onecmd(command))388 self.assertEqual(obj.__str__(), output.getvalue().strip())389 with patch("sys.stdout", new=StringIO()) as output:390 self.assertFalse(HBNBCommand().onecmd("create City"))391 testID = output.getvalue().strip()392 with patch("sys.stdout", new=StringIO()) as output:393 obj = storage.all()["City.{}".format(testID)]394 command = "City.show({})".format(testID)395 self.assertFalse(HBNBCommand().onecmd(command))396 self.assertEqual(obj.__str__(), output.getvalue().strip())397 with patch("sys.stdout", new=StringIO()) as output:398 self.assertFalse(HBNBCommand().onecmd("create Amenity"))399 testID = output.getvalue().strip()400 with patch("sys.stdout", new=StringIO()) as output:401 obj = storage.all()["Amenity.{}".format(testID)]402 command = "Amenity.show({})".format(testID)403 self.assertFalse(HBNBCommand().onecmd(command))404 self.assertEqual(obj.__str__(), output.getvalue().strip())405 with patch("sys.stdout", new=StringIO()) as output:406 self.assertFalse(HBNBCommand().onecmd("create Review"))407 testID = output.getvalue().strip()408 with patch("sys.stdout", new=StringIO()) as output:409 obj = storage.all()["Review.{}".format(testID)]410 command = "Review.show({})".format(testID)411 self.assertFalse(HBNBCommand().onecmd(command))412 self.assertEqual(obj.__str__(), output.getvalue().strip())413class TestHBNBCommand_destroy(unittest.TestCase):414 """Unittests for testing destroy from the HBNB command interpreter."""415 @classmethod416 def setUp(self):417 try:418 os.rename("file.json", "tmp")419 except IOError:420 pass421 FileStorage.__objects = {}422 @classmethod423 def tearDown(self):424 try:425 os.remove("file.json")426 except IOError:427 pass428 try:429 os.rename("tmp", "file.json")430 except IOError:431 pass432 storage.reload()433 def test_destroy_missing_class(self):434 correct = "** class name missing **"435 with patch("sys.stdout", new=StringIO()) as output:436 self.assertFalse(HBNBCommand().onecmd("destroy"))437 self.assertEqual(correct, output.getvalue().strip())438 with patch("sys.stdout", new=StringIO()) as output:439 self.assertFalse(HBNBCommand().onecmd(".destroy()"))440 self.assertEqual(correct, output.getvalue().strip())441 def test_destroy_invalid_class(self):442 correct = "** class doesn't exist **"443 with patch("sys.stdout", new=StringIO()) as output:444 self.assertFalse(HBNBCommand().onecmd("destroy MyModel"))445 self.assertEqual(correct, output.getvalue().strip())446 with patch("sys.stdout", new=StringIO()) as output:447 self.assertFalse(HBNBCommand().onecmd("MyModel.destroy()"))448 self.assertEqual(correct, output.getvalue().strip())449 def test_destroy_id_missing_space_notation(self):450 correct = "** instance id missing **"451 with patch("sys.stdout", new=StringIO()) as output:452 self.assertFalse(HBNBCommand().onecmd("destroy BaseModel"))453 self.assertEqual(correct, output.getvalue().strip())454 with patch("sys.stdout", new=StringIO()) as output:455 self.assertFalse(HBNBCommand().onecmd("destroy User"))456 self.assertEqual(correct, output.getvalue().strip())457 with patch("sys.stdout", new=StringIO()) as output:458 self.assertFalse(HBNBCommand().onecmd("destroy State"))459 self.assertEqual(correct, output.getvalue().strip())460 with patch("sys.stdout", new=StringIO()) as output:461 self.assertFalse(HBNBCommand().onecmd("destroy City"))462 self.assertEqual(correct, output.getvalue().strip())463 with patch("sys.stdout", new=StringIO()) as output:464 self.assertFalse(HBNBCommand().onecmd("destroy Amenity"))465 self.assertEqual(correct, output.getvalue().strip())466 with patch("sys.stdout", new=StringIO()) as output:467 self.assertFalse(HBNBCommand().onecmd("destroy Place"))468 self.assertEqual(correct, output.getvalue().strip())469 with patch("sys.stdout", new=StringIO()) as output:470 self.assertFalse(HBNBCommand().onecmd("destroy Review"))471 self.assertEqual(correct, output.getvalue().strip())472 def test_destroy_id_missing_dot_notation(self):473 correct = "** instance id missing **"474 with patch("sys.stdout", new=StringIO()) as output:475 self.assertFalse(HBNBCommand().onecmd("BaseModel.destroy()"))476 self.assertEqual(correct, output.getvalue().strip())477 with patch("sys.stdout", new=StringIO()) as output:478 self.assertFalse(HBNBCommand().onecmd("User.destroy()"))479 self.assertEqual(correct, output.getvalue().strip())480 with patch("sys.stdout", new=StringIO()) as output:481 self.assertFalse(HBNBCommand().onecmd("State.destroy()"))482 self.assertEqual(correct, output.getvalue().strip())483 with patch("sys.stdout", new=StringIO()) as output:484 self.assertFalse(HBNBCommand().onecmd("City.destroy()"))485 self.assertEqual(correct, output.getvalue().strip())486 with patch("sys.stdout", new=StringIO()) as output:487 self.assertFalse(HBNBCommand().onecmd("Amenity.destroy()"))488 self.assertEqual(correct, output.getvalue().strip())489 with patch("sys.stdout", new=StringIO()) as output:490 self.assertFalse(HBNBCommand().onecmd("Place.destroy()"))491 self.assertEqual(correct, output.getvalue().strip())492 with patch("sys.stdout", new=StringIO()) as output:493 self.assertFalse(HBNBCommand().onecmd("Review.destroy()"))494 self.assertEqual(correct, output.getvalue().strip())495 def test_destroy_invalid_id_space_notation(self):496 correct = "** no instance found **"497 with patch("sys.stdout", new=StringIO()) as output:498 self.assertFalse(HBNBCommand().onecmd("destroy BaseModel 1"))499 self.assertEqual(correct, output.getvalue().strip())500 with patch("sys.stdout", new=StringIO()) as output:501 self.assertFalse(HBNBCommand().onecmd("destroy User 1"))502 self.assertEqual(correct, output.getvalue().strip())503 with patch("sys.stdout", new=StringIO()) as output:504 self.assertFalse(HBNBCommand().onecmd("destroy State 1"))505 self.assertEqual(correct, output.getvalue().strip())506 with patch("sys.stdout", new=StringIO()) as output:507 self.assertFalse(HBNBCommand().onecmd("destroy City 1"))508 self.assertEqual(correct, output.getvalue().strip())509 with patch("sys.stdout", new=StringIO()) as output:510 self.assertFalse(HBNBCommand().onecmd("destroy Amenity 1"))511 self.assertEqual(correct, output.getvalue().strip())512 with patch("sys.stdout", new=StringIO()) as output:513 self.assertFalse(HBNBCommand().onecmd("destroy Place 1"))514 self.assertEqual(correct, output.getvalue().strip())515 with patch("sys.stdout", new=StringIO()) as output:516 self.assertFalse(HBNBCommand().onecmd("destroy Review 1"))517 self.assertEqual(correct, output.getvalue().strip())518 def test_destroy_invalid_id_dot_notation(self):519 correct = "** no instance found **"520 with patch("sys.stdout", new=StringIO()) as output:521 self.assertFalse(HBNBCommand().onecmd("BaseModel.destroy(1)"))522 self.assertEqual(correct, output.getvalue().strip())523 with patch("sys.stdout", new=StringIO()) as output:524 self.assertFalse(HBNBCommand().onecmd("User.destroy(1)"))525 self.assertEqual(correct, output.getvalue().strip())526 with patch("sys.stdout", new=StringIO()) as output:527 self.assertFalse(HBNBCommand().onecmd("State.destroy(1)"))528 self.assertEqual(correct, output.getvalue().strip())529 with patch("sys.stdout", new=StringIO()) as output:530 self.assertFalse(HBNBCommand().onecmd("City.destroy(1)"))531 self.assertEqual(correct, output.getvalue().strip())532 with patch("sys.stdout", new=StringIO()) as output:533 self.assertFalse(HBNBCommand().onecmd("Amenity.destroy(1)"))534 self.assertEqual(correct, output.getvalue().strip())535 with patch("sys.stdout", new=StringIO()) as output:536 self.assertFalse(HBNBCommand().onecmd("Place.destroy(1)"))537 self.assertEqual(correct, output.getvalue().strip())538 with patch("sys.stdout", new=StringIO()) as output:539 self.assertFalse(HBNBCommand().onecmd("Review.destroy(1)"))540 self.assertEqual(correct, output.getvalue().strip())541 def test_destroy_objects_space_notation(self):542 with patch("sys.stdout", new=StringIO()) as output:543 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))544 testID = output.getvalue().strip()545 with patch("sys.stdout", new=StringIO()) as output:546 obj = storage.all()["BaseModel.{}".format(testID)]547 command = "destroy BaseModel {}".format(testID)548 self.assertFalse(HBNBCommand().onecmd(command))549 self.assertNotIn(obj, storage.all())550 with patch("sys.stdout", new=StringIO()) as output:551 self.assertFalse(HBNBCommand().onecmd("create User"))552 testID = output.getvalue().strip()553 with patch("sys.stdout", new=StringIO()) as output:554 obj = storage.all()["User.{}".format(testID)]555 command = "show User {}".format(testID)556 self.assertFalse(HBNBCommand().onecmd(command))557 self.assertNotIn(obj, storage.all())558 with patch("sys.stdout", new=StringIO()) as output:559 self.assertFalse(HBNBCommand().onecmd("create State"))560 testID = output.getvalue().strip()561 with patch("sys.stdout", new=StringIO()) as output:562 obj = storage.all()["State.{}".format(testID)]563 command = "show State {}".format(testID)564 self.assertFalse(HBNBCommand().onecmd(command))565 self.assertNotIn(obj, storage.all())566 with patch("sys.stdout", new=StringIO()) as output:567 self.assertFalse(HBNBCommand().onecmd("create Place"))568 testID = output.getvalue().strip()569 with patch("sys.stdout", new=StringIO()) as output:570 obj = storage.all()["Place.{}".format(testID)]571 command = "show Place {}".format(testID)572 self.assertFalse(HBNBCommand().onecmd(command))573 self.assertNotIn(obj, storage.all())574 with patch("sys.stdout", new=StringIO()) as output:575 self.assertFalse(HBNBCommand().onecmd("create City"))576 testID = output.getvalue().strip()577 with patch("sys.stdout", new=StringIO()) as output:578 obj = storage.all()["City.{}".format(testID)]579 command = "show City {}".format(testID)580 self.assertFalse(HBNBCommand().onecmd(command))581 self.assertNotIn(obj, storage.all())582 with patch("sys.stdout", new=StringIO()) as output:583 self.assertFalse(HBNBCommand().onecmd("create Amenity"))584 testID = output.getvalue().strip()585 with patch("sys.stdout", new=StringIO()) as output:586 obj = storage.all()["Amenity.{}".format(testID)]587 command = "show Amenity {}".format(testID)588 self.assertFalse(HBNBCommand().onecmd(command))589 self.assertNotIn(obj, storage.all())590 with patch("sys.stdout", new=StringIO()) as output:591 self.assertFalse(HBNBCommand().onecmd("create Review"))592 testID = output.getvalue().strip()593 with patch("sys.stdout", new=StringIO()) as output:594 obj = storage.all()["Review.{}".format(testID)]595 command = "show Review {}".format(testID)596 self.assertFalse(HBNBCommand().onecmd(command))597 self.assertNotIn(obj, storage.all())598 def test_destroy_objects_dot_notation(self):599 with patch("sys.stdout", new=StringIO()) as output:600 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))601 testID = output.getvalue().strip()602 with patch("sys.stdout", new=StringIO()) as output:603 obj = storage.all()["BaseModel.{}".format(testID)]604 command = "BaseModel.destroy({})".format(testID)605 self.assertFalse(HBNBCommand().onecmd(command))606 self.assertNotIn(obj, storage.all())607 with patch("sys.stdout", new=StringIO()) as output:608 self.assertFalse(HBNBCommand().onecmd("create User"))609 testID = output.getvalue().strip()610 with patch("sys.stdout", new=StringIO()) as output:611 obj = storage.all()["User.{}".format(testID)]612 command = "User.destroy({})".format(testID)613 self.assertFalse(HBNBCommand().onecmd(command))614 self.assertNotIn(obj, storage.all())615 with patch("sys.stdout", new=StringIO()) as output:616 self.assertFalse(HBNBCommand().onecmd("create State"))617 testID = output.getvalue().strip()618 with patch("sys.stdout", new=StringIO()) as output:619 obj = storage.all()["State.{}".format(testID)]620 command = "State.destroy({})".format(testID)621 self.assertFalse(HBNBCommand().onecmd(command))622 self.assertNotIn(obj, storage.all())623 with patch("sys.stdout", new=StringIO()) as output:624 self.assertFalse(HBNBCommand().onecmd("create Place"))625 testID = output.getvalue().strip()626 with patch("sys.stdout", new=StringIO()) as output:627 obj = storage.all()["Place.{}".format(testID)]628 command = "Place.destroy({})".format(testID)629 self.assertFalse(HBNBCommand().onecmd(command))630 self.assertNotIn(obj, storage.all())631 with patch("sys.stdout", new=StringIO()) as output:632 self.assertFalse(HBNBCommand().onecmd("create City"))633 testID = output.getvalue().strip()634 with patch("sys.stdout", new=StringIO()) as output:635 obj = storage.all()["City.{}".format(testID)]636 command = "City.destroy({})".format(testID)637 self.assertFalse(HBNBCommand().onecmd(command))638 self.assertNotIn(obj, storage.all())639 with patch("sys.stdout", new=StringIO()) as output:640 self.assertFalse(HBNBCommand().onecmd("create Amenity"))641 testID = output.getvalue().strip()642 with patch("sys.stdout", new=StringIO()) as output:643 obj = storage.all()["Amenity.{}".format(testID)]644 command = "Amenity.destroy({})".format(testID)645 self.assertFalse(HBNBCommand().onecmd(command))646 self.assertNotIn(obj, storage.all())647 with patch("sys.stdout", new=StringIO()) as output:648 self.assertFalse(HBNBCommand().onecmd("create Review"))649 testID = output.getvalue().strip()650 with patch("sys.stdout", new=StringIO()) as output:651 obj = storage.all()["Review.{}".format(testID)]652 command = "Review.destory({})".format(testID)653 self.assertFalse(HBNBCommand().onecmd(command))654 self.assertNotIn(obj, storage.all())655class TestHBNBCommand_all(unittest.TestCase):656 """Unittests for testing all of the HBNB command interpreter."""657 @classmethod658 def setUp(self):659 try:660 os.rename("file.json", "tmp")661 except IOError:662 pass663 FileStorage.__objects = {}664 @classmethod665 def tearDown(self):666 try:667 os.remove("file.json")668 except IOError:669 pass670 try:671 os.rename("tmp", "file.json")672 except IOError:673 pass674 def test_all_invalid_class(self):675 correct = "** class doesn't exist **"676 with patch("sys.stdout", new=StringIO()) as output:677 self.assertFalse(HBNBCommand().onecmd("all MyModel"))678 self.assertEqual(correct, output.getvalue().strip())679 with patch("sys.stdout", new=StringIO()) as output:680 self.assertFalse(HBNBCommand().onecmd("MyModel.all()"))681 self.assertEqual(correct, output.getvalue().strip())682 def test_all_objects_space_notation(self):683 with patch("sys.stdout", new=StringIO()) as output:684 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))685 self.assertFalse(HBNBCommand().onecmd("create User"))686 self.assertFalse(HBNBCommand().onecmd("create State"))687 self.assertFalse(HBNBCommand().onecmd("create Place"))688 self.assertFalse(HBNBCommand().onecmd("create City"))689 self.assertFalse(HBNBCommand().onecmd("create Amenity"))690 self.assertFalse(HBNBCommand().onecmd("create Review"))691 with patch("sys.stdout", new=StringIO()) as output:692 self.assertFalse(HBNBCommand().onecmd("all"))693 self.assertIn("BaseModel", output.getvalue().strip())694 self.assertIn("User", output.getvalue().strip())695 self.assertIn("State", output.getvalue().strip())696 self.assertIn("Place", output.getvalue().strip())697 self.assertIn("City", output.getvalue().strip())698 self.assertIn("Amenity", output.getvalue().strip())699 self.assertIn("Review", output.getvalue().strip())700 def test_all_objects_dot_notation(self):701 with patch("sys.stdout", new=StringIO()) as output:702 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))703 self.assertFalse(HBNBCommand().onecmd("create User"))704 self.assertFalse(HBNBCommand().onecmd("create State"))705 self.assertFalse(HBNBCommand().onecmd("create Place"))706 self.assertFalse(HBNBCommand().onecmd("create City"))707 self.assertFalse(HBNBCommand().onecmd("create Amenity"))708 self.assertFalse(HBNBCommand().onecmd("create Review"))709 with patch("sys.stdout", new=StringIO()) as output:710 self.assertFalse(HBNBCommand().onecmd(".all()"))711 self.assertIn("BaseModel", output.getvalue().strip())712 self.assertIn("User", output.getvalue().strip())713 self.assertIn("State", output.getvalue().strip())714 self.assertIn("Place", output.getvalue().strip())715 self.assertIn("City", output.getvalue().strip())716 self.assertIn("Amenity", output.getvalue().strip())717 self.assertIn("Review", output.getvalue().strip())718 def test_all_single_object_space_notation(self):719 with patch("sys.stdout", new=StringIO()) as output:720 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))721 self.assertFalse(HBNBCommand().onecmd("create User"))722 self.assertFalse(HBNBCommand().onecmd("create State"))723 self.assertFalse(HBNBCommand().onecmd("create Place"))724 self.assertFalse(HBNBCommand().onecmd("create City"))725 self.assertFalse(HBNBCommand().onecmd("create Amenity"))726 self.assertFalse(HBNBCommand().onecmd("create Review"))727 with patch("sys.stdout", new=StringIO()) as output:728 self.assertFalse(HBNBCommand().onecmd("all BaseModel"))729 self.assertIn("BaseModel", output.getvalue().strip())730 self.assertNotIn("User", output.getvalue().strip())731 with patch("sys.stdout", new=StringIO()) as output:732 self.assertFalse(HBNBCommand().onecmd("all User"))733 self.assertIn("User", output.getvalue().strip())734 self.assertNotIn("BaseModel", output.getvalue().strip())735 with patch("sys.stdout", new=StringIO()) as output:736 self.assertFalse(HBNBCommand().onecmd("all State"))737 self.assertIn("State", output.getvalue().strip())738 self.assertNotIn("BaseModel", output.getvalue().strip())739 with patch("sys.stdout", new=StringIO()) as output:740 self.assertFalse(HBNBCommand().onecmd("all City"))741 self.assertIn("City", output.getvalue().strip())742 self.assertNotIn("BaseModel", output.getvalue().strip())743 with patch("sys.stdout", new=StringIO()) as output:744 self.assertFalse(HBNBCommand().onecmd("all Amenity"))745 self.assertIn("Amenity", output.getvalue().strip())746 self.assertNotIn("BaseModel", output.getvalue().strip())747 with patch("sys.stdout", new=StringIO()) as output:748 self.assertFalse(HBNBCommand().onecmd("all Place"))749 self.assertIn("Place", output.getvalue().strip())750 self.assertNotIn("BaseModel", output.getvalue().strip())751 with patch("sys.stdout", new=StringIO()) as output:752 self.assertFalse(HBNBCommand().onecmd("all Review"))753 self.assertIn("Review", output.getvalue().strip())754 self.assertNotIn("BaseModel", output.getvalue().strip())755 def test_all_single_object_dot_notation(self):756 with patch("sys.stdout", new=StringIO()) as output:757 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))758 self.assertFalse(HBNBCommand().onecmd("create User"))759 self.assertFalse(HBNBCommand().onecmd("create State"))760 self.assertFalse(HBNBCommand().onecmd("create Place"))761 self.assertFalse(HBNBCommand().onecmd("create City"))762 self.assertFalse(HBNBCommand().onecmd("create Amenity"))763 self.assertFalse(HBNBCommand().onecmd("create Review"))764 with patch("sys.stdout", new=StringIO()) as output:765 self.assertFalse(HBNBCommand().onecmd("BaseModel.all()"))766 self.assertIn("BaseModel", output.getvalue().strip())767 self.assertNotIn("User", output.getvalue().strip())768 with patch("sys.stdout", new=StringIO()) as output:769 self.assertFalse(HBNBCommand().onecmd("User.all()"))770 self.assertIn("User", output.getvalue().strip())771 self.assertNotIn("BaseModel", output.getvalue().strip())772 with patch("sys.stdout", new=StringIO()) as output:773 self.assertFalse(HBNBCommand().onecmd("State.all()"))774 self.assertIn("State", output.getvalue().strip())775 self.assertNotIn("BaseModel", output.getvalue().strip())776 with patch("sys.stdout", new=StringIO()) as output:777 self.assertFalse(HBNBCommand().onecmd("City.all()"))778 self.assertIn("City", output.getvalue().strip())779 self.assertNotIn("BaseModel", output.getvalue().strip())780 with patch("sys.stdout", new=StringIO()) as output:781 self.assertFalse(HBNBCommand().onecmd("Amenity.all()"))782 self.assertIn("Amenity", output.getvalue().strip())783 self.assertNotIn("BaseModel", output.getvalue().strip())784 with patch("sys.stdout", new=StringIO()) as output:785 self.assertFalse(HBNBCommand().onecmd("Place.all()"))786 self.assertIn("Place", output.getvalue().strip())787 self.assertNotIn("BaseModel", output.getvalue().strip())788 with patch("sys.stdout", new=StringIO()) as output:789 self.assertFalse(HBNBCommand().onecmd("Review.all()"))790 self.assertIn("Review", output.getvalue().strip())791 self.assertNotIn("BaseModel", output.getvalue().strip())792class TestHBNBCommand_update(unittest.TestCase):793 """Unittests for testing update from the HBNB command interpreter."""794 @classmethod795 def setUp(self):796 try:797 os.rename("file.json", "tmp")798 except IOError:799 pass800 FileStorage.__objects = {}801 @classmethod802 def tearDown(self):803 try:804 os.remove("file.json")805 except IOError:806 pass807 try:808 os.rename("tmp", "file.json")809 except IOError:810 pass811 def test_update_missing_class(self):812 correct = "** class name missing **"813 with patch("sys.stdout", new=StringIO()) as output:814 self.assertFalse(HBNBCommand().onecmd("update"))815 self.assertEqual(correct, output.getvalue().strip())816 with patch("sys.stdout", new=StringIO()) as output:817 self.assertFalse(HBNBCommand().onecmd(".update()"))818 self.assertEqual(correct, output.getvalue().strip())819 def test_update_invalid_class(self):820 correct = "** class doesn't exist **"821 with patch("sys.stdout", new=StringIO()) as output:822 self.assertFalse(HBNBCommand().onecmd("update MyModel"))823 self.assertEqual(correct, output.getvalue().strip())824 with patch("sys.stdout", new=StringIO()) as output:825 self.assertFalse(HBNBCommand().onecmd("MyModel.update()"))826 self.assertEqual(correct, output.getvalue().strip())827 def test_update_missing_id_space_notation(self):828 correct = "** instance id missing **"829 with patch("sys.stdout", new=StringIO()) as output:830 self.assertFalse(HBNBCommand().onecmd("update BaseModel"))831 self.assertEqual(correct, output.getvalue().strip())832 with patch("sys.stdout", new=StringIO()) as output:833 self.assertFalse(HBNBCommand().onecmd("update User"))834 self.assertEqual(correct, output.getvalue().strip())835 with patch("sys.stdout", new=StringIO()) as output:836 self.assertFalse(HBNBCommand().onecmd("update State"))837 self.assertEqual(correct, output.getvalue().strip())838 with patch("sys.stdout", new=StringIO()) as output:839 self.assertFalse(HBNBCommand().onecmd("update City"))840 self.assertEqual(correct, output.getvalue().strip())841 with patch("sys.stdout", new=StringIO()) as output:842 self.assertFalse(HBNBCommand().onecmd("update Amenity"))843 self.assertEqual(correct, output.getvalue().strip())844 with patch("sys.stdout", new=StringIO()) as output:845 self.assertFalse(HBNBCommand().onecmd("update Place"))846 self.assertEqual(correct, output.getvalue().strip())847 with patch("sys.stdout", new=StringIO()) as output:848 self.assertFalse(HBNBCommand().onecmd("update Review"))849 self.assertEqual(correct, output.getvalue().strip())850 def test_update_missing_id_dot_notation(self):851 correct = "** instance id missing **"852 with patch("sys.stdout", new=StringIO()) as output:853 self.assertFalse(HBNBCommand().onecmd("BaseModel.update()"))854 self.assertEqual(correct, output.getvalue().strip())855 with patch("sys.stdout", new=StringIO()) as output:856 self.assertFalse(HBNBCommand().onecmd("User.update()"))857 self.assertEqual(correct, output.getvalue().strip())858 with patch("sys.stdout", new=StringIO()) as output:859 self.assertFalse(HBNBCommand().onecmd("State.update()"))860 self.assertEqual(correct, output.getvalue().strip())861 with patch("sys.stdout", new=StringIO()) as output:862 self.assertFalse(HBNBCommand().onecmd("City.update()"))863 self.assertEqual(correct, output.getvalue().strip())864 with patch("sys.stdout", new=StringIO()) as output:865 self.assertFalse(HBNBCommand().onecmd("Amenity.update()"))866 self.assertEqual(correct, output.getvalue().strip())867 with patch("sys.stdout", new=StringIO()) as output:868 self.assertFalse(HBNBCommand().onecmd("Place.update()"))869 self.assertEqual(correct, output.getvalue().strip())870 with patch("sys.stdout", new=StringIO()) as output:871 self.assertFalse(HBNBCommand().onecmd("Review.update()"))872 self.assertEqual(correct, output.getvalue().strip())873 def test_update_invalid_id_space_notation(self):874 correct = "** no instance found **"875 with patch("sys.stdout", new=StringIO()) as output:876 self.assertFalse(HBNBCommand().onecmd("update BaseModel 1"))877 self.assertEqual(correct, output.getvalue().strip())878 with patch("sys.stdout", new=StringIO()) as output:879 self.assertFalse(HBNBCommand().onecmd("update User 1"))880 self.assertEqual(correct, output.getvalue().strip())881 with patch("sys.stdout", new=StringIO()) as output:882 self.assertFalse(HBNBCommand().onecmd("update State 1"))883 self.assertEqual(correct, output.getvalue().strip())884 with patch("sys.stdout", new=StringIO()) as output:885 self.assertFalse(HBNBCommand().onecmd("update City 1"))886 self.assertEqual(correct, output.getvalue().strip())887 with patch("sys.stdout", new=StringIO()) as output:888 self.assertFalse(HBNBCommand().onecmd("update Amenity 1"))889 self.assertEqual(correct, output.getvalue().strip())890 with patch("sys.stdout", new=StringIO()) as output:891 self.assertFalse(HBNBCommand().onecmd("update Place 1"))892 self.assertEqual(correct, output.getvalue().strip())893 with patch("sys.stdout", new=StringIO()) as output:894 self.assertFalse(HBNBCommand().onecmd("update Review 1"))895 self.assertEqual(correct, output.getvalue().strip())896 def test_update_invalid_id_dot_notation(self):897 correct = "** no instance found **"898 with patch("sys.stdout", new=StringIO()) as output:899 self.assertFalse(HBNBCommand().onecmd("BaseModel.update(1)"))900 self.assertEqual(correct, output.getvalue().strip())901 with patch("sys.stdout", new=StringIO()) as output:902 self.assertFalse(HBNBCommand().onecmd("User.update(1)"))903 self.assertEqual(correct, output.getvalue().strip())904 with patch("sys.stdout", new=StringIO()) as output:905 self.assertFalse(HBNBCommand().onecmd("State.update(1)"))906 self.assertEqual(correct, output.getvalue().strip())907 with patch("sys.stdout", new=StringIO()) as output:908 self.assertFalse(HBNBCommand().onecmd("City.update(1)"))909 self.assertEqual(correct, output.getvalue().strip())910 with patch("sys.stdout", new=StringIO()) as output:911 self.assertFalse(HBNBCommand().onecmd("Amenity.update(1)"))912 self.assertEqual(correct, output.getvalue().strip())913 with patch("sys.stdout", new=StringIO()) as output:914 self.assertFalse(HBNBCommand().onecmd("Place.update(1)"))915 self.assertEqual(correct, output.getvalue().strip())916 with patch("sys.stdout", new=StringIO()) as output:917 self.assertFalse(HBNBCommand().onecmd("Review.update(1)"))918 self.assertEqual(correct, output.getvalue().strip())919 def test_update_missing_attr_name_space_notation(self):920 correct = "** attribute name missing **"921 with patch("sys.stdout", new=StringIO()) as output:922 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))923 testId = output.getvalue().strip()924 testCmd = "update BaseModel {}".format(testId)925 with patch("sys.stdout", new=StringIO()) as output:926 self.assertFalse(HBNBCommand().onecmd(testCmd))927 self.assertEqual(correct, output.getvalue().strip())928 with patch("sys.stdout", new=StringIO()) as output:929 self.assertFalse(HBNBCommand().onecmd("create User"))930 testId = output.getvalue().strip()931 testCmd = "update User {}".format(testId)932 with patch("sys.stdout", new=StringIO()) as output:933 self.assertFalse(HBNBCommand().onecmd(testCmd))934 self.assertEqual(correct, output.getvalue().strip())935 with patch("sys.stdout", new=StringIO()) as output:936 self.assertFalse(HBNBCommand().onecmd("create State"))937 testId = output.getvalue().strip()938 testCmd = "update State {}".format(testId)939 with patch("sys.stdout", new=StringIO()) as output:940 self.assertFalse(HBNBCommand().onecmd(testCmd))941 self.assertEqual(correct, output.getvalue().strip())942 with patch("sys.stdout", new=StringIO()) as output:943 self.assertFalse(HBNBCommand().onecmd("create City"))944 testId = output.getvalue().strip()945 testCmd = "update City {}".format(testId)946 with patch("sys.stdout", new=StringIO()) as output:947 self.assertFalse(HBNBCommand().onecmd(testCmd))948 self.assertEqual(correct, output.getvalue().strip())949 with patch("sys.stdout", new=StringIO()) as output:950 self.assertFalse(HBNBCommand().onecmd("create Amenity"))951 testId = output.getvalue().strip()952 testCmd = "update Amenity {}".format(testId)953 with patch("sys.stdout", new=StringIO()) as output:954 self.assertFalse(HBNBCommand().onecmd(testCmd))955 self.assertEqual(correct, output.getvalue().strip())956 with patch("sys.stdout", new=StringIO()) as output:957 self.assertFalse(HBNBCommand().onecmd("create Place"))958 testId = output.getvalue().strip()959 testCmd = "update Place {}".format(testId)960 with patch("sys.stdout", new=StringIO()) as output:961 self.assertFalse(HBNBCommand().onecmd(testCmd))962 self.assertEqual(correct, output.getvalue().strip())963 def test_update_missing_attr_name_dot_notation(self):964 correct = "** attribute name missing **"965 with patch("sys.stdout", new=StringIO()) as output:966 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))967 testId = output.getvalue().strip()968 testCmd = "BaseModel.update({})".format(testId)969 with patch("sys.stdout", new=StringIO()) as output:970 self.assertFalse(HBNBCommand().onecmd(testCmd))971 self.assertEqual(correct, output.getvalue().strip())972 with patch("sys.stdout", new=StringIO()) as output:973 self.assertFalse(HBNBCommand().onecmd("create User"))974 testId = output.getvalue().strip()975 testCmd = "User.update({})".format(testId)976 with patch("sys.stdout", new=StringIO()) as output:977 self.assertFalse(HBNBCommand().onecmd(testCmd))978 self.assertEqual(correct, output.getvalue().strip())979 with patch("sys.stdout", new=StringIO()) as output:980 self.assertFalse(HBNBCommand().onecmd("create State"))981 testId = output.getvalue().strip()982 testCmd = "State.update({})".format(testId)983 with patch("sys.stdout", new=StringIO()) as output:984 self.assertFalse(HBNBCommand().onecmd(testCmd))985 self.assertEqual(correct, output.getvalue().strip())986 with patch("sys.stdout", new=StringIO()) as output:987 self.assertFalse(HBNBCommand().onecmd("create City"))988 testId = output.getvalue().strip()989 testCmd = "City.update({})".format(testId)990 with patch("sys.stdout", new=StringIO()) as output:991 self.assertFalse(HBNBCommand().onecmd(testCmd))992 self.assertEqual(correct, output.getvalue().strip())993 with patch("sys.stdout", new=StringIO()) as output:994 self.assertFalse(HBNBCommand().onecmd("create Amenity"))995 testId = output.getvalue().strip()996 testCmd = "Amenity.update({})".format(testId)997 with patch("sys.stdout", new=StringIO()) as output:998 self.assertFalse(HBNBCommand().onecmd(testCmd))999 self.assertEqual(correct, output.getvalue().strip())1000 with patch("sys.stdout", new=StringIO()) as output:1001 self.assertFalse(HBNBCommand().onecmd("create Place"))1002 testId = output.getvalue().strip()1003 testCmd = "Place.update({})".format(testId)1004 with patch("sys.stdout", new=StringIO()) as output:1005 self.assertFalse(HBNBCommand().onecmd(testCmd))1006 self.assertEqual(correct, output.getvalue().strip())1007 def test_update_missing_attr_value_space_notation(self):1008 correct = "** value missing **"1009 with patch("sys.stdout", new=StringIO()) as output:1010 HBNBCommand().onecmd("create BaseModel")1011 testId = output.getvalue().strip()1012 with patch("sys.stdout", new=StringIO()) as output:1013 testCmd = "update BaseModel {} attr_name".format(testId)1014 self.assertFalse(HBNBCommand().onecmd(testCmd))1015 self.assertEqual(correct, output.getvalue().strip())1016 with patch("sys.stdout", new=StringIO()) as output:1017 HBNBCommand().onecmd("create User")1018 testId = output.getvalue().strip()1019 with patch("sys.stdout", new=StringIO()) as output:1020 testCmd = "update User {} attr_name".format(testId)1021 self.assertFalse(HBNBCommand().onecmd(testCmd))1022 self.assertEqual(correct, output.getvalue().strip())1023 with patch("sys.stdout", new=StringIO()) as output:1024 HBNBCommand().onecmd("create State")1025 testId = output.getvalue().strip()1026 with patch("sys.stdout", new=StringIO()) as output:1027 testCmd = "update State {} attr_name".format(testId)1028 self.assertFalse(HBNBCommand().onecmd(testCmd))1029 self.assertEqual(correct, output.getvalue().strip())1030 with patch("sys.stdout", new=StringIO()) as output:1031 HBNBCommand().onecmd("create City")1032 testId = output.getvalue().strip()1033 with patch("sys.stdout", new=StringIO()) as output:1034 testCmd = "update City {} attr_name".format(testId)1035 self.assertFalse(HBNBCommand().onecmd(testCmd))1036 self.assertEqual(correct, output.getvalue().strip())1037 with patch("sys.stdout", new=StringIO()) as output:1038 HBNBCommand().onecmd("create Amenity")1039 testId = output.getvalue().strip()1040 with patch("sys.stdout", new=StringIO()) as output:1041 testCmd = "update Amenity {} attr_name".format(testId)1042 self.assertFalse(HBNBCommand().onecmd(testCmd))1043 self.assertEqual(correct, output.getvalue().strip())1044 with patch("sys.stdout", new=StringIO()) as output:1045 HBNBCommand().onecmd("create Place")1046 testId = output.getvalue().strip()1047 with patch("sys.stdout", new=StringIO()) as output:1048 testCmd = "update Place {} attr_name".format(testId)1049 self.assertFalse(HBNBCommand().onecmd(testCmd))1050 self.assertEqual(correct, output.getvalue().strip())1051 with patch("sys.stdout", new=StringIO()) as output:1052 HBNBCommand().onecmd("create Review")1053 testId = output.getvalue().strip()1054 with patch("sys.stdout", new=StringIO()) as output:1055 testCmd = "update Review {} attr_name".format(testId)1056 self.assertFalse(HBNBCommand().onecmd(testCmd))1057 self.assertEqual(correct, output.getvalue().strip())1058 def test_update_missing_attr_value_dot_notation(self):1059 correct = "** value missing **"1060 with patch("sys.stdout", new=StringIO()) as output:1061 HBNBCommand().onecmd("create BaseModel")1062 testId = output.getvalue().strip()1063 with patch("sys.stdout", new=StringIO()) as output:1064 testCmd = "BaseModel.update({}, attr_name)".format(testId)1065 self.assertFalse(HBNBCommand().onecmd(testCmd))1066 self.assertEqual(correct, output.getvalue().strip())1067 with patch("sys.stdout", new=StringIO()) as output:1068 HBNBCommand().onecmd("create User")1069 testId = output.getvalue().strip()1070 with patch("sys.stdout", new=StringIO()) as output:1071 testCmd = "User.update({}, attr_name)".format(testId)1072 self.assertFalse(HBNBCommand().onecmd(testCmd))1073 self.assertEqual(correct, output.getvalue().strip())1074 with patch("sys.stdout", new=StringIO()) as output:1075 HBNBCommand().onecmd("create State")1076 testId = output.getvalue().strip()1077 with patch("sys.stdout", new=StringIO()) as output:1078 testCmd = "State.update({}, attr_name)".format(testId)1079 self.assertFalse(HBNBCommand().onecmd(testCmd))1080 self.assertEqual(correct, output.getvalue().strip())1081 with patch("sys.stdout", new=StringIO()) as output:1082 HBNBCommand().onecmd("create City")1083 testId = output.getvalue().strip()1084 with patch("sys.stdout", new=StringIO()) as output:1085 testCmd = "City.update({}, attr_name)".format(testId)1086 self.assertFalse(HBNBCommand().onecmd(testCmd))1087 self.assertEqual(correct, output.getvalue().strip())1088 with patch("sys.stdout", new=StringIO()) as output:1089 HBNBCommand().onecmd("create Amenity")1090 testId = output.getvalue().strip()1091 with patch("sys.stdout", new=StringIO()) as output:1092 testCmd = "Amenity.update({}, attr_name)".format(testId)1093 self.assertFalse(HBNBCommand().onecmd(testCmd))1094 self.assertEqual(correct, output.getvalue().strip())1095 with patch("sys.stdout", new=StringIO()) as output:1096 HBNBCommand().onecmd("create Place")1097 testId = output.getvalue().strip()1098 with patch("sys.stdout", new=StringIO()) as output:1099 testCmd = "Place.update({}, attr_name)".format(testId)1100 self.assertFalse(HBNBCommand().onecmd(testCmd))1101 self.assertEqual(correct, output.getvalue().strip())1102 with patch("sys.stdout", new=StringIO()) as output:1103 HBNBCommand().onecmd("create Review")1104 testId = output.getvalue().strip()1105 with patch("sys.stdout", new=StringIO()) as output:1106 testCmd = "Review.update({}, attr_name)".format(testId)1107 self.assertFalse(HBNBCommand().onecmd(testCmd))1108 self.assertEqual(correct, output.getvalue().strip())1109 def test_update_valid_string_attr_space_notation(self):1110 with patch("sys.stdout", new=StringIO()) as output:1111 HBNBCommand().onecmd("create BaseModel")1112 testId = output.getvalue().strip()1113 testCmd = "update BaseModel {} attr_name 'attr_value'".format(testId)1114 self.assertFalse(HBNBCommand().onecmd(testCmd))1115 test_dict = storage.all()["BaseModel.{}".format(testId)].__dict__1116 self.assertEqual("attr_value", test_dict["attr_name"])1117 with patch("sys.stdout", new=StringIO()) as output:1118 HBNBCommand().onecmd("create User")1119 testId = output.getvalue().strip()1120 testCmd = "update User {} attr_name 'attr_value'".format(testId)1121 self.assertFalse(HBNBCommand().onecmd(testCmd))1122 test_dict = storage.all()["User.{}".format(testId)].__dict__1123 self.assertEqual("attr_value", test_dict["attr_name"])1124 with patch("sys.stdout", new=StringIO()) as output:1125 HBNBCommand().onecmd("create State")1126 testId = output.getvalue().strip()1127 testCmd = "update State {} attr_name 'attr_value'".format(testId)1128 self.assertFalse(HBNBCommand().onecmd(testCmd))1129 test_dict = storage.all()["State.{}".format(testId)].__dict__1130 self.assertEqual("attr_value", test_dict["attr_name"])1131 with patch("sys.stdout", new=StringIO()) as output:1132 HBNBCommand().onecmd("create City")1133 testId = output.getvalue().strip()1134 testCmd = "update City {} attr_name 'attr_value'".format(testId)1135 self.assertFalse(HBNBCommand().onecmd(testCmd))1136 test_dict = storage.all()["City.{}".format(testId)].__dict__1137 self.assertEqual("attr_value", test_dict["attr_name"])1138 with patch("sys.stdout", new=StringIO()) as output:1139 HBNBCommand().onecmd("create Place")1140 testId = output.getvalue().strip()1141 testCmd = "update Place {} attr_name 'attr_value'".format(testId)1142 self.assertFalse(HBNBCommand().onecmd(testCmd))1143 test_dict = storage.all()["Place.{}".format(testId)].__dict__1144 self.assertEqual("attr_value", test_dict["attr_name"])1145 with patch("sys.stdout", new=StringIO()) as output:1146 HBNBCommand().onecmd("create Amenity")1147 testId = output.getvalue().strip()1148 testCmd = "update Amenity {} attr_name 'attr_value'".format(testId)1149 self.assertFalse(HBNBCommand().onecmd(testCmd))1150 test_dict = storage.all()["Amenity.{}".format(testId)].__dict__1151 self.assertEqual("attr_value", test_dict["attr_name"])1152 with patch("sys.stdout", new=StringIO()) as output:1153 HBNBCommand().onecmd("create Review")1154 testId = output.getvalue().strip()1155 testCmd = "update Review {} attr_name 'attr_value'".format(testId)1156 self.assertFalse(HBNBCommand().onecmd(testCmd))1157 test_dict = storage.all()["Review.{}".format(testId)].__dict__1158 self.assertTrue("attr_value", test_dict["attr_name"])1159 def test_update_valid_string_attr_dot_notation(self):1160 with patch("sys.stdout", new=StringIO()) as output:1161 HBNBCommand().onecmd("create BaseModel")1162 tId = output.getvalue().strip()1163 testCmd = "BaseModel.update({}, attr_name, 'attr_value')".format(tId)1164 self.assertFalse(HBNBCommand().onecmd(testCmd))1165 test_dict = storage.all()["BaseModel.{}".format(tId)].__dict__1166 self.assertEqual("attr_value", test_dict["attr_name"])1167 with patch("sys.stdout", new=StringIO()) as output:1168 HBNBCommand().onecmd("create User")1169 tId = output.getvalue().strip()1170 testCmd = "User.update({}, attr_name, 'attr_value')".format(tId)1171 self.assertFalse(HBNBCommand().onecmd(testCmd))1172 test_dict = storage.all()["User.{}".format(tId)].__dict__1173 self.assertEqual("attr_value", test_dict["attr_name"])1174 with patch("sys.stdout", new=StringIO()) as output:1175 HBNBCommand().onecmd("create State")1176 tId = output.getvalue().strip()1177 testCmd = "State.update({}, attr_name, 'attr_value')".format(tId)1178 self.assertFalse(HBNBCommand().onecmd(testCmd))1179 test_dict = storage.all()["State.{}".format(tId)].__dict__1180 self.assertEqual("attr_value", test_dict["attr_name"])1181 with patch("sys.stdout", new=StringIO()) as output:1182 HBNBCommand().onecmd("create City")1183 tId = output.getvalue().strip()1184 testCmd = "City.update({}, attr_name, 'attr_value')".format(tId)1185 self.assertFalse(HBNBCommand().onecmd(testCmd))1186 test_dict = storage.all()["City.{}".format(tId)].__dict__1187 self.assertEqual("attr_value", test_dict["attr_name"])1188 with patch("sys.stdout", new=StringIO()) as output:1189 HBNBCommand().onecmd("create Place")1190 tId = output.getvalue().strip()1191 testCmd = "Place.update({}, attr_name, 'attr_value')".format(tId)1192 self.assertFalse(HBNBCommand().onecmd(testCmd))1193 test_dict = storage.all()["Place.{}".format(tId)].__dict__1194 self.assertEqual("attr_value", test_dict["attr_name"])1195 with patch("sys.stdout", new=StringIO()) as output:1196 HBNBCommand().onecmd("create Amenity")1197 tId = output.getvalue().strip()1198 testCmd = "Amenity.update({}, attr_name, 'attr_value')".format(tId)1199 self.assertFalse(HBNBCommand().onecmd(testCmd))1200 test_dict = storage.all()["Amenity.{}".format(tId)].__dict__1201 self.assertEqual("attr_value", test_dict["attr_name"])1202 with patch("sys.stdout", new=StringIO()) as output:1203 HBNBCommand().onecmd("create Review")1204 tId = output.getvalue().strip()1205 testCmd = "Review.update({}, attr_name, 'attr_value')".format(tId)1206 self.assertFalse(HBNBCommand().onecmd(testCmd))1207 test_dict = storage.all()["Review.{}".format(tId)].__dict__1208 self.assertEqual("attr_value", test_dict["attr_name"])1209 def test_update_valid_int_attr_space_notation(self):1210 with patch("sys.stdout", new=StringIO()) as output:1211 HBNBCommand().onecmd("create Place")1212 testId = output.getvalue().strip()1213 testCmd = "update Place {} max_guest 98".format(testId)1214 self.assertFalse(HBNBCommand().onecmd(testCmd))1215 test_dict = storage.all()["Place.{}".format(testId)].__dict__1216 self.assertEqual(98, test_dict["max_guest"])1217 def test_update_valid_int_attr_dot_notation(self):1218 with patch("sys.stdout", new=StringIO()) as output:1219 HBNBCommand().onecmd("create Place")1220 tId = output.getvalue().strip()1221 testCmd = "Place.update({}, max_guest, 98)".format(tId)1222 self.assertFalse(HBNBCommand().onecmd(testCmd))1223 test_dict = storage.all()["Place.{}".format(tId)].__dict__1224 self.assertEqual(98, test_dict["max_guest"])1225 def test_update_valid_float_attr_space_notation(self):1226 with patch("sys.stdout", new=StringIO()) as output:1227 HBNBCommand().onecmd("create Place")1228 testId = output.getvalue().strip()1229 testCmd = "update Place {} latitude 7.2".format(testId)1230 self.assertFalse(HBNBCommand().onecmd(testCmd))1231 test_dict = storage.all()["Place.{}".format(testId)].__dict__1232 self.assertEqual(7.2, test_dict["latitude"])1233 def test_update_valid_float_attr_dot_notation(self):1234 with patch("sys.stdout", new=StringIO()) as output:1235 HBNBCommand().onecmd("create Place")1236 tId = output.getvalue().strip()1237 testCmd = "Place.update({}, latitude, 7.2)".format(tId)1238 self.assertFalse(HBNBCommand().onecmd(testCmd))1239 test_dict = storage.all()["Place.{}".format(tId)].__dict__1240 self.assertEqual(7.2, test_dict["latitude"])1241 def test_update_valid_dictionary_space_notation(self):1242 with patch("sys.stdout", new=StringIO()) as output:1243 HBNBCommand().onecmd("create BaseModel")1244 testId = output.getvalue().strip()1245 testCmd = "update BaseModel {} ".format(testId)1246 testCmd += "{'attr_name': 'attr_value'}"1247 HBNBCommand().onecmd(testCmd)1248 test_dict = storage.all()["BaseModel.{}".format(testId)].__dict__1249 self.assertEqual("attr_value", test_dict["attr_name"])1250 with patch("sys.stdout", new=StringIO()) as output:1251 HBNBCommand().onecmd("create User")1252 testId = output.getvalue().strip()1253 testCmd = "update User {} ".format(testId)1254 testCmd += "{'attr_name': 'attr_value'}"1255 HBNBCommand().onecmd(testCmd)1256 test_dict = storage.all()["User.{}".format(testId)].__dict__1257 self.assertEqual("attr_value", test_dict["attr_name"])1258 with patch("sys.stdout", new=StringIO()) as output:1259 HBNBCommand().onecmd("create State")1260 testId = output.getvalue().strip()1261 testCmd = "update State {} ".format(testId)1262 testCmd += "{'attr_name': 'attr_value'}"1263 HBNBCommand().onecmd(testCmd)1264 test_dict = storage.all()["State.{}".format(testId)].__dict__1265 self.assertEqual("attr_value", test_dict["attr_name"])1266 with patch("sys.stdout", new=StringIO()) as output:1267 HBNBCommand().onecmd("create City")1268 testId = output.getvalue().strip()1269 testCmd = "update City {} ".format(testId)1270 testCmd += "{'attr_name': 'attr_value'}"1271 HBNBCommand().onecmd(testCmd)1272 test_dict = storage.all()["City.{}".format(testId)].__dict__1273 self.assertEqual("attr_value", test_dict["attr_name"])1274 with patch("sys.stdout", new=StringIO()) as output:1275 HBNBCommand().onecmd("create Place")1276 testId = output.getvalue().strip()1277 testCmd = "update Place {} ".format(testId)1278 testCmd += "{'attr_name': 'attr_value'}"1279 HBNBCommand().onecmd(testCmd)1280 test_dict = storage.all()["Place.{}".format(testId)].__dict__1281 self.assertEqual("attr_value", test_dict["attr_name"])1282 with patch("sys.stdout", new=StringIO()) as output:1283 HBNBCommand().onecmd("create Amenity")1284 testId = output.getvalue().strip()1285 testCmd = "update Amenity {} ".format(testId)1286 testCmd += "{'attr_name': 'attr_value'}"1287 HBNBCommand().onecmd(testCmd)1288 test_dict = storage.all()["Amenity.{}".format(testId)].__dict__1289 self.assertEqual("attr_value", test_dict["attr_name"])1290 with patch("sys.stdout", new=StringIO()) as output:1291 HBNBCommand().onecmd("create Review")1292 testId = output.getvalue().strip()1293 testCmd = "update Review {} ".format(testId)1294 testCmd += "{'attr_name': 'attr_value'}"1295 HBNBCommand().onecmd(testCmd)1296 test_dict = storage.all()["Review.{}".format(testId)].__dict__1297 self.assertEqual("attr_value", test_dict["attr_name"])1298 def test_update_valid_dictionary_dot_notation(self):1299 with patch("sys.stdout", new=StringIO()) as output:1300 HBNBCommand().onecmd("create BaseModel")1301 testId = output.getvalue().strip()1302 testCmd = "BaseModel.update({}".format(testId)1303 testCmd += "{'attr_name': 'attr_value'})"1304 HBNBCommand().onecmd(testCmd)1305 test_dict = storage.all()["BaseModel.{}".format(testId)].__dict__1306 self.assertEqual("attr_value", test_dict["attr_name"])1307 with patch("sys.stdout", new=StringIO()) as output:1308 HBNBCommand().onecmd("create User")1309 testId = output.getvalue().strip()1310 testCmd = "User.update({}, ".format(testId)1311 testCmd += "{'attr_name': 'attr_value'})"1312 HBNBCommand().onecmd(testCmd)1313 test_dict = storage.all()["User.{}".format(testId)].__dict__1314 self.assertEqual("attr_value", test_dict["attr_name"])1315 with patch("sys.stdout", new=StringIO()) as output:1316 HBNBCommand().onecmd("create State")1317 testId = output.getvalue().strip()1318 testCmd = "State.update({}, ".format(testId)1319 testCmd += "{'attr_name': 'attr_value'})"1320 HBNBCommand().onecmd(testCmd)1321 test_dict = storage.all()["State.{}".format(testId)].__dict__1322 self.assertEqual("attr_value", test_dict["attr_name"])1323 with patch("sys.stdout", new=StringIO()) as output:1324 HBNBCommand().onecmd("create City")1325 testId = output.getvalue().strip()1326 testCmd = "City.update({}, ".format(testId)1327 testCmd += "{'attr_name': 'attr_value'})"1328 HBNBCommand().onecmd(testCmd)1329 test_dict = storage.all()["City.{}".format(testId)].__dict__1330 self.assertEqual("attr_value", test_dict["attr_name"])1331 with patch("sys.stdout", new=StringIO()) as output:1332 HBNBCommand().onecmd("create Place")1333 testId = output.getvalue().strip()1334 testCmd = "Place.update({}, ".format(testId)1335 testCmd += "{'attr_name': 'attr_value'})"1336 HBNBCommand().onecmd(testCmd)1337 test_dict = storage.all()["Place.{}".format(testId)].__dict__1338 self.assertEqual("attr_value", test_dict["attr_name"])1339 with patch("sys.stdout", new=StringIO()) as output:1340 HBNBCommand().onecmd("create Amenity")1341 testId = output.getvalue().strip()1342 testCmd = "Amenity.update({}, ".format(testId)1343 testCmd += "{'attr_name': 'attr_value'})"1344 HBNBCommand().onecmd(testCmd)1345 test_dict = storage.all()["Amenity.{}".format(testId)].__dict__1346 self.assertEqual("attr_value", test_dict["attr_name"])1347 with patch("sys.stdout", new=StringIO()) as output:1348 HBNBCommand().onecmd("create Review")1349 testId = output.getvalue().strip()1350 testCmd = "Review.update({}, ".format(testId)1351 testCmd += "{'attr_name': 'attr_value'})"1352 HBNBCommand().onecmd(testCmd)1353 test_dict = storage.all()["Review.{}".format(testId)].__dict__1354 self.assertEqual("attr_value", test_dict["attr_name"])1355 def test_update_valid_dictionary_with_int_space_notation(self):1356 with patch("sys.stdout", new=StringIO()) as output:1357 HBNBCommand().onecmd("create Place")1358 testId = output.getvalue().strip()1359 testCmd = "update Place {} ".format(testId)1360 testCmd += "{'max_guest': 98})"1361 HBNBCommand().onecmd(testCmd)1362 test_dict = storage.all()["Place.{}".format(testId)].__dict__1363 self.assertEqual(98, test_dict["max_guest"])1364 def test_update_valid_dictionary_with_int_dot_notation(self):1365 with patch("sys.stdout", new=StringIO()) as output:1366 HBNBCommand().onecmd("create Place")1367 testId = output.getvalue().strip()1368 testCmd = "Place.update({}, ".format(testId)1369 testCmd += "{'max_guest': 98})"1370 HBNBCommand().onecmd(testCmd)1371 test_dict = storage.all()["Place.{}".format(testId)].__dict__1372 self.assertEqual(98, test_dict["max_guest"])1373 def test_update_valid_dictionary_with_float_space_notation(self):1374 with patch("sys.stdout", new=StringIO()) as output:1375 HBNBCommand().onecmd("create Place")1376 testId = output.getvalue().strip()1377 testCmd = "update Place {} ".format(testId)1378 testCmd += "{'latitude': 9.8})"1379 HBNBCommand().onecmd(testCmd)1380 test_dict = storage.all()["Place.{}".format(testId)].__dict__1381 self.assertEqual(9.8, test_dict["latitude"])1382 def test_update_valid_dictionary_with_float_dot_notation(self):1383 with patch("sys.stdout", new=StringIO()) as output:1384 HBNBCommand().onecmd("create Place")1385 testId = output.getvalue().strip()1386 testCmd = "Place.update({}, ".format(testId)1387 testCmd += "{'latitude': 9.8})"1388 HBNBCommand().onecmd(testCmd)1389 test_dict = storage.all()["Place.{}".format(testId)].__dict__1390 self.assertEqual(9.8, test_dict["latitude"])1391class TestHBNBCommand_count(unittest.TestCase):1392 """Unittests for testing count method of HBNB comand interpreter."""1393 @classmethod1394 def setUp(self):1395 try:1396 os.rename("file.json", "tmp")1397 except IOError:1398 pass1399 FileStorage._FileStorage__objects = {}1400 @classmethod1401 def tearDown(self):1402 try:1403 os.remove("file.json")1404 except IOError:1405 pass1406 try:1407 os.rename("tmp", "file.json")1408 except IOError:1409 pass1410 def test_count_invalid_class(self):1411 with patch("sys.stdout", new=StringIO()) as output:1412 self.assertFalse(HBNBCommand().onecmd("MyModel.count()"))1413 self.assertEqual("0", output.getvalue().strip())1414 def test_count_object(self):1415 with patch("sys.stdout", new=StringIO()) as output:1416 self.assertFalse(HBNBCommand().onecmd("create BaseModel"))1417 with patch("sys.stdout", new=StringIO()) as output:1418 self.assertFalse(HBNBCommand().onecmd("BaseModel.count()"))1419 self.assertEqual("1", output.getvalue().strip())1420 with patch("sys.stdout", new=StringIO()) as output:1421 self.assertFalse(HBNBCommand().onecmd("create User"))1422 with patch("sys.stdout", new=StringIO()) as output:1423 self.assertFalse(HBNBCommand().onecmd("User.count()"))1424 self.assertEqual("1", output.getvalue().strip())1425 with patch("sys.stdout", new=StringIO()) as output:1426 self.assertFalse(HBNBCommand().onecmd("create State"))1427 with patch("sys.stdout", new=StringIO()) as output:1428 self.assertFalse(HBNBCommand().onecmd("State.count()"))1429 self.assertEqual("1", output.getvalue().strip())1430 with patch("sys.stdout", new=StringIO()) as output:1431 self.assertFalse(HBNBCommand().onecmd("create Place"))1432 with patch("sys.stdout", new=StringIO()) as output:1433 self.assertFalse(HBNBCommand().onecmd("Place.count()"))1434 self.assertEqual("1", output.getvalue().strip())1435 with patch("sys.stdout", new=StringIO()) as output:1436 self.assertFalse(HBNBCommand().onecmd("create City"))1437 with patch("sys.stdout", new=StringIO()) as output:1438 self.assertFalse(HBNBCommand().onecmd("City.count()"))1439 self.assertEqual("1", output.getvalue().strip())1440 with patch("sys.stdout", new=StringIO()) as output:1441 self.assertFalse(HBNBCommand().onecmd("create Amenity"))1442 with patch("sys.stdout", new=StringIO()) as output:1443 self.assertFalse(HBNBCommand().onecmd("Amenity.count()"))1444 self.assertEqual("1", output.getvalue().strip())1445 with patch("sys.stdout", new=StringIO()) as output:1446 self.assertFalse(HBNBCommand().onecmd("create Review"))1447 with patch("sys.stdout", new=StringIO()) as output:1448 self.assertFalse(HBNBCommand().onecmd("Review.count()"))1449 self.assertEqual("1", output.getvalue().strip())1450if __name__ == "__main__":...

Full Screen

Full Screen

ganeti.ht_unittest.py

Source:ganeti.ht_unittest.py Github

copy

Full Screen

...22from ganeti import ht23import testutils24class TestTypeChecks(unittest.TestCase):25 def testNone(self):26 self.assertFalse(ht.TNotNone(None))27 self.assertTrue(ht.TNone(None))28 for val in [0, True, "", "Hello World", [], range(5)]:29 self.assertTrue(ht.TNotNone(val))30 self.assertFalse(ht.TNone(val))31 def testBool(self):32 self.assertTrue(ht.TBool(True))33 self.assertTrue(ht.TBool(False))34 for val in [0, None, "", [], "Hello"]:35 self.assertFalse(ht.TBool(val))36 for val in [True, -449, 1, 3, "x", "abc", [1, 2]]:37 self.assertTrue(ht.TTrue(val))38 for val in [False, 0, None, []]:39 self.assertFalse(ht.TTrue(val))40 def testInt(self):41 for val in [-100, -3, 0, 16, 128, 923874]:42 self.assertTrue(ht.TInt(val))43 self.assertTrue(ht.TNumber(val))44 for val in [False, True, None, "", [], "Hello", 0.0, 0.23, -3818.163]:45 self.assertFalse(ht.TInt(val))46 for val in range(0, 100, 4):47 self.assertTrue(ht.TNonNegativeInt(val))48 neg = -(val + 1)49 self.assertFalse(ht.TNonNegativeInt(neg))50 self.assertFalse(ht.TPositiveInt(neg))51 self.assertFalse(ht.TNonNegativeInt(0.1 + val))52 self.assertFalse(ht.TPositiveInt(0.1 + val))53 for val in [0, 0.1, 0.9, -0.3]:54 self.assertFalse(ht.TPositiveInt(val))55 for val in range(1, 100, 4):56 self.assertTrue(ht.TPositiveInt(val))57 self.assertFalse(ht.TPositiveInt(0.1 + val))58 def testFloat(self):59 for val in [-100.21, -3.0, 0.0, 16.12, 128.3433, 923874.928]:60 self.assertTrue(ht.TFloat(val))61 self.assertTrue(ht.TNumber(val))62 for val in [False, True, None, "", [], "Hello", 0, 28, -1, -3281]:63 self.assertFalse(ht.TFloat(val))64 def testNumber(self):65 for val in [-100, -3, 0, 16, 128, 923874,66 -100.21, -3.0, 0.0, 16.12, 128.3433, 923874.928]:67 self.assertTrue(ht.TNumber(val))68 for val in [False, True, None, "", [], "Hello", "1"]:69 self.assertFalse(ht.TNumber(val))70 def testString(self):71 for val in ["", "abc", "Hello World", "123",72 u"", u"\u272C", u"abc"]:73 self.assertTrue(ht.TString(val))74 for val in [False, True, None, [], 0, 1, 5, -193, 93.8582]:75 self.assertFalse(ht.TString(val))76 def testElemOf(self):77 fn = ht.TElemOf(range(10))78 self.assertTrue(fn(0))79 self.assertTrue(fn(3))80 self.assertTrue(fn(9))81 self.assertFalse(fn(-1))82 self.assertFalse(fn(100))83 fn = ht.TElemOf([])84 self.assertFalse(fn(0))85 self.assertFalse(fn(100))86 self.assertFalse(fn(True))87 fn = ht.TElemOf(["Hello", "World"])88 self.assertTrue(fn("Hello"))89 self.assertTrue(fn("World"))90 self.assertFalse(fn("e"))91 def testList(self):92 for val in [[], range(10), ["Hello", "World", "!"]]:93 self.assertTrue(ht.TList(val))94 for val in [False, True, None, {}, 0, 1, 5, -193, 93.8582]:95 self.assertFalse(ht.TList(val))96 def testDict(self):97 for val in [{}, dict.fromkeys(range(10)), {"Hello": [], "World": "!"}]:98 self.assertTrue(ht.TDict(val))99 for val in [False, True, None, [], 0, 1, 5, -193, 93.8582]:100 self.assertFalse(ht.TDict(val))101 def testIsLength(self):102 fn = ht.TIsLength(10)103 self.assertTrue(fn(range(10)))104 self.assertFalse(fn(range(1)))105 self.assertFalse(fn(range(100)))106 def testAnd(self):107 fn = ht.TAnd(ht.TNotNone, ht.TString)108 self.assertTrue(fn(""))109 self.assertFalse(fn(1))110 self.assertFalse(fn(None))111 def testOr(self):112 fn = ht.TMaybe(ht.TAnd(ht.TString, ht.TIsLength(5)))113 self.assertTrue(fn("12345"))114 self.assertTrue(fn(None))115 self.assertFalse(fn(1))116 self.assertFalse(fn(""))117 self.assertFalse(fn("abc"))118 def testMap(self):119 self.assertTrue(ht.TMap(str, ht.TString)(123))120 self.assertTrue(ht.TMap(int, ht.TInt)("9999"))121 self.assertFalse(ht.TMap(lambda x: x + 100, ht.TString)(123))122 def testNonEmptyString(self):123 self.assertTrue(ht.TNonEmptyString("xyz"))124 self.assertTrue(ht.TNonEmptyString("Hello World"))125 self.assertFalse(ht.TNonEmptyString(""))126 self.assertFalse(ht.TNonEmptyString(None))127 self.assertFalse(ht.TNonEmptyString([]))128 def testMaybeString(self):129 self.assertTrue(ht.TMaybeString("xyz"))130 self.assertTrue(ht.TMaybeString("Hello World"))131 self.assertTrue(ht.TMaybeString(None))132 self.assertFalse(ht.TMaybeString(""))133 self.assertFalse(ht.TMaybeString([]))134 def testMaybeBool(self):135 self.assertTrue(ht.TMaybeBool(False))136 self.assertTrue(ht.TMaybeBool(True))137 self.assertTrue(ht.TMaybeBool(None))138 self.assertFalse(ht.TMaybeBool([]))139 self.assertFalse(ht.TMaybeBool("0"))140 self.assertFalse(ht.TMaybeBool("False"))141 def testListOf(self):142 fn = ht.TListOf(ht.TNonEmptyString)143 self.assertTrue(fn([]))144 self.assertTrue(fn(["x"]))145 self.assertTrue(fn(["Hello", "World"]))146 self.assertFalse(fn(None))147 self.assertFalse(fn(False))148 self.assertFalse(fn(range(3)))149 self.assertFalse(fn(["x", None]))150 def testDictOf(self):151 fn = ht.TDictOf(ht.TNonEmptyString, ht.TInt)152 self.assertTrue(fn({}))153 self.assertTrue(fn({"x": 123, "y": 999}))154 self.assertFalse(fn(None))155 self.assertFalse(fn({1: "x"}))156 self.assertFalse(fn({"x": ""}))157 self.assertFalse(fn({"x": None}))158 self.assertFalse(fn({"": 8234}))159 def testStrictDictRequireAllExclusive(self):160 fn = ht.TStrictDict(True, True, { "a": ht.TInt, })161 self.assertFalse(fn(1))162 self.assertFalse(fn(None))163 self.assertFalse(fn({}))164 self.assertFalse(fn({"a": "Hello", }))165 self.assertFalse(fn({"unknown": 999,}))166 self.assertFalse(fn({"unknown": None,}))167 self.assertTrue(fn({"a": 123, }))168 self.assertTrue(fn({"a": -5, }))169 fn = ht.TStrictDict(True, True, { "a": ht.TInt, "x": ht.TString, })170 self.assertFalse(fn({}))171 self.assertFalse(fn({"a": -5, }))172 self.assertTrue(fn({"a": 123, "x": "", }))173 self.assertFalse(fn({"a": 123, "x": None, }))174 def testStrictDictExclusive(self):175 fn = ht.TStrictDict(False, True, { "a": ht.TInt, "b": ht.TList, })176 self.assertTrue(fn({}))177 self.assertTrue(fn({"a": 123, }))178 self.assertTrue(fn({"b": range(4), }))179 self.assertFalse(fn({"b": 123, }))180 self.assertFalse(fn({"foo": {}, }))181 self.assertFalse(fn({"bar": object(), }))182 def testStrictDictRequireAll(self):183 fn = ht.TStrictDict(True, False, { "a": ht.TInt, "m": ht.TInt, })184 self.assertTrue(fn({"a": 1, "m": 2, "bar": object(), }))185 self.assertFalse(fn({}))186 self.assertFalse(fn({"a": 1, "bar": object(), }))187 self.assertFalse(fn({"a": 1, "m": [], "bar": object(), }))188 def testStrictDict(self):189 fn = ht.TStrictDict(False, False, { "a": ht.TInt, })190 self.assertTrue(fn({}))191 self.assertFalse(fn({"a": ""}))192 self.assertTrue(fn({"a": 11}))193 self.assertTrue(fn({"other": 11}))194 self.assertTrue(fn({"other": object()}))195 def testJobId(self):196 for i in [0, 1, 4395, 2347625220]:197 self.assertTrue(ht.TJobId(i))198 self.assertTrue(ht.TJobId(str(i)))199 self.assertFalse(ht.TJobId(-(i + 1)))200 for i in ["", "-", ".", ",", "a", "99j", "job-123", "\t", " 83 ",201 None, [], {}, object()]:202 self.assertFalse(ht.TJobId(i))203 def testRelativeJobId(self):204 for i in [-1, -93, -4395]:205 self.assertTrue(ht.TRelativeJobId(i))206 self.assertFalse(ht.TRelativeJobId(str(i)))207 for i in [0, 1, 2, 10, 9289, "", "0", "-1", "-999"]:208 self.assertFalse(ht.TRelativeJobId(i))209 self.assertFalse(ht.TRelativeJobId(str(i)))210 def testItems(self):211 self.assertRaises(AssertionError, ht.TItems, [])212 fn = ht.TItems([ht.TString])213 self.assertFalse(fn([0]))214 self.assertFalse(fn([None]))215 self.assertTrue(fn(["Hello"]))216 self.assertTrue(fn(["Hello", "World"]))217 self.assertTrue(fn(["Hello", 0, 1, 2, "anything"]))218 fn = ht.TItems([ht.TAny, ht.TInt, ht.TAny])219 self.assertTrue(fn(["Hello", 0, []]))220 self.assertTrue(fn(["Hello", 893782]))221 self.assertTrue(fn([{}, -938210858947, None]))222 self.assertFalse(fn(["Hello", []]))223 def testInstanceOf(self):224 fn = ht.TInstanceOf(self.__class__)225 self.assertTrue(fn(self))226 self.assertTrue(str(fn).startswith("Instance of "))227 self.assertFalse(fn(None))228 def testMaybeValueNone(self):229 fn = ht.TMaybeValueNone(ht.TInt)230 self.assertTrue(fn(None))231 self.assertTrue(fn(0))232 self.assertTrue(fn(constants.VALUE_NONE))233 self.assertFalse(fn(""))234 self.assertFalse(fn([]))235 self.assertFalse(fn(constants.VALUE_DEFAULT))236if __name__ == "__main__":...

Full Screen

Full Screen

faketime.py

Source:faketime.py Github

copy

Full Screen

...34 def test_minutes(self):35 schedule = EventSchedule(callback="foo", \36 minutes=set([1,3,5]), 37 count=1)38 self.assertFalse(schedule.should_fire(start))39 self.assertFalse(schedule.should_fire(start+sec))40 self.assertTrue(schedule.should_fire(start+1*min))41 self.assertFalse(schedule.should_fire(start+2*min))42 self.assertTrue(schedule.should_fire(start+3*min))43 self.assertFalse(schedule.should_fire(start+4*min))44 self.assertTrue(schedule.should_fire(start+5*min)) 45 self.assertFalse(schedule.should_fire(start+hour))46 self.assertFalse(schedule.should_fire(start+day))47 self.assertFalse(schedule.should_fire(start+week))48 def test_hours(self):49 schedule = EventSchedule(callback="foo", hours=set([3,5,23]), \50 minutes='*')51 self.assertFalse(schedule.should_fire(start))52 self.assertTrue(schedule.should_fire(start+3*hour))53 self.assertFalse(schedule.should_fire(start+4*hour))54 self.assertTrue(schedule.should_fire(start+5*hour))55 self.assertFalse(schedule.should_fire(start+6*hour))56 self.assertTrue(schedule.should_fire(start+23*hour))57 def test_days_of_week(self):58 """ fire event monday, friday, and sunday, at 8:15 am and 5:15 pm59 Note: days of week are indexed starting '0' 60 """61 schedule = EventSchedule(callback="foo", days_of_week=set([0,4,6]),62 hours=set([8,17]), \63 minutes=set([15]))64 self.assertFalse(schedule.should_fire(start))65 self.assertFalse(schedule.should_fire(start+5*day))66 self.assertFalse(schedule.should_fire(start+7*day))67 self.assertFalse(schedule.should_fire(start+3*hour))68 self.assertFalse(schedule.should_fire(start+5*day+7*hour))69 self.assertFalse(schedule.should_fire(start+7*day+16*hour))70 self.assertFalse(schedule.should_fire(start+8*hour+13*min))71 self.assertFalse(schedule.should_fire(start+5*day+8*hour+16*min))72 self.assertFalse(schedule.should_fire(start+7*day+8*hour+25*min))73 self.assertFalse(schedule.should_fire(start+3*day+8*hour+15*min))74 self.assertFalse(schedule.should_fire(start+5*day+17*hour+15*min))75 self.assertTrue(schedule.should_fire(start+8*hour+15*min))76 self.assertTrue(schedule.should_fire(start+17*hour+15*min))77 self.assertTrue(schedule.should_fire(start+4*day+8*hour+15*min))78 self.assertTrue(schedule.should_fire(start+6*day+17*hour+15*min))79 80 def test_days_of_month(self):81 """ Fire event on the 1st, 15th, and 30th of the month at 10:00 am82 Note: days of month are indexed starting '1' 83 """84 schedule = EventSchedule(callback="foo", days_of_month=set([1,15,30]),85 hours=set([10]), \86 minutes=set([0]))87 self.assertFalse(schedule.should_fire(start))88 self.assertTrue(schedule.should_fire(start+10*hour))89 self.assertFalse(schedule.should_fire(start+10*hour+min))90 self.assertFalse(schedule.should_fire(start+10*min))91 self.assertFalse(schedule.should_fire(start+day+10*hour))92 self.assertTrue(schedule.should_fire(start+14*day+10*hour))93 self.assertFalse(schedule.should_fire(start+14*day+9*hour))94 self.assertFalse(schedule.should_fire(start+14*day+11*hour))95 self.assertFalse(schedule.should_fire(start+13*day+10*hour))96 self.assertFalse(schedule.should_fire(start+15*day+10*hour))97 self.assertTrue(schedule.should_fire(start+29*day+10*hour))98 self.assertFalse(schedule.should_fire(start+29*day+1*min))99 self.assertFalse(schedule.should_fire(start+29*day-1*min))100 self.assertFalse(schedule.should_fire(start+28*day+10*hour))101 102 def test_month(self):103 """ Fire event every minute in February104 Note: months are indexed from '1' 105 """106 schedule = EventSchedule(callback="foo", months=set([2]), \107 days_of_month='*',108 hours='*', \109 minutes='*')110 self.assertFalse(schedule.should_fire(start))111 self.assertTrue(schedule.should_fire(start+month))112 self.assertTrue(schedule.should_fire(start+month+sec))113 self.assertTrue(schedule.should_fire(start+month+min))114 self.assertTrue(schedule.should_fire(start+month+hour))115 self.assertTrue(schedule.should_fire(start+month+day))116 self.assertTrue(schedule.should_fire(start+month+sec+min+hour+day))117 self.assertFalse(schedule.should_fire(start+2*month))118 self.assertFalse(schedule.should_fire(start+2*month+sec))119 self.assertFalse(schedule.should_fire(start+2*month+min))120 self.assertFalse(schedule.should_fire(start+2*month+hour))121 self.assertFalse(schedule.should_fire(start+2*month+day))122 123 def tearDown(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful