def test_create_from_dict1(self): b1 = BaseModel() b1.name = "Bob" b1.my_number = "213" b1.lname = "Smith" b1_json = b1.to_dict() b2 = BaseModel(**b1_json) self.assertEqual(b1.__dict__, b2.__dict__)
def test_create_from_dict3(self): b1 = BaseModel() b1.name = "Peter" b1.my_number = "415" b1.lname = "Pico" b1_json = b1.to_dict() b2 = BaseModel(**b1_json) self.assertEqual(b1.__class__.__name__, b2.__class__.__name__) self.assertEqual(b1.created_at, b2.created_at) self.assertEqual(b1.updated_at, b2.updated_at) self.assertEqual(b1.id, b2.id) self.assertEqual(b1.name, b2.name) self.assertEqual(b1.my_number, b2.my_number) self.assertEqual(b1.lname, b2.lname)
def test_create_from_dict2(self): b1 = BaseModel() b1.name = "Rob" b1.my_number = "312" b1.lname = "Jones" b1_json = b1.to_dict() b2 = BaseModel(**b1_json) output1 = StringIO() print(sorted(b1.__dict__.items()), file=output1, end='') content1 = output1.getvalue() output1.close() output2 = StringIO() print(sorted(b2.__dict__.items()), file=output2, end='') content2 = output2.getvalue() output2.close() self.assertEqual(content1, content2)
def test_str(self): b1 = BaseModel() b1.lname = "Smith" teststr = "[BaseModel] ({}) {}".format(b1.id, b1.__dict__) self.assertEqual(teststr, str(b1))