示例#1
0
def test_is_quickstart_majority():
    """Test the function is_quickstart_majority."""
    package_list = []
    assert is_quickstart_majority(package_list)
    package_list = ['io.vertx:vertx-core',
                    'org.springframework.boot:spring-boot-starter-web',
                    'org.slf4j:slf4j-api']
    assert is_quickstart_majority(package_list)
    package_list = ['org.slf4j:slf4j-api']
    assert not is_quickstart_majority(package_list)
    def get_insights_url(payload):
        """Get the insights url based on the ecosystem."""
        if payload and 'ecosystem' in payload[0]:
            quickstarts = False
            if payload[0]['ecosystem'] in RecommendationTask.chester_ecosystems:
                INSIGHTS_SERVICE_HOST = os.getenv("CHESTER_SERVICE_HOST")
            elif payload[0]['ecosystem'] in RecommendationTask.pypi_ecosystems:
                INSIGHTS_SERVICE_HOST = os.getenv("PYPI_SERVICE_HOST")
            elif payload[0]['ecosystem'] in RecommendationTask.golang_ecosystem:
                INSIGHTS_SERVICE_HOST = os.environ.get("GOLANG_SERVICE_HOST")
            else:
                INSIGHTS_SERVICE_HOST = os.getenv("HPF_SERVICE_HOST") + "-" + payload[0][
                    'ecosystem']
                if payload[0]['ecosystem'] == 'maven':
                    quickstarts = is_quickstart_majority(payload[0]['package_list'])
                if quickstarts:
                    INSIGHTS_SERVICE_HOST = os.getenv("PGM_SERVICE_HOST") + "-" + payload[0][
                        'ecosystem']

            INSIGHTS_URL_REST = "http://{host}:{port}".format(host=INSIGHTS_SERVICE_HOST,
                                                              port=os.getenv("PGM_SERVICE_PORT"))

            if quickstarts:
                insights_url = INSIGHTS_URL_REST + "/api/v1/schemas/kronos_scoring"
            else:
                insights_url = INSIGHTS_URL_REST + "/api/v1/companion_recommendation"

            return insights_url

        else:
            logger.error('Payload information not passed in the call, Quitting! inights '
                         'recommender\'s call')