def test_query_facility_id(self):
     test_query = '''query{
     metadata {
         facilities(referenceId:"18116481"){
             name
             id
             created
             createdBy
             referenceId
             code
             type
             aliases {
                 name
                 code
                 description
             }
         }
     
     }
 }'''
     authInfo = auth.AuthInfo()
     try:
         authInfo.init_from_env_vars()
         authObj = auth.Authenticate(authInfo)
         token = authObj.authenticate()
         query_obj = graph.Graph(token)
         result = query_obj.query(test_query)
     except Exception as err:
         self.fail("Query failed with error:" + str(err))
コード例 #2
0
 def setUp(self):
     authInfo=auth.AuthInfo()
     try:
         authInfo.init_from_env_vars()
         authObj=auth.Authenticate(authInfo) 
         self.token=authObj.authenticate()
     except Exception as err:
         self.fail("Failed in getting token:"+str(err))
    def test_auth_from_env_variable(self):
        authInfo = auth.AuthInfo()
        authInfo.init_from_env_vars()
        authObj = auth.Authenticate(authInfo)
        try:
            token = authObj.authenticate()

        except Exception as err:
            self.fail('Expected not an exception but got it' + str(err))
コード例 #4
0
    def setUp(self):

        authInfo=auth.AuthInfo()
        try:
            authInfo.init_from_config_file('./test/config_auth.json')
            authObj=auth.Authenticate(authInfo) 
            self.token=authObj.authenticate()
            self.subscriptionKey=authInfo.subscriptionKey
            self.graphUrl=authInfo.graphUrl
        except Exception as err:
            self.fail("Failed in getting token:"+str(err)) 
 def test_validatereport(self):
     authInfo=auth.AuthInfo()
     ddrmlFile = os.path.join(os.path.dirname(__file__)+"/data/", 'test_ddrml_report.xml')
     try:
         authInfo.init_from_env_vars()
         authObj=auth.Authenticate(authInfo) 
         token=authObj.authenticate()
         report=reports.Reports(
         token)
         result=report.validate(reports.ReportType.DDRML,
         ddrmlFile)
     except Exception as err:
         self.fail("Failed with error:"+str(err)) 
 def test_authinfo(self):
     clientId = "clientId"
     clientSecret = "clientSecret"
     tokenUrl = "tokenUrl"
     resourceId = "resourceId"
     subscriptionKey = "subscriptionKey"
     authObj = auth.AuthInfo(clientId, clientSecret, tokenUrl, resourceId,
                             subscriptionKey)
     self.assertEqual(authObj.clientId, clientId)
     self.assertEqual(authObj.clientSecret, clientSecret)
     self.assertEqual(authObj.tokenUrl, tokenUrl)
     self.assertEqual(authObj.resourceId, resourceId)
     self.assertEqual(authObj.subscriptionKey, subscriptionKey)
    def test_query_field_name_to_file(self):
        test_query = '''query{
                metadata {
                    fields(name:"OSEBERG"){
                        name
                        id
                        status
                        created
                        createdBy
                        validFrom
                        validTo
                        description
                        code 
                        country
                        referenceId
                        license {
                            name

                        }
                        wells{
                            name
                            referenceId
                        
                            
                        }
                        platforms {
                            name
                            referenceId
                        }
                    
                        wellbores{
                            name
                            referenceId
                        }
                    
                    }
                    
                }
                
            }'''
        authInfo = auth.AuthInfo()
        result_file = os.path.join(
            os.path.dirname(__file__) + "/data/", 'field_result.json')
        try:
            authInfo.init_from_env_vars()
            authObj = auth.Authenticate(authInfo)
            token = authObj.authenticate()
            query_obj = graph.Graph(token)
            query_obj.query_to_file(test_query, result_file)
        except Exception as err:
            self.fail("Query failed with error:" + str(err))
def drilling(datatype, format, start, end, wellbore, output, log, debug,
             rolldays, decimalformat):
    __initialize_logging(log, debug)
    logging.info(
        "Extracting data for - dataType:%s, format:%s, start:%s, end:%s, wellbore:%s, output:%s",
        datatype, format, start, end, wellbore, output)
    toDate = end
    fromDate = start
    #get the token first
    authInfo = auth.AuthInfo()
    authInfo.init_from_env_vars()
    try:
        #create the filepath if not existing
        common_utils.create_filepath_if_not_exists(output)

        authObj = auth.Authenticate(authInfo)
        token = authObj.authenticate()
        dObj = subsurfaceDrilling.DrillingData(token)
        #map the datatype
        type_enum = dObj.map_str_activity_to_enum(datatype)
        #handle rolldays
        if rolldays > 0:
            toDate = common_utils.format_date_to_yy_mm_dd(
                common_utils.add_days(datetime.today(), 1))
            fromDate = common_utils.format_date_to_yy_mm_dd(
                common_utils.substract_days(datetime.today(), rolldays))
        #need to handle the format
        if format == 'json':
            #handle json
            dObj.get_json_data_to_file(output, fromDate, toDate, wellbore,
                                       type_enum)
            logging.info("Data written to:%s", output)
        elif format == 'xml':
            dObj.get_xml_data(output, fromDate, toDate, wellbore, type_enum)
            logging.info("Data written to:%s", output)
        elif format == 'csv':
            #handle csv
            dObj.get_csv_data(output, fromDate, toDate, wellbore, type_enum,
                              decimalformat)
            logging.info("Data written to:%s", output)
        elif format == 'excel':
            #handle excel
            dObj.get_excel_data(output, fromDate, toDate, wellbore, type_enum)
            logging.info("Data written to:%s", output)
        else:
            logging.info("Unknown format...")
    except Exception as err:
        logging.error("Failed in processing of drilling data:%s",
                      str(err),
                      exc_info=True)
