コード例 #1
0
    def setUp(self):
        self.assertEqual(
            config.get_environment(),
            'unittest')  # Distructive Tests must run in unittest enviornment
        self.dbi = config.get_database_instance()
        self.db = config.get_database()
        self.dbu = DatabaseUtilities()
        self.db_create = DatabaseCreate()

        self.dbu.delete_all_tables()
コード例 #2
0
 def test_process_monthly(self):
     self.dbu = DatabaseUtilities()
     self.dbu.delete_all_tables()
     self.dbu.create_some_test_well_royalty_masters()
     self.dbu.create_some_test_lease_royalty_masters()
     self.dbu.create_some_test_leases()
     self.dbu.create_some_test_monthly()
     self.dbu.create_some_test_econdata()
     self.dbu.create_calc()
     pr = ProcessRoyalties()
     pr.process_one(4, 201501, 'Oil')
コード例 #3
0
    def setUp(self):
        self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment
        db_utils = DatabaseUtilities()
        db_utils.delete_all_tables()

        instance = config.get_database_instance()
        instance.execute('create table ' + self.TEST_TABLE_NAME  + ' (myKey int, myText text, myDate date)')
        instance.commit()
        
        instance.execute('insert into ' + self.TEST_TABLE_NAME + " values (1, 'Test Item One', '2016-02-14')")
        instance.execute('insert into ' + self.TEST_TABLE_NAME + " values (2, 'Test Item Two', '2016-02-14')")
        instance.commit()
コード例 #4
0
    def test_get_column_name(self):
        instance = config.get_database_instance()
        db_utils = DatabaseUtilities()
        db_utils.delete_all_tables()

        instance.execute('create table ' + self.TEST_TABLE_NAME  + ' (myKey int, myText text, myDate date)')
        instance.execute('insert into ' + self.TEST_TABLE_NAME + " values (1, 'Test Item One', '2016-02-14')")
        
        instance.execute('select * from ' + self.TEST_TABLE_NAME)
        
        columns = instance.get_column_names()
        self.assertEqual(columns[0],'myKey')
        self.assertEqual(columns[1],'myText')
        self.assertEqual(columns[2],'myDate')
コード例 #5
0
    def test_get_link_data(self):
        #setup stuff
        utils = Utils()
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()

        dbu.delete_all_tables()
        db_create.linktab()
        dbu.create_some_test_well_royalty_masters()
        dbu.create_some_test_leases()

        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Lease'
        linktab.AttrName = 'ID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 1
        linktab.ShowAttrs = 'ID,Lessor'
        db.insert(linktab)

        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'LeaseID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 0
        linktab.ShowAttrs = ''
        db.insert(linktab)

        data = dict()
        data["TabName"] = 'Well'
        data["AttrName"] = 'LeaseID'
        data["AttrValue"] = 2

        json_from_browser = json.dumps(data)
        print('json_from_browser', json_from_browser)

        # Data should be found
        resp = self.myapp.post('/data/getLinkData.json',
                               data=json_from_browser)
        print("resp:", resp)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)

        print('data', data)
        rows = data['BaseData']
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0][0], 'ID')
        self.assertEqual(rows[0][1], 'Lessor')
        self.assertEqual(rows[1][0], 2)
        self.assertEqual(rows[1][1], 2346)

        rows = data['Links']
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0][0], 'Lease')
        self.assertEqual(rows[0][1], 'ID')
        self.assertEqual(rows[1][0], 'Well')
        self.assertEqual(rows[1][1], 'LeaseID')
コード例 #6
0
 def setUp(self):
     self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment
     self.dbi = config.get_database_instance()
     self.db = config.get_database()
     self.dbu = DatabaseUtilities()
     self.db_create = DatabaseCreate()
     
     self.dbu.delete_all_tables()
コード例 #7
0
 def test_process_monthly(self):
     self.dbu = DatabaseUtilities()
     self.dbu.delete_all_tables()
     self.dbu.create_some_test_well_royalty_masters()
     self.dbu.create_some_test_lease_royalty_masters()
     self.dbu.create_some_test_leases()
     self.dbu.create_some_test_monthly()
     self.dbu.create_some_test_econdata()
     self.dbu.create_calc()
     pr = ProcessRoyalties()
     pr.process_one(4, 201501, 'Oil')
コード例 #8
0
    def test_get_link_data(self):
        #setup stuff
        utils = Utils()
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()

        dbu.delete_all_tables()
        db_create.linktab()
        dbu.create_some_test_well_royalty_masters()
        dbu.create_some_test_leases()
        
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Lease'
        linktab.AttrName = 'ID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 1
        linktab.ShowAttrs = 'ID,Lessor'
        db.insert(linktab)
        
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'LeaseID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 0
        linktab.ShowAttrs = ''
        db.insert(linktab)

        data = dict()
        data["TabName"] = 'Well'
        data["AttrName"] = 'LeaseID'
        data["AttrValue"] = 2
        
        json_from_browser = json.dumps(data)
        print('json_from_browser', json_from_browser)

        # Data should be found
        resp = self.myapp.post('/data/getLinkData.json',data=json_from_browser)
        print("resp:",resp)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        
        print('data',data)
        rows = data['BaseData']
        self.assertEqual(len(rows),2)
        self.assertEqual(rows[0][0],'ID')
        self.assertEqual(rows[0][1],'Lessor')
        self.assertEqual(rows[1][0],2)
        self.assertEqual(rows[1][1],2346)
        
        rows = data['Links']
        self.assertEqual(len(rows),2)
        self.assertEqual(rows[0][0],'Lease')
        self.assertEqual(rows[0][1],'ID')
        self.assertEqual(rows[1][0],'Well')
        self.assertEqual(rows[1][1],'LeaseID')
