Exemplo n.º 1
0
def post_entity_context_update(oc: pyfiware.OrionConnector, entity_id: str,
                               element_type: str, data: Dict):
    device = oc.get(entity_id=entity_id)
    if device:
        oc.patch(element_id=entity_id,
                 element_type=element_type,
                 attributes={
                     'type': 'StructuredValue',
                     'value': data,
                     "metadata": {}
                 })

        device = oc.get(entity_id=entity_id)
        print(device)
Exemplo n.º 2
0
class TestFiwareManagerPatch(TestCase):
    url = "http://127.0.0.1:1026"

    def setUp(self):
        self.fiware_manager = OrionConnector(self.url)

    @patch.object(OrionConnector, "_request",
                  Mock(return_value=DummyResponse(status=204, data='')))
    def test_patch_success(self):
        attributes = {
            "temperature": {
                "value": 26.5,
                "type": "Float"
            },
            "pressure": {
                "value": 763,
                "type": "Float"
            }
        }

        self.fiware_manager.patch(element_id="1",
                                  element_type="FAKE",
                                  **attributes)
        self.fiware_manager._request.assert_called_with(
            method='PATCH',
            url=self.url + '/v2/entities/' + "1" + "/attrs" + "?type=" +
            "FAKE",
            body={
                "pressure": {
                    "value": 763,
                    "type": "Float"
                },
                "temperature": {
                    "value": 26.5,
                    "type": "Float"
                }
            },
            headers={
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            },
        )

    @patch.object(OrionConnector, "_request",
                  Mock(return_value=DummyResponse(status=404, data='')))
    def test_patch_fails(self):
        attributes = {
            "temperature": {
                "value": 26.5,
                "type": "Float"
            },
            "pressure": {
                "value": 763,
                "type": "Float"
            }
        }

        with self.assertRaises(FiException):
            self.fiware_manager.patch(element_id="1",
                                      element_type="FAKE",
                                      **attributes)