def publish(reporttype, reportfile, log, debug):
    __initialize_logging(log, debug)
    logging.info("Publishing report type:%s, file:%s", reporttype, reportfile)
    #get the token first
    authInfo = auth.AuthInfo()
    authInfo.init_from_env_vars()
    try:
        authObj = auth.Authenticate(authInfo)
        token = authObj.authenticate()
        report = reports.Reports(token)
        #map the report type to the enum
        reportEnum = report.map_str_reporttype_to_enum(reporttype)
        #submit it
        result = report.publish(reportEnum, reportfile)
        logging.info("Published report, response:%s", str(result))
    except Exception as err:
        logging.error("Failed in publish:%s", str(err), exc_info=True)
 def test_authenticate_fail_missing_authinfo(self):
     logging.disable(
         logging.CRITICAL
     )  #disable error logging for this case as it should fail
     clientId = "clientId"
     clientSecret = "clientSecret"
     tokenUrl = "tokenUrl"
     resourceId = "resourceId"
     subscriptionKey = "subscriptionKey"
     authObj = auth.AuthInfo(clientId, clientSecret, tokenUrl, resourceId,
                             subscriptionKey)
     authObj = auth.Authenticate(authObj)
     try:
         authObj.authenticate()
         self.fail('Expected an exception but got data...')
     except Exception as err:
         self.assertEqual(1, 1)
    def test_query_drilling_activities(self):
        query = '''
        query {
  drilling {
    drillingActivity(
      limit: 1000
      period_after: "2020-03-21T23:00:00.000Z"
      period_before: "2020-03-26T12:00:00.000Z"
    ) {
      created
      modified
      endTime
      startTime
      dataStartTime
      dataEndTime
      dataEntity {
        name
        type
      }
     conveyance
     state
     stateDetailActivity
     phase
     proprietaryCode
     comment
    
     
   
  }
  }
}
        '''
        authInfo = auth.AuthInfo()
        result_file = os.path.join(
            os.path.dirname(__file__) + "/data/",
            'drilling_activities_result.json')
        try:
            authInfo.init_from_env_vars()
            authObj = auth.Authenticate(authInfo)
            token = authObj.authenticate()
            query_obj = graph.Graph(token)
            query_obj.query_to_file(query, result_file)
        except Exception as err:
            self.fail("Query failed with error:" + str(err))
コード例 #12
0
def production(datatype, format, start, end, asset, output, log, debug,
               rolldays, product, decimalformat, reporttype, filter):
    __initialize_logging(log, debug)
    logging.info(
        "Extracting data for - dataType:%s, format:%s, start:%s, end:%s, asset:%s, output:%s, reporttype:%s",
        datatype, format, start, end, asset, output, reporttype)
    if reporttype == 'ANY':
        reporttype = ''
    fromDate = start
    toDate = end
    #check if we need to add some additional signs to the data type in case it is a single query
    if datatype.find(',') != -1:
        splitted = datatype.split(',')
        tempType = ''
        i = 0
        for item in splitted:
            if i == 0:
                tempType = '"' + item + '"'
            else:
                tempType = tempType + ',"' + item + '"'
            i = +1
        datatype = tempType

    else:
        datatype = '"' + datatype + '"'
    #get the token first
    authInfo = auth.AuthInfo()
    authInfo.init_from_env_vars()
    try:
        #create the filepath if not existing
        common_utils.create_filepath_if_not_exists(output)
        authObj = auth.Authenticate(authInfo)
        token = authObj.authenticate()
        pObj = subsurfaceProduction.ProductionData(token)
        #map the datatype
        #need to check if we should just rolldays
        if rolldays > 0:
            toDate = common_utils.format_date_to_yy_mm_dd(
                common_utils.add_days(datetime.today(), 1))
            fromDate = common_utils.format_date_to_yy_mm_dd(
                common_utils.substract_days(datetime.today(), rolldays))
        #need to handle the format
        if format == 'json':
            #handle json
            pObj.get_json_data_to_file(output, fromDate, toDate, asset,
                                       datatype, product, reporttype, filter)
            logging.info("Data written to:%s", output)
        elif format == 'xml':
            pObj.get_xml_data(output, fromDate, toDate, asset, datatype,
                              product, reporttype)
            logging.info("Data written to:%s", output)
        elif format == 'csv':
            #handle csv
            pObj.get_csv_data(output, fromDate, toDate, asset, datatype,
                              product, decimalformat, reporttype, filter)
            logging.info("Data written to:%s", output)
        elif format == 'excel':
            #handle excel
            pObj.get_excel_data(output, fromDate, toDate, asset, datatype,
                                product, reporttype, filter)
            logging.info("Data written to:%s", output)
        else:
            logging.info("Unknown format...")

    except Exception as err:
        logging.error("Failed in processing of production data:%s",
                      str(err),
                      exc_info=True)
 def test_auth_init_from_config(self):
     authInfo = auth.AuthInfo()
     authInfo.init_from_config_file('./test/config_auth_test.json')