コード例 #9
0
    def test_link_update(self):
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()
        db_create.linktab()

        # Test Insert
        data = dict()
        data["ID"] = '0'
        data["TabName"] = 'Lease'
        data["AttrName"] = 'ID'
        data["LinkName"] = 'Lease'
        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',
                               data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"], 0)

        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)

        # Test Update
        data = utils.obj_to_dict(result[0])
        data['LinkName'] = 'Changed'

        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',
                               data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"], 0)

        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].LinkName, 'Changed')
コード例 #10
0
    def test_get_link_row(self):
        #setup stuff
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()

        db_create.linktab()
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'ID'
        json_to_browser = json.dumps(utils.obj_to_dict(linktab))
        print('json_to_browser', json_to_browser)

        # Data should not be found but there should not be an error
        resp = self.myapp.post('/data/getLinkRow.json', data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["LinkName"], '')

        linktab.LinkName = 'Well'
        linktab.BaseTab = 0
        linktab.ShowAttrs = 'ID,UWI'
        db.insert(linktab)

        # Data should be found
        resp = self.myapp.post('/data/getLinkRow.json', data=json_to_browser)
        data = utils.json_decode(resp)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(data["LinkName"], 'Well')
        self.assertEqual(data["ShowAttrs"], 'ID,UWI')

        print('status:', resp.status)
        print('status code:', resp.status_code)
        print(resp)
        print(resp.data)
コード例 #11
0
    def test_get_link_row(self):
        #setup stuff
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()

        db_create.linktab()
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'ID'
        json_to_browser = json.dumps(utils.obj_to_dict(linktab))
        print('json_to_browser', json_to_browser)

        # Data should not be found but there should not be an error
        resp = self.myapp.post('/data/getLinkRow.json',data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["LinkName"],'')
        
        linktab.LinkName = 'Well'
        linktab.BaseTab = 0
        linktab.ShowAttrs = 'ID,UWI'
        db.insert(linktab)
        
        # Data should be found 
        resp = self.myapp.post('/data/getLinkRow.json',data=json_to_browser)
        data = utils.json_decode(resp)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(data["LinkName"],'Well')
        self.assertEqual(data["ShowAttrs"],'ID,UWI')
        
        print('status:',resp.status)
        print('status code:',resp.status_code)
        print(resp)
        print(resp.data)      
コード例 #12
0
    def test_link_update(self):
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()
        db_create.linktab()

        # Test Insert
        data = dict()
        data["ID"] = '0'
        data["TabName"] = 'Lease'
        data["AttrName"] = 'ID'
        data["LinkName"] = 'Lease'
        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"],0)
        
        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)
        
        # Test Update
        data = utils.obj_to_dict(result[0])
        data['LinkName'] = 'Changed' 

        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"],0)
        
        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].LinkName,'Changed')
コード例 #13
0
class TestSaskRoyaltyCalc(unittest.TestCase):

    def setUp(self):
        self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment


#     def xtest_determineRoyaltyPrice (self):
#         
#         pr = ProcessRoyalties()
#         monthly = TestHelper.getMonthlyDataClone()
#         monthly.WellHeadPrice = 10
#         monthly.TransRate = 3
#         monthly.ProcessingRate = 1
#         self.assertEqual(pr.determineRoyaltyprice(None,monthly), monthly.WellHeadPrice)
#         self.assertEqual(pr.determineRoyaltyprice('asdf',monthly), monthly.WellHeadPrice)
#         self.assertEqual(pr.determineRoyaltyprice('ActSales',monthly), 14)
# 
#         return

    def test_calcSaskOilRegulationSubsection2(self):
        """ subsection (2) """
        pr = ProcessRoyalties()
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(70), 7)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(90), 10)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(200), (24 + .26 * (200 - 160)))
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(2000), (24 + .26 * (2000 - 160)))
        return
    
    def test_calcSaskOilRegulationSubsection3(self):
        """ subsection (3) """
        pr = ProcessRoyalties()
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(70), 7)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(90), 10)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(200), (24 + .26 * (200 - 160)))
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(2000), (189 + .4 * (2000 - 795)))
        return
    
    
    def test_determineCommencementPeriod(self):
        pr = ProcessRoyalties()
        self.assertEqual(pr.determine_commencement_period(201501, date(2014, 12, 1)), .08)
        self.assertEqual(pr.determine_commencement_period(201501, date(2014, 12, 31)), 0)
        self.assertEqual(pr.determine_commencement_period(201501, date(2014, 1, 1)), 1)
        self.assertEqual(pr.determine_commencement_period(201501, date(2010, 11, 30)), 4.09)
        self.assertEqual(pr.determine_commencement_period(201501, date(2010, 1, 1)), 5)
        self.assertEqual(pr.determine_commencement_period(201501, date(2010, 1, 31)), 4.92)
        self.assertEqual(pr.determine_commencement_period(201501, date(2010, 1, 1)), 5.0)
        self.assertRaises(AppError, pr.determine_commencement_period, None, None)
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2003, 1, 1)), 12.01)
        return
    

#    
    # Adrienne - write this tests
    # 110% if you can understand what all these lines of code are trying to do....
    
    def test_calcSaskOilProvCrownRoyaltyRate(self):
        econStringData = \
