def dict_to_obj(self, dic, obj=None):
        if not obj:
            obj = DataStructure()
        for k in dic:
            obj.__dict__[k] = dic[k]

        return obj
    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)
Beispiel #4
0
 def dict_to_obj(self,dic,obj=None):
     if not obj:
         obj = DataStructure()
     for k in dic:
         obj.__dict__[k] = dic[k]
         
     return obj
Beispiel #5
0
    def test_to_json(self):
        utils= Utils()
        # create a dummy request structure
        request = DataStructure()
        # This is exactly what the data from the browser looks like:
        request.data = b'{"tableName":"BAInfo","attrName":" StartDate ","attrValue":"","linkName":"undefined","baseTab":false,"showAttrs":""}'
#         dictionaryStructure = AppServer.json_decode(request)
        dictionaryStructure = utils.json_decode(request)
        self.assertEqual("BAInfo", dictionaryStructure['tableName'])
    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')
Beispiel #9
0
    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')
Beispiel #10
0
    def test_dict_to_obj(self):
        utils= Utils()
        d = dict()
        d['fld1'] = 'val1'
        d['fld2'] = 'val2'
        obj = utils.dict_to_obj(d)

        self.assertEqual(obj.fld1,'val1')
        self.assertEqual(obj.fld2,'val2')
        
        ds = DataStructure()
        ds.__dict__['myValue'] = 'Important'
        
        utils.dict_to_obj(d,ds)
        
        self.assertEqual(ds.myValue,'Important')
        self.assertEqual(ds.fld1,'val1')
        self.assertEqual(ds.fld2,'val2')
Beispiel #11
0
    def excelLoadWsTable(self, tabName):
        try:
            ws = self.wb[tabName]
            stack = []
            recordNo = 0
            headerRow = None
            for row in ws.rows:
                if headerRow == None:
                    headerRow = row
                else:
                    recordNo = recordNo + 1
                    ds = DataStructure()
                    stack.append(ds)
                    i = 0
                    for cell in headerRow:
                        setattr(ds, cell.value, row[i].value)
                        i = i + 1
                    setattr(ds, 'RecordNumber', recordNo)
                    setattr(ds, 'ExcelRow', row)
                    setattr(ds, 'HeaderRow', headerRow)
        except KeyError:
            raise AppError('The excel worksheet ' + self.worksheetName +
                           ' does not have tab: ' + tabName)
        except AttributeError as e:
            print('Error Loading tab:', tabName, ' column:', i, 'Record:',
                  recordNo, 'Error:', e)
            print('   cell.value:', cell.value)
            print('   headerRow:', headerRow)
            print('         row:', row)
            raise e
        except TypeError as e:
            print('Error Loading tab:', tabName, ' column:', i, 'Record:',
                  recordNo, 'Error:', e)
            print('   headerRow:', headerRow)
            print('         row:', row)
            raise e

        return stack
Beispiel #12
0
    def getRoyaltyCalc(self, month, wellID):
        rc = DataStructure()
        setattr(rc, 'ID', 0)
        setattr(rc, 'ProdMonth', month)
        setattr(rc, 'WellID', wellID)

        setattr(rc, 'K', 0.0)
        setattr(rc, 'X', 0.0)
        setattr(rc, 'C', 0.0)
        setattr(rc, 'D', 0.0)

        setattr(rc, 'RoyaltyPrice', 0.0)
        setattr(rc, 'RoyaltyVolume', 0.0)

        setattr(rc, 'ProvCrownRoyaltyRate', 0.0)
        setattr(rc, 'ProvCrownUsedRoyaltyRate', 0.0)
        setattr(rc, 'IOGR1995RoyaltyRate', 0.0)
        setattr(rc, 'GorrRoyaltyRate', 0.0)

        setattr(rc, 'ProvCrownRoyaltyVolume', 0.0)
        setattr(rc, 'GorrRoyaltyVolume', 0.0)
        setattr(rc, 'IOGR1995RoyaltyVolume', 0.0)

        setattr(rc, 'ProvCrownRoyaltyValue', 0.0)
        setattr(rc, 'IOGR1995RoyaltyValue', 0.0)
        setattr(rc, 'GorrRoyaltyValue', 0.0)

        setattr(rc, 'RoyaltyValuePreDeductions', 0.0)
        setattr(rc, 'RoyaltyTransportation', 0.0)
        setattr(rc, 'RoyaltyProcessing', 0.0)
        setattr(rc, 'RoyaltyDeductions', 0.0)
        setattr(rc, 'RoyaltyValue', 0.0)

        setattr(rc, 'CommencementPeriod', None)
        setattr(rc, 'Message', None)
        setattr(rc, 'GorrMessage', None)

        return rc
    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_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')
 def get_data_structure(self, table_name):
     """ This method must be called to create a valid database data structure. """
     ds = DataStructure()
     ds._table_name = table_name
     return ds
 def get_data_structure(self,table_name):
     """ This method must be called to create a valid database data structure. """ 
     ds = DataStructure()
     ds._table_name = table_name
     return ds
    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_formatter_prod_month(self):        
     well = DataStructure()
     well.ProdMonth = 201602
     
     # If there is no attribute in the object called 'LeaseID' use the ID attribute to format the lease string
     self.assertEqual(well._format.ProdMonth,'2016-02')