コード例 #1
0
def test_execute_with_insights(_mock1, _mock2, _mock3):
    """Test the function execute."""
    with open("tests/v2/data/stack_aggregator_execute_input.json", "r") as f:
        payload = json.load(f)

    r = RecommendationTask()
    out = r.execute(arguments=payload, persist=False, check_license=False)

    assert out['recommendation'] == "success"
コード例 #2
0
    def test_call_insights_recommender_npm(self, _mock_get, _mock_post):
        """Test if the correct service is called for the correct ecosystem."""
        with mock.patch.dict(
                'src.v2.recommender.os.environ', {
                    'GOLANG_SERVICE_HOST': 'golang-insights',
                    'CHESTER_SERVICE_HOST': 'npm-insights',
                    'PYPI_SERVICE_HOST': 'pypi-insights',
                    'PGM_SERVICE_HOST': 'pgm',
                    'PGM_SERVICE_PORT': '6006',
                    'HPF_SERVICE_HOST': 'hpf-insights',
                }):
            # Test whether the correct service is called for NPM.
            called_url_json = RecommendationTask.call_insights_recommender([{
                "ecosystem":
                "npm"
            }])
            self.assertTrue('npm-insights' in called_url_json['url'])
            # Test whether the correct service is called for PYPI.
            called_url_json = RecommendationTask.call_insights_recommender([{
                "ecosystem":
                "pypi"
            }])
            self.assertTrue('pypi-insights' in called_url_json['url'])
            # Test whether the correct service is called for golang.
            called_url_json = RecommendationTask.call_insights_recommender([{
                "ecosystem":
                "golang"
            }])
            self.assertTrue('golang-insights' in called_url_json['url'])
            # Now test whether the correct service is called for maven.
            called_url_json = RecommendationTask.call_insights_recommender([{
                "ecosystem":
                "maven",
                "package_list": []
            }])
            self.assertTrue('pgm' in called_url_json['url'])

            called_url_json = RecommendationTask.call_insights_recommender([{
                "ecosystem":
                "maven",
                "package_list": ["org.slf4j:slf4j-api"]
            }])
            self.assertTrue('hpf-insights' in called_url_json['url'])
コード例 #3
0
def test_execute_both_resolved_type(_mock_call_insights, _mock_db):
    """Test the function execute."""
    with open("tests/v2/data/stack_aggregator_combined_input.json", "r") as f:
        payload = json.load(f)

    r = RecommendationTask()
    out = r.execute(arguments=payload, persist=False)
    assert out['recommendation'] == "success"
    r = RecommendationTask()
    out = r.execute(arguments=payload, check_license=True, persist=False)
    assert out['recommendation'] == "success"

    out = r.execute(arguments=payload, persist=True)
    _mock_db.assert_called_once()
コード例 #4
0
def test_execute_empty_resolved(_mock_call_insights, _mock_db):
    """Test the function execute."""
    with open("tests/v2/data/stack_aggregator_empty_resolved.json", "r") as f:
        payload = json.load(f)

    r = RecommendationTask()
    out = r.execute(arguments=payload, persist=False)

    assert out['recommendation'] == "success"
    assert not out["result"]["companion"]
    assert not out["result"]["usage_outliers"]

    r = RecommendationTask()
    out = r.execute(arguments=payload, check_license=True, persist=False)
    assert out['recommendation'] == "success"

    out = r.execute(arguments=payload, persist=True)
    _mock_db.assert_called_once()