"""
CharMonth,ProdMonth,HOP,SOP,NOP,H4T_C,H4T_D,H4T_K,H4T_X,H3T_K,H3T_X,HNEW_K,HNEW_X,SW4T_C,SW4T_D,SW4T_K,SW4T_X,SW3T_K,SW3T_X,SWNEW_K,SWNEW_X,O4T_C,O4T_D,O4T_K,O4T_X,O3T_K,O3T_X,ONEW_K,ONEW_X,OOLD_K,OOLD_X
Sept.,201509,162,210,276,0.0841,2.1,20.81,1561,20.46,472,26.48,611,0.1045,2.61,25.85,1939,31.57,729,38.54,890,0.1209,3.02,29.91,2243,36.08,833,40.79,941,52.61,1214
"""
        # All this work so we don't need to read from the database. It's a way better test.
        econOilData = DataStructure()
        th = TestHelper()
        royaltyCalc = DataStructure()

        th.load_object_csv_style(econOilData, econStringData)
              
        pr = ProcessRoyalties()

        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Heavy', 24, 0), 0)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Heavy', 100, 0), 6.31)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Southwest', 100, 0), 7.84)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Other', 130, 0), 12.697)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Heavy', 140, 0), 9.66)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Southwest', 136.3, 0), 11.624028)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Other', 150, 0), 14.956667)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Fourth Tier Oil', 'Other', 0, 0), 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Fourth Tier Oil', 'BadString', 120, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Fourth Tier Oil', 'BadString', 140, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Bad String', 'Heavy', 120, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Bad String', 'Southwest', 120, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Bad String', 'Other', 120, 0)

        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Third Tier Oil', 'Heavy', 100, 0.75), 14.99)
        self.assertAlmostEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'New Oil', 'Heavy', 100, 0.75), 19.620000)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'New Oil', 'Heavy', 0, 0), 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Third Tier Oil', 'Bad String', 120, 0)

        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Third Tier Oil', 'Southwest', 120, 0), 25.495000)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'New Oil', 'Southwest', 130, 0.75), 30.943846)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'New Oil', 'Southwest', 0, 0), 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'New Oil', 'Bad String', 120, 0)

        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Third Tier Oil', 'Other', 120, 2.25), 26.888333)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'New Oil', 'Other', 110, 0), 32.235455)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Old Oil', 'Other', 100, 0.75), 39.720000)
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData, 'Old Oil', 'Other', 0, 0), 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Old Oil', 'Bad String', 120, 0)

        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Old Oil', 'Heavy', 120, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate, royaltyCalc, econOilData, 'Old Oil', 'Southwest', 120, 0)

        return


    """
    def test_calcSaskOilProvCrownRoyaltyVolumeValue(self):
        royStringData = \

ProvCrownUsedRoyaltyRate, CrownMultiplier, IndianInterest, MinRoyalty, RoyaltyPrice
6.31, 1, 1, 3.21,

        royOilData = DataStructure()
        th = TestHelper()
        royaltyCalc = DataStructure()

        th.load_object_csv_style(royOilData, royStringData)
        print('ProvCrownUsedRoyaltyRate:',royOilData.ProvCrownUsedRoyaltyRate)
        print('CrownMultiplier:',royOilData.CrownMultiplier)
        print(vars(royOilData))
        print(vars(royOilData).values())

        pr = ProcessRoyalties()
"""

    def test_calcSaskOilProvCrownRoyaltyVolumeValue(self):
        pr = ProcessRoyalties()
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_volume_value(2, 100, 1, 20, 1, 100), (20.0, 2000.0))
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_volume_value(-1, 100, 1, 20, 1, 100), (20.0, 2000.0))
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_volume_value(2, 100, 1, 5, 1, 100), (5, 500.0))
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_volume_value(2, 100, 1, None, 1, 100), (2.0, 200.0))
        self.assertEqual(pr.calc_sask_oil_prov_crown_royalty_volume_value(10, 120, 1, 2, 1, 120), (12, 1440.0))

        return



    def test_calcSaskOilIOGR1995(self):
        m = DataStructure()
        m.WellHeadPrice = 221.123456
        m.TransRate = 2.123455
        m.ProcessingRate = 0.123455
        m.ProdVol = 70
        m.ProdMonth = 201501

        calc = DataStructure()

        pr = ProcessRoyalties()
        #all tests for SaskWellHead
        pr.calc_sask_oil_iogr1995(datetime(2015, 1, 1), "SaskWellHead", 1.2, 0.25, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue,464.36)
        self.assertEqual(calc.CommencementPeriod,0)
        self.assertEqual(calc.IOGR1995RoyaltyVolume,7)
        self.assertEqual(calc.RoyaltyPrice,221.123456)

        m.ProdVol = 100
        pr.calc_sask_oil_iogr1995(datetime(2015, 4, 2), "SaskWellHead", 0.25, 3, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue,1990.11)
        m.ProdVol = 170
        pr.calc_sask_oil_iogr1995(datetime(2015, 5, 1), "SaskWellHead", 1, 1, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 5881.88)
        m.ProdVol = 79.9
        pr.calc_sask_oil_iogr1995(datetime(2010, 1, 1), "SaskWellHead", 3, 2, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue,10600.66)
        m.ProdVol = 150
        pr.calc_sask_oil_iogr1995(datetime(2009, 7, 3), "SaskWellHead", 2, 4, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 38917.73)
        m.ProdVol = 500
        pr.calc_sask_oil_iogr1995(datetime(2007, 8, 2), "SaskWellHead", 1, 5, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 124271.38)
        m.ProdVol = 800
        pr.calc_sask_oil_iogr1995(datetime(2008, 9, 9), "SaskWellHead", 5, 0.1, m, calc)

        self.assertEqual(calc.IOGR1995RoyaltyValue, 21117.29)

    def test_determineCommencementPeriod(self):
        pr = ProcessRoyalties()
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2015, 1, 1)), 0)
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2014, 12, 1)), 0.08)
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2014, 11, 15)), 0.13)
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2014, 1, 1)), 1)
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2014, 1, 1)), 1)
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2010, 1, 1)), 5)
        self.assertEqual(pr.determine_commencement_period(201501, datetime(2009, 12, 1)), 5.09)
        self.assertEqual(pr.determine_commencement_period(201501, None), 5)
        #write tests for ActSales



    def test_calcSaskOilRegulationSubsection2(self):
        pr = ProcessRoyalties()
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(70), 7)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(100), 12)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(170), 26.6)



    def test_calcSaskOilRegulationSubsection3(self):
        pr = ProcessRoyalties()
        self.assertAlmostEqual(pr.calc_sask_oil_iogr_subsection3(79.9), 7.99)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(150), 22)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(500), 112.4)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(800), 191)

    def test_determineRoyaltyPrice(self):
        m = DataStructure()
        m.WellHeadPrice = 221.123456
        m.TransRate = 2.123455
        m.ProcessingRate = 0.123455

        pr = ProcessRoyalties()
        self.assertAlmostEqual(pr.determine_royalty_price('ActSales', m), 223.370366)

        m.WellHeadPrice = 225
        m.TransRate = 3
        m.ProcessingRate = 1

        self.assertAlmostEqual(pr.determine_royalty_price('ActSales', m), 229)


    def test_calcGorrPercent(self):
        pr = ProcessRoyalties()

        gorr = "bad string,0,2"
        self.assertRaises(AppError, pr.calc_gorr_percent, 400, 10, gorr)
        self.assertRaises(AppError, pr.calc_gorr_percent, None, 10, gorr)

        gorr = None,"0,2"
        self.assertRaises(AttributeError, pr.calc_gorr_percent, 400, 10, gorr)

        gorr = "dprod,250,2,300,3,400,4,500,5,0,6"
        self.assertEqual(pr.calc_gorr_percent(600, 10, gorr), (2.0, 'dprod = 60.000000 = 600 / 10 is greater than 0.0 and less than or equal to 250.0 for an RR of 2.0%'))
        self.assertEqual(pr.calc_gorr_percent(1008, 4, gorr), (3.0, 'dprod = 252.000000 = 1008 / 4 is greater than 250.0 and less than or equal to 300.0 for an RR of 3.0%'))
        self.assertEqual(pr.calc_gorr_percent(400, 1, gorr), (4.0, 'dprod = 400.000000 = 400 / 1 is greater than 300.0 and less than or equal to 400.0 for an RR of 4.0%'))
        self.assertEqual(pr.calc_gorr_percent(990, 2, gorr), (5.0, 'dprod = 495.000000 = 990 / 2 is greater than 400.0 and less than or equal to 500.0 for an RR of 5.0%'))
        self.assertEqual(pr.calc_gorr_percent(10000, 17, gorr), (6.0, 'dprod = 588.235294 = 10000 / 17 is greater than 500.0 for an RR of 6.0%'))

        self.assertRaises(TypeError, pr.calc_gorr_percent, None, 10, gorr)

        gorr = "mprod,250,2,300,3,400,4,500,5,0,6"
        self.assertEqual(pr.calc_gorr_percent(200, 10, gorr), (2.0, 'mprod = 200 is greater than 0.0 and less than or equal to 250.0 for an RR of 2.0%'))
        self.assertEqual(pr.calc_gorr_percent(300, 4, gorr), (3.0, 'mprod = 300 is greater than 250.0 and less than or equal to 300.0 for an RR of 3.0%'))
        self.assertEqual(pr.calc_gorr_percent(350.6, 1, gorr), (4.0, 'mprod = 350.6 is greater than 300.0 and less than or equal to 400.0 for an RR of 4.0%'))
        self.assertEqual(pr.calc_gorr_percent(410, 2, gorr), (5.0, 'mprod = 410 is greater than 400.0 and less than or equal to 500.0 for an RR of 5.0%'))
        self.assertEqual(pr.calc_gorr_percent(10000, 17, gorr), (6.0, 'mprod = 10000 is greater than 500.0 for an RR of 6.0%'))

        gorr = "fixed,0,2"
        self.assertEqual(pr.calc_gorr_percent(200, 10, gorr), (2.0, 'fixed for an RR of 2.0%'))
        self.assertEqual(pr.calc_gorr_percent(10000, 4, gorr), (2.0, 'fixed for an RR of 2.0%'))
        #In future make this raise an error:
        self.assertEqual(pr.calc_gorr_percent(None, 10, gorr), (2.0, 'fixed for an RR of 2.0%'))

    def test_calcSupplementaryRoyaltiesIOGR1995(self):
        reference_price = {'Pigeon Lake Indian': 24.04, 'Reserve no.138A': 25.37, 'Sawridge Indian': 25.13, 'Stony Plain Indian': 24.64}
        pr = ProcessRoyalties()
        calc = DataStructure()

        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(3.5, 228, 80, 60, reference_price['Pigeon Lake Indian']), 2039.6)
        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(5, 200, 90, 40, reference_price['Reserve no.138A']), 4365.75)
        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(4, 221.123456, 100, 50, reference_price['Sawridge Indian']), 4899.84)
        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(.2, 180, 80, 35, reference_price['Stony Plain Indian']), 3495.6)

        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(6, 228, 80, 60, reference_price['Pigeon Lake Indian']), 2996.5)
        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(5.5, 200, 90, 40, reference_price['Reserve no.138A']), 6391.38)
        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(8, 221.123456, 100, 50, reference_price['Sawridge Indian']), 7192.5)
        self.assertEqual(pr.calc_supplementary_royalties_iogr1995(15, 180, 80, 35, reference_price['Stony Plain Indian']), 5101.88)

    def test_process_monthly(self):
        self.dbu = DatabaseUtilities()
        self.dbu.delete_all_tables()
        self.dbu.create_some_test_well_royalty_masters()
        self.dbu.create_some_test_lease_royalty_masters()
        self.dbu.create_some_test_leases()
        self.dbu.create_some_test_monthly()
        self.dbu.create_some_test_econdata()
        self.dbu.create_calc()
        pr = ProcessRoyalties()
        pr.process_one(4, 201501, 'Oil')
