示例#1
0
    def test_get_source_id_from_applications_id_server_error(self):
        """Test to get source ID from application resource_id with server error."""
        resource_id = 2

        client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id)
        with requests_mock.mock() as m:
            m.get(f"http://www.sources.com/api/v1.0/applications?filter[id]={resource_id}", status_code=400)
            with self.assertRaises(SourcesHTTPClientError):
                client.get_source_id_from_applications_id(resource_id)
示例#2
0
    def test_get_source_id_from_applications_id_misconfigured(self):
        """Test to get source_id from application resource_id with route not found."""
        resource_id = 2
        source_id = 3

        client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=source_id)
        with requests_mock.mock() as m:
            m.get(
                f"http://www.sources.com/api/v1.0/applications?filter[id]={resource_id}",
                status_code=404,
                json={"data": [{"id": resource_id}]},
            )
            with self.assertRaises(SourceNotFoundError):
                client.get_source_id_from_applications_id(resource_id)
示例#3
0
def cost_mgmt_msg_filter(msg_data):
    """Verify that message is for cost management."""
    event_type = msg_data.get("event_type")
    auth_header = msg_data.get("auth_header")

    if event_type in (KAFKA_APPLICATION_DESTROY, KAFKA_SOURCE_DESTROY):
        return msg_data

    if event_type in (KAFKA_AUTHENTICATION_CREATE,
                      KAFKA_AUTHENTICATION_UPDATE):
        sources_network = SourcesHTTPClient(auth_header)

        if msg_data.get("resource_type") == "Application":
            source_id = sources_network.get_source_id_from_applications_id(
                msg_data.get("resource_id"))
        msg_data["source_id"] = source_id
        if not sources_network.get_application_type_is_cost_management(
                source_id):
            LOG.info(
                f"Resource id {msg_data.get('resource_id')} not associated with cost-management."
            )
            return None
    else:
        source_id = msg_data.get("source_id")

    return msg_data
示例#4
0
    def test_get_source_id_from_applications_id_no_data(self):
        """Test to get source_id from application resource_id with no data in response."""
        resource_id = 2
        source_id = 3

        client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=source_id)
        with requests_mock.mock() as m:
            m.get(
                f"http://www.sources.com/api/v1.0/applications?filter[id]={resource_id}",
                status_code=200,
                json={"data": []},
            )
            self.assertIsNone(client.get_source_id_from_applications_id(resource_id))