def test_insert(self): self.db_create.well() well = DataStructure() well.UWI = 'UWI for this well' # Should raise this error since we need to get the structure from the database self.assertRaises(TypeError, self.db.insert) well = self.db.get_data_structure('Well') well.UWI = 'UWI for this well' self.db.insert(well) self.assertEqual(well.ID, 1) well = self.db.get_data_structure('Well') well.UWI = 'Different UWI for this well' self.db.insert(well) self.assertEqual(well.ID, 2) well = self.db.select('Well', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].UWI, 'UWI for this well') well = self.db.get_data_structure('Well') well.UWI = 'Next Well UWI' well.ID = 10 self.db.insert(well) well = self.db.select('Well', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].UWI, 'UWI for this well') well = self.db.select('Well', ID=10) self.assertEqual(well[0].ID, 10) self.assertEqual(well[0].UWI, 'Next Well UWI') well = self.db.get_data_structure('Well') well.UWI = 'Just One More' self.db.insert(well) self.assertEqual(well.ID, 11) well = self.db.get_data_structure('Well') well.BadAttr = 'Just another value' self.assertRaises(AppError, self.db.insert,well) # if the ID is None,Blank,or zero we shold still be able to insert a record well = self.db.get_data_structure('Well') well.ID = None well.UWI = 'Just One More' self.db.insert(well) self.assertEqual(well.ID, 12) well.ID = 0 self.db.insert(well) self.assertEqual(well.ID, 13) well.ID = '' self.db.insert(well) self.assertEqual(well.ID, 14)
def test_insert(self): self.db_create.well() well = DataStructure() well.UWI = 'UWI for this well' # Should raise this error since we need to get the structure from the database self.assertRaises(TypeError, self.db.insert) well = self.db.get_data_structure('Well') well.UWI = 'UWI for this well' self.db.insert(well) self.assertEqual(well.ID, 1) well = self.db.get_data_structure('Well') well.UWI = 'Different UWI for this well' self.db.insert(well) self.assertEqual(well.ID, 2) well = self.db.select('Well', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].UWI, 'UWI for this well') well = self.db.get_data_structure('Well') well.UWI = 'Next Well UWI' well.ID = 10 self.db.insert(well) well = self.db.select('Well', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].UWI, 'UWI for this well') well = self.db.select('Well', ID=10) self.assertEqual(well[0].ID, 10) self.assertEqual(well[0].UWI, 'Next Well UWI') well = self.db.get_data_structure('Well') well.UWI = 'Just One More' self.db.insert(well) self.assertEqual(well.ID, 11) well = self.db.get_data_structure('Well') well.BadAttr = 'Just another value' self.assertRaises(AppError, self.db.insert, well) # if the ID is None,Blank,or zero we shold still be able to insert a record well = self.db.get_data_structure('Well') well.ID = None well.UWI = 'Just One More' self.db.insert(well) self.assertEqual(well.ID, 12) well.ID = 0 self.db.insert(well) self.assertEqual(well.ID, 13) well.ID = '' self.db.insert(well) self.assertEqual(well.ID, 14)
def test_update(self): self.dbu.create_some_test_well_royalty_masters() # change all types of attributes, read another record and then read the record again to make sure the changes were made. well = self.db.select('Well', ID=2) well[0].UWI = 'Changed' well[0].LeaseID = 100 well[0].CommencementDate = '2016-02-01 00:00:00' well[0].WellType = None self.db.update(well[0]) well = self.db.select('Well', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].UWI, 'SKWI111062705025W300') well = self.db.select('Well', ID=2) self.assertEqual(well[0].ID, 2) self.assertEqual(well[0].UWI, 'Changed') self.assertEqual(well[0].LeaseID, 100) self.assertEqual(well[0].CommencementDate, datetime(2016, 2, 1, 0, 0)) self.assertEqual(well[0].WellType, None) ds = DataStructure() self.assertRaises(AttributeError, self.db.update, ds) ds._table_name = 'Well' self.assertRaises(AttributeError, self.db.update, ds) ds.ID = 100 self.assertRaises(AppError, self.db.update, ds)
def test_update(self): self.dbu.create_some_test_well_royalty_masters() # change all types of attributes, read another record and then read the record again to make sure the changes were made. well = self.db.select('Well', ID=2) well[0].UWI = 'Changed' well[0].LeaseID = 100 well[0].CommencementDate = '2016-02-01 00:00:00' well[0].WellType = None self.db.update(well[0]) well = self.db.select('Well', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].UWI, 'SKWI111062705025W300') well = self.db.select('Well', ID=2) self.assertEqual(well[0].ID, 2) self.assertEqual(well[0].UWI, 'Changed') self.assertEqual(well[0].LeaseID, 100) self.assertEqual(well[0].CommencementDate, datetime(2016,2,1,0,0)) self.assertEqual(well[0].WellType, None) ds = DataStructure() self.assertRaises(AttributeError, self.db.update, ds) ds._table_name = 'Well' self.assertRaises(AttributeError, self.db.update, ds) ds.ID = 100 self.assertRaises(AppError, self.db.update, ds)
def test_formatter_lease(self): well = DataStructure() well.ID = 123 well.LeaseType = 'OL' # If there is no attribute in the object called 'LeaseID' use the ID attribute to format the lease string self.assertEqual(well._format.lease, 'OL-0123') well.LeaseID = 1 # If there is an attribute in the object called 'LeaseID' use it to format the lease string self.assertEqual(well._format.lease, 'OL-0001')
def test_data_structure(self): well = DataStructure() well.ID = 123 well.Name = 'WellName' # This returns a dictionary object for the attributes in an object dd = vars(well) self.assertEqual(len(dd),3) self.assertIn('_format', dd) # The format attribute is used for formatting. self.assertEqual(dd['ID'],123) self.assertEqual(dd['Name'],'WellName')
def test_format_lease(self): """ This is the old way of formatting attributes and will be deprecated shortly: test_formatter_lease for the new way """ well = DataStructure() well.ID = 123 well.LeaseType = 'OL' # If there is no attribute in the object called 'LeaseID' use the ID attribute to format the lease string self.assertEqual(well.lease, 'OL-0123') well.LeaseID = 1 # If there is an attribute in the object called 'LeaseID' use it to format the lease string self.assertEqual(well.lease, 'OL-0001')
def test_obj_to_dict(self): ds = DataStructure() utils = Utils() ds.ID = 123 ds.Name = "My Name" result = utils.obj_to_dict(ds, dict()) self.assertEqual(result['ID'],123) self.assertEqual(result['Name'],'My Name') result = utils.obj_to_dict(ds) self.assertEqual(result['ID'],123) self.assertEqual(result['Name'],'My Name')
def test_formatter_date(self): monthly = DataStructure() monthly.ID = 123 monthly.ExtractMonth = datetime(2016,2,22) self.assertEqual(monthly._format.yyyy_mm_dd(monthly.ExtractMonth), '2016-02-22')