コード例 #14
0
class SqliteDatabaseTest(unittest.TestCase):
    def setUp(self):
        self.assertEqual(
            config.get_environment(),
            'unittest')  # Distructive Tests must run in unittest enviornment
        self.dbi = config.get_database_instance()
        self.db = config.get_database()
        self.dbu = DatabaseUtilities()
        self.db_create = DatabaseCreate()

        self.dbu.delete_all_tables()

    def test_to_db_value(self):
        self.assertEqual('123', self.db.to_db_value(123))
        self.assertEqual('"asdf"', self.db.to_db_value("asdf"))
        self.assertEqual('123.45', self.db.to_db_value(123.45))
        self.assertEqual('1', self.db.to_db_value(True))
        self.assertEqual('0', self.db.to_db_value(False))
        self.assertEqual('null', self.db.to_db_value(None))

    def test_get_data_structure(self):
        ds = self.db.get_data_structure('WhatEver')
        self.assertEqual('WhatEver', ds._table_name)

    def test_select(self):
        self.dbu.create_some_test_well_royalty_masters()
        self.dbu.create_some_test_leases()

        self.assertIsNotNone(
            self.db.select('Well', RoyaltyClassification='New Oil'))
        self.assertEqual(
            len(self.db.select('Well', Prov='SK', Classification='Other')), 2)
        self.assertEqual(len(self.db.select('Well')), 4)
        self.assertRaises(AppError, self.db.select, 'WrongTable')
        self.assertRaises(AppError,
                          self.db.select,
                          'WrongTable',
                          WrongAttr='WhoCares')
        self.assertRaises(AppError, self.db.select, 'Well', Foo='bar')
        self.assertEqual(len(self.db.select('Lease')), 3)
        self.assertEqual(len(self.db.select('Lease', Prov='SK')), 3)
        self.assertEqual(len(self.db.select('Well', ID=1000)), 0)

    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_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_delete(self):
        self.dbu.create_some_test_well_royalty_masters()

        self.assertEqual(4, len(self.db.select('Well')))

        self.db.delete('Well', 2)
        self.assertEqual(3, len(self.db.select('Well')))
        self.assertEqual(0, len(self.db.select('Well', ID=2)))

    def test_date_format(self):
        self.dbu.create_some_test_well_royalty_masters()

        well = self.db.select('Well', ID=1)
        self.assertTrue(isinstance(well[0].CommencementDate, datetime))
