示例#1
0
文件: main.py 项目: a-liut/fogflow
def rest_client():
    data = request.get_json()
    configobj = config_data()
    fog_url = configobj.get_fogflow_subscription_endpoint()
    url = constant.http + fog_url + constant.subscribe_uri
    payload = json.dumps(data)
    robj = Rest_client(url, payload)
    r = robj.post_request()
    return "subscribe"
示例#2
0
 def test_mock_post(self,mock_get):
     mock_get.return_value.status_code = 201
     configobj=config_data()
     entity_url=configobj.get_entity_url()
     url1 =constant.http+entity_url+constant.entity_uri
     payload=data.convert_data_output
     payload=json.dumps(payload)
     obj=Rest_client(url1,payload)
     response=obj.post_request()
     self.assertEqual(response.status_code, 201)
示例#3
0
文件: test.py 项目: a-liut/fogflow
 def test_mock_post(self):
     with patch('common_utilities.rest_client.requests.post') as mock_get:
         mock_get.return_value.status_code = 201
         configobj = config_data()
         entity_url = configobj.get_entity_url()
         url1 = constant.http + entity_url + constant.entity_uri
         payload = convert_data_output
         obj = Rest_client(url1, payload)
         response = obj.post_request()
     self.assertEqual(response.status_code, 201)
示例#4
0
 def test_mock_patch(self,mock_get):
     mock_get.return_value.status_code = 204
     obj=ngsi_data_creation(data.ngsi_data)
     entity_id=obj.get_entityId()
     configobj=config_data()
     entity_url=configobj.get_entity_url()
     url=constant.http+entity_url+constant.entity_uri+entity_id+'/attrs'
     payload=data.patch_data_output
     payload=json.dumps(payload)
     obj=Rest_client(url,payload)
     response=obj.patch_request()
     self.assertEqual(response.status_code, 204)
示例#5
0
def rest_client():
    logger_obj = Handler()
    logger = logger_obj.get_logger()
    data = request.get_json()
    configobj = config_data()
    fog_url = configobj.get_fogflow_subscription_endpoint()
    url = constant.http + fog_url + constant.subscribe_uri
    payload = json.dumps(data)
    robj = Rest_client(url, payload)
    r = robj.post_request()
    logger.info("Forwarded Subscription to Fogflow.")
    return "subscribe"
示例#6
0
文件: test.py 项目: a-liut/fogflow
 def test_mock_patch(self):
     with patch('common_utilities.rest_client.requests.patch') as mock_get:
         mock_get.return_value.status_code = 204
         obj = ngsi_data_creation(ngsi_data)
         entity_id = obj.get_entityId()
         configobj = config_data()
         entity_url = configobj.get_entity_url()
         url = constant.http + entity_url + constant.entity_uri + entity_id + '/attrs'
         payload = patch_data_output
         obj = Rest_client(url, payload)
         response = obj.patch_request()
     self.assertEqual(response.status_code, 204)
示例#7
0
def noify_server():
    data = request.get_json()
    #print(data)
    dataObj = ngsi_data_creation(data)
    context = dataObj.get_ngsi_ld()
    patch_context = copy.deepcopy(context)
    del patch_context['type']
    del patch_context['id']
    entity_id = dataObj.get_entityId()
    configobj = config_data()
    entity_url = configobj.get_entity_url()
    url1 = 'http://' + entity_url + constant.entity_uri
    url2 = 'http://' + entity_url + constant.entity_uri + entity_id + '/attrs'
    #print(url1)
    if entity_id in File_data.keys():
        payload = json.dumps(patch_context)
        robj = Rest_client(url2, payload)
        r = robj.patch_request()
    else:
        payload = json.dumps(context)
        robj = Rest_client(url1, payload)
        r = robj.post_request()
        if r.status_code == 201:
            id_file = open("data_model/storage/data_file.txt", 'a+')
            id_file.write(entity_id + '\n')
            File_data[entity_id] = 1
            id_file.close()
    return "notify"
示例#8
0
 def data_convert_invoker(self, context, dataObj):
     self.logger.info("data_convert_invoker has been started")
     patch_context = copy.deepcopy(context)
     del patch_context["type"]
     del patch_context["id"]
     entity_id = dataObj.get_entityId()
     configobj = config_data()
     entity_url = configobj.get_entity_url()
     url1 = constant.http + entity_url + constant.entity_uri
     url2 = constant.http + entity_url + constant.entity_uri + entity_id + '/attrs'
     if entity_id in File_data.keys():
         self.logger.debug("sending update request")
         payload = json.dumps(patch_context)
         robj = Rest_client(url2, payload)
         r = robj.patch_request()
         if r.status_code == constant.update_status:
             self.logger.debug("Entity has been updated to NGB")
     else:
         self.logger.debug("Sending create request")
         payload = json.dumps(context)
         robj = Rest_client(url1, payload)
         r = robj.post_request()
         if r.status_code == constant.create_status:
             self.logger.debug("Entity has been created in NGB")
             id_file = open("data_model/storage/data_file.txt", 'a+')
             id_file.write(entity_id + '\n')
             File_data[entity_id] = 1
             id_file.close()
     self.logger.info("data_convert_invoker has been end")