Пример #1
0
    def test_get_entities_with_type(self):
        test_entity = Materialflow()
        test_entity_2 = Materialflow()

        self.context_broker_handler.create_entity(test_entity)
        self.context_broker_handler.create_entity(test_entity_2)

        entities = self.context_broker_handler.get_entities(
            entity_type="Materialflow")

        self.assertEqual(len(entities), 2)
        self.assertEqual(entities[0]["id"], test_entity.id)
        self.assertEqual(entities[1]["id"], test_entity_2.id)
Пример #2
0
    def test_get_entities_with_id(self):
        test_entity = Materialflow()
        test_entity_2 = Materialflow()

        self.context_broker_handler.create_entity(test_entity)
        self.context_broker_handler.create_entity(test_entity_2)

        entity = self.context_broker_handler.get_entities(
            entity_id=test_entity.id)
        self.assertEqual(entity["id"], test_entity.id)

        entity = self.context_broker_handler.get_entities(
            entity_id=test_entity_2.id)
        self.assertEqual(entity["id"], test_entity_2.id)
 def test_create_entity_without_error(self):
     test_entity = Materialflow()
     try:
         self.context_broker_handler.create_entity(test_entity)
     except Exception:
         self.fail(
             "create_entity raised an Exception which should not happen!")
Пример #4
0
    def test_retreive_with_materialflow(self):
        test_interface = TestBrokerInterface("id", "broker_name")
        self.broker_connector.register_interface(test_interface)

        materialflow = Materialflow()
        self.broker_connector.retreive(materialflow, test_interface)

        self.assertEqual(my_globals.taskQueue.qsize(), 1)
 def test_delete_entity_without_error(self):
     test_entitiy = Materialflow()
     try:
         self.context_broker_handler.published_entities.append("uuid")
         self.context_broker_handler.delete_entity("uuid")
     except Exception:
         self.fail(
             "delete_entity raised and Exception which should not happen!")
Пример #6
0
    def test_update_entity(self):
        test_entity = Materialflow()
        self.context_broker_handler.create_entity(test_entity)

        response = requests.request("GET", ENTITY_ADDRESS)
        self.assertEqual(response_is_ok(response.status_code), True)

        content = json.loads(response.content.decode("utf-8"))
        self.assertEqual(content[0]["active"]["value"], False)

        test_entity.active = True
        self.context_broker_handler.update_entity(test_entity)

        response = requests.request("GET", ENTITY_ADDRESS)
        self.assertEqual(response_is_ok(response.status_code), True)

        content = json.loads(response.content.decode("utf-8"))
        self.assertEqual(content[0]["active"]["value"], True)
Пример #7
0
    def test_create_entity(self):
        test_entitiy = Materialflow()
        self.context_broker_handler.create_entity(test_entitiy)
        response = requests.request("GET", ENTITY_ADDRESS)

        self.assertEqual(response_is_ok(response.status_code), True)

        content = json.loads(response.content.decode("utf-8"))
        materialflow_schema = open(
            "./tasksupervisor/endpoint/fiware_orion/flask/materialflow_schema.json"
        )

        self.validate_schema(content[0],
                             json.loads(materialflow_schema.read()))
        materialflow_schema.close()
Пример #8
0
    def test_subscribe_generic(self):
        materialflow = Materialflow()
        context_broker_handler = self.orion_interface.context_broker_handler

        with patch.object(context_broker_handler,
                          "subscribe_to_entity") as mock:
            self.orion_interface.subscribe(materialflow, generic=True)

        expected_notification = my_globals.parsed_config_file.get_taskplanner_address(
        ) + "/materialflow"
        expected_description = "Materialflow subscription"
        expected_entity = [{"id": materialflow.id, "type": "Materialflow"}]
        mock.assert_called_with(expected_description,
                                expected_entity,
                                expected_notification,
                                generic=True)
Пример #9
0
    def test_delete_entity(self):
        test_entity = Materialflow()

        self.assertRaises(BrokerException,
                          self.context_broker_handler.delete_entity,
                          test_entity.id)

        self.context_broker_handler.create_entity(test_entity)
        try:
            self.context_broker_handler.delete_entity(test_entity.id)
        except BrokerException as brokerException:
            self.fail("Fail")

        response = requests.request("GET", ENTITY_ADDRESS)
        self.assertEqual(response_is_ok(response.status_code), True)

        content = json.loads(response.content.decode("utf-8"))
        self.assertEqual(content, [])
Пример #10
0
    def test_materialflow_endpoint(self):
        topic = Materialflow()
        entities = [{"id": topic.id, "type": "Materialflow"}]
        notification = SUPERVISOR_ADDRESS + "/materialflow"
        TestOrionEndpoints.context_broker_handler.subscribe_to_entity(
            "description", entities, notification, generic=True)
        time.sleep(3)
        requests.request("POST",
                         ENTITY_ADDRESS,
                         data=json.dumps(MF_DUMMY),
                         headers=HEADER)
        time.sleep(3)

        interface_data = TestOrionEndpoints.dummy_interface.data

        self.assertIsInstance(interface_data, dict)
        self.assertTrue("data" in interface_data)
        self.assertEqual(len(interface_data["data"]), 1)
        self.assertTrue("id" in interface_data["data"][0])
        self.assertEqual(interface_data["data"][0]["id"], "mf_id")
Пример #11
0
 def test_subscribe_sub_dict(self):
     materialflow = Materialflow()
     self.orion_interface.subscribe(materialflow)
     self.assertTrue("sub_id" in self.orion_interface.subscription_dict)
     self.assertEqual(self.orion_interface.subscription_dict["sub_id"],
                      "Materialflow")
 def test_create_entity_creation(self):
     test_entity = Materialflow()
     self.context_broker_handler.create_entity(test_entity)
     self.assertEqual(len(self.context_broker_handler.published_entities),
                      1)
 def test_create_entity_with_error(self):
     test_entitiy = Materialflow()
     self.assertRaises(BrokerException,
                       self.context_broker_handler.create_entity,
                       test_entitiy)
 def test_delete_entity_deletion(self):
     test_entitiy = Materialflow()
     self.context_broker_handler.published_entities.append("uuid")
     self.context_broker_handler.delete_entity("uuid")
     self.assertEqual(len(self.context_broker_handler.published_entities),
                      0)