コード例 #15
0
def load_sample_data():
    dbu = DatabaseUtilities()
    drop_create_tables()
    dbu.create_some_test_well_royalty_masters()
    dbu.create_some_test_leases()
コード例 #16
0
def drop_create_tables():
    dbu = DatabaseUtilities()
    db_create = DatabaseCreate()

    dbu.delete_all_tables()
    db_create.create_all()
コード例 #17
0
    def test_all(self):
        dbu = DatabaseUtilities()
        dbc = DatabaseCreate()

        dbu.delete_all_tables()
        dbc.create_all()
コード例 #18
0
class TestSaskRoyaltyCalc(unittest.TestCase):
    def setUp(self):
        self.assertEqual(
            config.get_environment(),
            'unittest')  # Distructive Tests must run in unittest enviornment

#     def xtest_determineRoyaltyPrice (self):
#
#         pr = ProcessRoyalties()
#         monthly = TestHelper.getMonthlyDataClone()
#         monthly.WellHeadPrice = 10
#         monthly.TransRate = 3
#         monthly.ProcessingRate = 1
#         self.assertEqual(pr.determineRoyaltyprice(None,monthly), monthly.WellHeadPrice)
#         self.assertEqual(pr.determineRoyaltyprice('asdf',monthly), monthly.WellHeadPrice)
#         self.assertEqual(pr.determineRoyaltyprice('ActSales',monthly), 14)
#
#         return

    def test_calcSaskOilRegulationSubsection2(self):
        """ subsection (2) """
        pr = ProcessRoyalties()
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(70), 7)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(90), 10)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(200),
                         (24 + .26 * (200 - 160)))
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(2000),
                         (24 + .26 * (2000 - 160)))
        return

    def test_calcSaskOilRegulationSubsection3(self):
        """ subsection (3) """
        pr = ProcessRoyalties()
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(70), 7)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(90), 10)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(200),
                         (24 + .26 * (200 - 160)))
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(2000),
                         (189 + .4 * (2000 - 795)))
        return

    def test_determineCommencementPeriod(self):
        pr = ProcessRoyalties()
        self.assertEqual(
            pr.determine_commencement_period(201501, date(2014, 12, 1)), .08)
        self.assertEqual(
            pr.determine_commencement_period(201501, date(2014, 12, 31)), 0)
        self.assertEqual(
            pr.determine_commencement_period(201501, date(2014, 1, 1)), 1)
        self.assertEqual(
            pr.determine_commencement_period(201501, date(2010, 11, 30)), 4.09)
        self.assertEqual(
            pr.determine_commencement_period(201501, date(2010, 1, 1)), 5)
        self.assertEqual(
            pr.determine_commencement_period(201501, date(2010, 1, 31)), 4.92)
        self.assertEqual(
            pr.determine_commencement_period(201501, date(2010, 1, 1)), 5.0)
        self.assertRaises(AppError, pr.determine_commencement_period, None,
                          None)
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2003, 1, 1)),
            12.01)
        return


