def test_insert(self): self.db_create.well_royalty_master() well = DataStructure() well.WellEvent = 'WellEvent 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('WellRoyaltyMaster') well.WellEvent = 'WellEvent for this well' self.db.insert(well) self.assertEqual(well.ID, 1) well = self.db.get_data_structure('WellRoyaltyMaster') well.WellEvent = 'Different WellEvent for this well' self.db.insert(well) self.assertEqual(well.ID, 2) well = self.db.select('WellRoyaltyMaster', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].WellEvent, 'WellEvent for this well') well = self.db.get_data_structure('WellRoyaltyMaster') well.WellEvent = 'Next Well WellEvent' well.ID = 10 self.db.insert(well) well = self.db.select('WellRoyaltyMaster', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].WellEvent, 'WellEvent for this well') well = self.db.select('WellRoyaltyMaster', ID=10) self.assertEqual(well[0].ID, 10) self.assertEqual(well[0].WellEvent, 'Next Well WellEvent') well = self.db.get_data_structure('WellRoyaltyMaster') well.WellEvent = 'Just One More' self.db.insert(well) self.assertEqual(well.ID, 11) well = self.db.get_data_structure('WellRoyaltyMaster') 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('WellRoyaltyMaster') well.ID = None well.WellEvent = '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_royalty_master() well = DataStructure() well.WellEvent = "WellEvent 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("WellRoyaltyMaster") well.WellEvent = "WellEvent for this well" self.db.insert(well) self.assertEqual(well.ID, 1) well = self.db.get_data_structure("WellRoyaltyMaster") well.WellEvent = "Different WellEvent for this well" self.db.insert(well) self.assertEqual(well.ID, 2) well = self.db.select("WellRoyaltyMaster", ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].WellEvent, "WellEvent for this well") well = self.db.get_data_structure("WellRoyaltyMaster") well.WellEvent = "Next Well WellEvent" well.ID = 10 self.db.insert(well) well = self.db.select("WellRoyaltyMaster", ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].WellEvent, "WellEvent for this well") well = self.db.select("WellRoyaltyMaster", ID=10) self.assertEqual(well[0].ID, 10) self.assertEqual(well[0].WellEvent, "Next Well WellEvent") well = self.db.get_data_structure("WellRoyaltyMaster") well.WellEvent = "Just One More" self.db.insert(well) self.assertEqual(well.ID, 11) well = self.db.get_data_structure("WellRoyaltyMaster") 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("WellRoyaltyMaster") well.ID = None well.WellEvent = "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_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') self.assertEqual(monthly._format.yyyy_mm_dd(None), '')
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('WellRoyaltyMaster', ID=2) well[0].WellEvent = '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('WellRoyaltyMaster', ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].WellEvent, 'SKWI111062705025W300') well = self.db.select('WellRoyaltyMaster', ID=2) self.assertEqual(well[0].ID, 2) self.assertEqual(well[0].WellEvent, 'Changed') 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 = 'WellRoyaltyMaster' 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("WellRoyaltyMaster", ID=2) well[0].WellEvent = "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("WellRoyaltyMaster", ID=1) self.assertEqual(well[0].ID, 1) self.assertEqual(well[0].WellEvent, "SKWI111062705025W300") well = self.db.select("WellRoyaltyMaster", ID=2) self.assertEqual(well[0].ID, 2) self.assertEqual(well[0].WellEvent, "Changed") 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 = "WellRoyaltyMaster" 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_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), 4) self.assertIn('_format', dd) # The format attribute is used for formatting. self.assertIn('_original', dd) # Used for comparing differences. 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_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_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")