def tearDown(self) -> None: """ Cleanup test server """ clear_all(fiware_header=self.fiware_header, cb_url=settings.CB_URL, iota_url=[settings.IOTA_JSON_URL, settings.IOTA_UL_URL])
def setUp(self) -> None: self.fiware_header = FiwareHeader( service=settings.FIWARE_SERVICE, service_path=settings.FIWARE_SERVICEPATH) clear_all(fiware_header=self.fiware_header, cb_url=settings.CB_URL, iota_url=settings.IOTA_JSON_URL) self.service_group1 = ServiceGroup(entity_type='Thing', resource='/iot/json', apikey=str(uuid4())) self.service_group2 = ServiceGroup(entity_type='OtherThing', resource='/iot/json', apikey=str(uuid4())) self.device = { "device_id": "test_device", "service": self.fiware_header.service, "service_path": self.fiware_header.service_path, "entity_name": "test_entity", "entity_type": "test_entity_type", "timezone": 'Europe/Berlin', "timestamp": None, "apikey": "1234", "endpoint": None, "transport": 'HTTP', "expressionLanguage": None } self.client = IoTAClient( url=settings.IOTA_JSON_URL, fiware_header=self.fiware_header)
def tearDown(self) -> None: """ Cleanup test server """ self.client.close() clear_all(fiware_header=self.fiware_header, cb_url=settings.CB_URL, iota_url=settings.IOTA_JSON_URL)
def setUp(self) -> None: """ Setup test data Returns: None """ self.fiware_header = FiwareHeader( service=settings.FIWARE_SERVICE, service_path=settings.FIWARE_SERVICEPATH) clear_all(fiware_header=self.fiware_header, cb_url=settings.CB_URL, iota_url=settings.IOTA_JSON_URL) self.resources = { "entities_url": "/v2/entities", "types_url": "/v2/types", "subscriptions_url": "/v2/subscriptions", "registrations_url": "/v2/registrations" } self.attr = {'temperature': {'value': 20.0, 'type': 'Number'}} self.entity = ContextEntity(id='MyId', type='MyType', **self.attr) self.client = ContextBrokerClient( url=settings.CB_URL, fiware_header=self.fiware_header) self.subscription = Subscription.parse_obj({ "description": "One subscription to rule them all", "subject": { "entities": [ { "idPattern": ".*", "type": "Room" } ], "condition": { "attrs": [ "temperature" ], "expression": { "q": "temperature>40" } } }, "notification": { "http": { "url": "http://localhost:1234" }, "attrs": [ "temperature", "humidity" ] }, "expires": datetime.now(), "throttling": 0 })
def tearDown(self) -> None: """ Cleanup test server """ self.clear_registry() clear_all(fiware_header=FiwareHeader( service=settings.FIWARE_SERVICE, service_path=settings.FIWARE_SERVICEPATH), cb_url=settings.CB_URL, iota_url=settings.IOTA_JSON_URL)
def tearDown(self) -> None: # Cleanup test server with ContextBrokerClient(url=settings.CB_URL) as client: client.fiware_service = settings.FIWARE_SERVICE for path in self.service_paths: header = FiwareHeader(service=settings.FIWARE_SERVICE, service_path=path) clear_all(fiware_header=header, cb_url=settings.CB_URL) client.close()
def tearDown(self) -> None: """ Clean up server Returns: None """ clear_all(fiware_header=self.fiware_header, cb_url=settings.CB_URL, ql_url=settings.QL_URL) self.ql_client.close() self.cb_client.close()
def tearDown(self) -> None: """ Cleanup test server """ clear_all(fiware_header=self.fiware_header, cb_url=settings.CB_URL)
logging.basicConfig(level='INFO', format='%(asctime)s %(name)s %(levelname)s: %(message)s') logger = logging.getLogger(__name__) if __name__ == "__main__": # ## 1 Setup # # A QuantumLeapClient and a ContextBrokerClient are created to access # FIWARE in the space given by the FiwareHeader. For more information see: # e01_http_clients.py fiware_header = FiwareHeader(service=SERVICE, service_path=SERVICE_PATH) # clear all existing data clear_all(fiware_header=fiware_header, cb_url=CB_URL, ql_url=QL_URL) ql_client = QuantumLeapClient(url=QL_URL, fiware_header=fiware_header) print("Quantum Leap " + ql_client.get_version()["version"] + " at url " + ql_client.base_url) cb_client = ContextBrokerClient(url=CB_URL, fiware_header=fiware_header) print("Context broker version " + cb_client.get_version()["orion"]["version"] + " at url " + cb_client.base_url) # ## 2 Interact with QL # # ### 2.1 Create a ContextEntity to work with #
To run this example you need a working Fiware v2 setup with a context-broker and an iota-broker. You can here set the addresses: """ cb_url = "http://localhost:1026" iota_url = "http://localhost:4041" if __name__ == '__main__': # # 0 Clean up Fiware state: # # For this example to work the fiware state needs to be clean: from filip.models.base import FiwareHeader from filip.utils.cleanup import clear_all fiware_header = FiwareHeader(service="example", service_path="/") clear_all(fiware_header=fiware_header, cb_url=cb_url, iota_url=iota_url) # # 1 Import Models # # First we need to import the models that we have created in the # "semantics_vocabulary_example" and exported into the file "models.py". # Each vocabulary class was converted to a python class and can now be # instantiated. # Additionally the class semantic_manager is created and will be used to # manage the local state as well as save it. # It is important that we only import one vocabulary model file, # if we want to use multiple models, we need to combine them in a # vocabulary and export them as one file. # We can import the classes selectively or all at once from models import semantic_manager