#
# Adrienne - write this tests
# 110% if you can understand what all these lines of code are trying to do....

    def test_calcSaskOilProvCrownRoyaltyRate(self):
        econStringData = \
"""
CharMonth,ProdMonth,HOP,SOP,NOP,H4T_C,H4T_D,H4T_K,H4T_X,H3T_K,H3T_X,HNEW_K,HNEW_X,SW4T_C,SW4T_D,SW4T_K,SW4T_X,SW3T_K,SW3T_X,SWNEW_K,SWNEW_X,O4T_C,O4T_D,O4T_K,O4T_X,O3T_K,O3T_X,ONEW_K,ONEW_X,OOLD_K,OOLD_X
Sept.,201509,162,210,276,0.0841,2.1,20.81,1561,20.46,472,26.48,611,0.1045,2.61,25.85,1939,31.57,729,38.54,890,0.1209,3.02,29.91,2243,36.08,833,40.79,941,52.61,1214
"""
        # All this work so we don't need to read from the database. It's a way better test.
        econOilData = DataStructure()
        th = TestHelper()
        royaltyCalc = DataStructure()

        th.load_object_csv_style(econOilData, econStringData)

        pr = ProcessRoyalties()

        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Heavy', 24, 0), 0)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Heavy', 100, 0), 6.31)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Southwest', 100, 0),
            7.84)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Other', 130, 0), 12.697)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Heavy', 140, 0), 9.66)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Southwest', 136.3, 0),
            11.624028)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Other', 150, 0),
            14.956667)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Fourth Tier Oil',
                                                     'Other', 0, 0), 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Fourth Tier Oil',
                          'BadString', 120, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Fourth Tier Oil',
                          'BadString', 140, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Bad String', 'Heavy', 120,
                          0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Bad String', 'Southwest',
                          120, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Bad String', 'Other', 120,
                          0)

        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Third Tier Oil', 'Heavy',
                                                     100, 0.75), 14.99)
        self.assertAlmostEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'New Oil', 'Heavy', 100,
                                                     0.75), 19.620000)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'New Oil', 'Heavy', 0, 0),
            0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Third Tier Oil',
                          'Bad String', 120, 0)

        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Third Tier Oil',
                                                     'Southwest', 120, 0),
            25.495000)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'New Oil', 'Southwest',
                                                     130, 0.75), 30.943846)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'New Oil', 'Southwest', 0,
                                                     0), 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'New Oil', 'Bad String',
                          120, 0)

        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Third Tier Oil', 'Other',
                                                     120, 2.25), 26.888333)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'New Oil', 'Other', 110,
                                                     0), 32.235455)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Old Oil', 'Other', 100,
                                                     0.75), 39.720000)
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_rate(royaltyCalc, econOilData,
                                                     'Old Oil', 'Other', 0, 0),
            0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Old Oil', 'Bad String',
                          120, 0)

        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Old Oil', 'Heavy', 120, 0)
        self.assertRaises(AppError, pr.calc_sask_oil_prov_crown_royalty_rate,
                          royaltyCalc, econOilData, 'Old Oil', 'Southwest',
                          120, 0)

        return

    """
    def test_calcSaskOilProvCrownRoyaltyVolumeValue(self):
        royStringData = \

ProvCrownUsedRoyaltyRate, CrownMultiplier, IndianInterest, MinRoyalty, RoyaltyPrice
6.31, 1, 1, 3.21,

        royOilData = DataStructure()
        th = TestHelper()
        royaltyCalc = DataStructure()

        th.load_object_csv_style(royOilData, royStringData)
        print('ProvCrownUsedRoyaltyRate:',royOilData.ProvCrownUsedRoyaltyRate)
        print('CrownMultiplier:',royOilData.CrownMultiplier)
        print(vars(royOilData))
        print(vars(royOilData).values())

        pr = ProcessRoyalties()
"""

    def test_calcSaskOilProvCrownRoyaltyVolumeValue(self):
        pr = ProcessRoyalties()
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_volume_value(
                2, 100, 1, 20, 1, 100), (20.0, 2000.0))
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_volume_value(
                -1, 100, 1, 20, 1, 100), (20.0, 2000.0))
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_volume_value(
                2, 100, 1, 5, 1, 100), (5, 500.0))
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_volume_value(
                2, 100, 1, None, 1, 100), (2.0, 200.0))
        self.assertEqual(
            pr.calc_sask_oil_prov_crown_royalty_volume_value(
                10, 120, 1, 2, 1, 120), (12, 1440.0))

        return

    def test_calcSaskOilIOGR1995(self):
        m = DataStructure()
        m.WellHeadPrice = 221.123456
        m.TransRate = 2.123455
        m.ProcessingRate = 0.123455
        m.ProdVol = 70
        m.ProdMonth = 201501

        calc = DataStructure()

        pr = ProcessRoyalties()
        #all tests for SaskWellHead
        pr.calc_sask_oil_iogr1995(datetime(2015, 1, 1), "SaskWellHead", 1.2,
                                  0.25, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 464.36)
        self.assertEqual(calc.CommencementPeriod, 0)
        self.assertEqual(calc.IOGR1995RoyaltyVolume, 7)
        self.assertEqual(calc.RoyaltyPrice, 221.123456)

        m.ProdVol = 100
        pr.calc_sask_oil_iogr1995(datetime(2015, 4, 2), "SaskWellHead", 0.25,
                                  3, m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 1990.11)
        m.ProdVol = 170
        pr.calc_sask_oil_iogr1995(datetime(2015, 5, 1), "SaskWellHead", 1, 1,
                                  m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 5881.88)
        m.ProdVol = 79.9
        pr.calc_sask_oil_iogr1995(datetime(2010, 1, 1), "SaskWellHead", 3, 2,
                                  m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 10600.66)
        m.ProdVol = 150
        pr.calc_sask_oil_iogr1995(datetime(2009, 7, 3), "SaskWellHead", 2, 4,
                                  m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 38917.73)
        m.ProdVol = 500
        pr.calc_sask_oil_iogr1995(datetime(2007, 8, 2), "SaskWellHead", 1, 5,
                                  m, calc)
        self.assertEqual(calc.IOGR1995RoyaltyValue, 124271.38)
        m.ProdVol = 800
        pr.calc_sask_oil_iogr1995(datetime(2008, 9, 9), "SaskWellHead", 5, 0.1,
                                  m, calc)

        self.assertEqual(calc.IOGR1995RoyaltyValue, 21117.29)

    def test_determineCommencementPeriod(self):
        pr = ProcessRoyalties()
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2015, 1, 1)), 0)
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2014, 12, 1)),
            0.08)
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2014, 11, 15)),
            0.13)
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2014, 1, 1)), 1)
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2014, 1, 1)), 1)
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2010, 1, 1)), 5)
        self.assertEqual(
            pr.determine_commencement_period(201501, datetime(2009, 12, 1)),
            5.09)
        self.assertEqual(pr.determine_commencement_period(201501, None), 5)
        #write tests for ActSales

    def test_calcSaskOilRegulationSubsection2(self):
        pr = ProcessRoyalties()
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(70), 7)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(100), 12)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection2(170), 26.6)

    def test_calcSaskOilRegulationSubsection3(self):
        pr = ProcessRoyalties()
        self.assertAlmostEqual(pr.calc_sask_oil_iogr_subsection3(79.9), 7.99)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(150), 22)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(500), 112.4)
        self.assertEqual(pr.calc_sask_oil_iogr_subsection3(800), 191)

    def test_determineRoyaltyPrice(self):
        m = DataStructure()
        m.WellHeadPrice = 221.123456
        m.TransRate = 2.123455
        m.ProcessingRate = 0.123455

        pr = ProcessRoyalties()
        self.assertAlmostEqual(pr.determine_royalty_price('ActSales', m),
                               223.370366)

        m.WellHeadPrice = 225
        m.TransRate = 3
        m.ProcessingRate = 1

        self.assertAlmostEqual(pr.determine_royalty_price('ActSales', m), 229)

    def test_calcGorrPercent(self):
        pr = ProcessRoyalties()

        gorr = "bad string,0,2"
        self.assertRaises(AppError, pr.calc_gorr_percent, 400, 10, gorr)
        self.assertRaises(AppError, pr.calc_gorr_percent, None, 10, gorr)

        gorr = None, "0,2"
        self.assertRaises(AttributeError, pr.calc_gorr_percent, 400, 10, gorr)

        gorr = "dprod,250,2,300,3,400,4,500,5,0,6"
        self.assertEqual(pr.calc_gorr_percent(600, 10, gorr), (
            2.0,
            'dprod = 60.000000 = 600 / 10 is greater than 0.0 and less than or equal to 250.0 for an RR of 2.0%'
        ))
        self.assertEqual(pr.calc_gorr_percent(1008, 4, gorr), (
            3.0,
            'dprod = 252.000000 = 1008 / 4 is greater than 250.0 and less than or equal to 300.0 for an RR of 3.0%'
        ))
        self.assertEqual(pr.calc_gorr_percent(400, 1, gorr), (
            4.0,
            'dprod = 400.000000 = 400 / 1 is greater than 300.0 and less than or equal to 400.0 for an RR of 4.0%'
        ))
        self.assertEqual(pr.calc_gorr_percent(990, 2, gorr), (
            5.0,
            'dprod = 495.000000 = 990 / 2 is greater than 400.0 and less than or equal to 500.0 for an RR of 5.0%'
        ))
        self.assertEqual(pr.calc_gorr_percent(10000, 17, gorr), (
            6.0,
            'dprod = 588.235294 = 10000 / 17 is greater than 500.0 for an RR of 6.0%'
        ))

        self.assertRaises(TypeError, pr.calc_gorr_percent, None, 10, gorr)

        gorr = "mprod,250,2,300,3,400,4,500,5,0,6"
        self.assertEqual(pr.calc_gorr_percent(200, 10, gorr), (
            2.0,
            'mprod = 200 is greater than 0.0 and less than or equal to 250.0 for an RR of 2.0%'
        ))
        self.assertEqual(pr.calc_gorr_percent(300, 4, gorr), (
            3.0,
            'mprod = 300 is greater than 250.0 and less than or equal to 300.0 for an RR of 3.0%'
        ))
        self.assertEqual(pr.calc_gorr_percent(350.6, 1, gorr), (
            4.0,
            'mprod = 350.6 is greater than 300.0 and less than or equal to 400.0 for an RR of 4.0%'
        ))
        self.assertEqual(pr.calc_gorr_percent(410, 2, gorr), (
            5.0,
            'mprod = 410 is greater than 400.0 and less than or equal to 500.0 for an RR of 5.0%'
        ))
        self.assertEqual(
            pr.calc_gorr_percent(10000, 17, gorr),
            (6.0, 'mprod = 10000 is greater than 500.0 for an RR of 6.0%'))

        gorr = "fixed,0,2"
        self.assertEqual(pr.calc_gorr_percent(200, 10, gorr),
                         (2.0, 'fixed for an RR of 2.0%'))
        self.assertEqual(pr.calc_gorr_percent(10000, 4, gorr),
                         (2.0, 'fixed for an RR of 2.0%'))
        #In future make this raise an error:
        self.assertEqual(pr.calc_gorr_percent(None, 10, gorr),
                         (2.0, 'fixed for an RR of 2.0%'))

    def test_calcSupplementaryRoyaltiesIOGR1995(self):
        reference_price = {
            'Pigeon Lake Indian': 24.04,
            'Reserve no.138A': 25.37,
            'Sawridge Indian': 25.13,
            'Stony Plain Indian': 24.64
        }
        pr = ProcessRoyalties()
        calc = DataStructure()

        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                3.5, 228, 80, 60, reference_price['Pigeon Lake Indian']),
            2039.6)
        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                5, 200, 90, 40, reference_price['Reserve no.138A']), 4365.75)
        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                4, 221.123456, 100, 50, reference_price['Sawridge Indian']),
            4899.84)
        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                .2, 180, 80, 35, reference_price['Stony Plain Indian']),
            3495.6)

        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                6, 228, 80, 60, reference_price['Pigeon Lake Indian']), 2996.5)
        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                5.5, 200, 90, 40, reference_price['Reserve no.138A']), 6391.38)
        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                8, 221.123456, 100, 50, reference_price['Sawridge Indian']),
            7192.5)
        self.assertEqual(
            pr.calc_supplementary_royalties_iogr1995(
                15, 180, 80, 35, reference_price['Stony Plain Indian']),
            5101.88)

    def test_process_monthly(self):
        self.dbu = DatabaseUtilities()
        self.dbu.delete_all_tables()
        self.dbu.create_some_test_well_royalty_masters()
        self.dbu.create_some_test_lease_royalty_masters()
        self.dbu.create_some_test_leases()
        self.dbu.create_some_test_monthly()
        self.dbu.create_some_test_econdata()
        self.dbu.create_calc()
        pr = ProcessRoyalties()
        pr.process_one(4, 201501, 'Oil')
コード例 #19
0
ファイル: batch.py プロジェクト: lshumlich/python-playground
def drop_create_tables():
    dbu = DatabaseUtilities()
    db_create = DatabaseCreate()

    dbu.delete_all_tables()
    db_create.create_all()
コード例 #20
0
class SqliteDatabaseTest(unittest.TestCase):

    def setUp(self):
        self.assertEqual(config.get_environment(),'unittest') # Distructive Tests must run in unittest enviornment
        self.dbi = config.get_database_instance()
        self.db = config.get_database()
        self.dbu = DatabaseUtilities()
        self.db_create = DatabaseCreate()
        
        self.dbu.delete_all_tables()
        
    def test_to_db_value(self):
        self.assertEqual('123', self.db.to_db_value(123))
        self.assertEqual('"asdf"', self.db.to_db_value("asdf"))
        self.assertEqual('123.45', self.db.to_db_value(123.45))
        self.assertEqual('1', self.db.to_db_value(True))
        self.assertEqual('0', self.db.to_db_value(False))
        self.assertEqual('null', self.db.to_db_value(None))
        
    def test_get_data_structure(self):
        ds = self.db.get_data_structure('WhatEver')
        self.assertEqual('WhatEver',ds._table_name)

    def test_select(self):
        self.dbu.create_some_test_well_royalty_masters()
        self.dbu.create_some_test_leases()
        
        self.assertIsNotNone(self.db.select('Well', RoyaltyClassification='New Oil'))
        self.assertEqual(len(self.db.select('Well', Prov='SK', Classification='Other')), 2)
        self.assertEqual(len(self.db.select('Well')), 4)
        self.assertRaises(AppError, self.db.select, 'WrongTable')
        self.assertRaises(AppError, self.db.select, 'WrongTable',WrongAttr='WhoCares')
        self.assertRaises(AppError, self.db.select, 'Well', Foo='bar')
        self.assertEqual(len(self.db.select('Lease')), 3)
        self.assertEqual(len(self.db.select('Lease', Prov='SK')), 3)
        self.assertEqual(len(self.db.select('Well', ID=1000)),0)
        
    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_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_delete(self):
        self.dbu.create_some_test_well_royalty_masters()

        self.assertEqual(4,len(self.db.select('Well')))
                         
        self.db.delete('Well', 2)
        self.assertEqual(3,len(self.db.select('Well')))
        self.assertEqual(0, len(self.db.select('Well', ID=2)))
        
    def test_date_format(self):
        self.dbu.create_some_test_well_royalty_masters()
        
        well = self.db.select('Well', ID=1)
        self.assertTrue(isinstance(well[0].CommencementDate,datetime))
コード例 #21
0
ファイル: batch.py プロジェクト: lshumlich/python-playground
def load_sample_data():
    dbu = DatabaseUtilities()
    drop_create_tables()
    dbu.create_some_test_well_royalty_masters()
    dbu.create_some_test_leases()
コード例 #22
0
    def test_all(self):
        dbu = DatabaseUtilities()
        dbc = DatabaseCreate()

        dbu.delete_all_tables()
        dbc.create_all()