def test_call_insights_recommender_npm(self, _mock_get, _mock_post): """Test if the correct service is called for the correct ecosystem.""" with app.app_context(): # 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'])
def test_execute_with_insights(_mock1, _mock2, _mock3): """Test the function execute.""" with open("tests/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"
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.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'])
def test_execute(_mock_call_insights): """Test the function execute.""" f = open("tests/data/stack_aggregator_execute_input.json", "r") payload = json.loads(f.read()) 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) assert out['recommendation'] == "database error"
def test_execute(_mock_call_insights, _mock_db): """Test the function execute.""" with open("tests/data/stack_aggregator_execute_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()
def test_execute_both_resolved_type(_mock_call_insights, _mock_db): """Test the function execute.""" with open("tests/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" assert len(out['result']['recommendations']) == 3 file_names_expecetd = ["/home/JohnDoe1", "/home/JohnDoe2", "/home/JohnDoe3"] file_names_received = [reco["manifest_file_path"] for reco in out['result']['recommendations']] assert file_names_received == file_names_expecetd 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()
def test_execute_empty_resolved(_mock_call_insights): """Test the function execute.""" with open("tests/data/stack_aggregator_empty_resolved.json", "r") as f: payload = json.loads(f.read()) r = RecommendationTask() out = r.execute(arguments=payload, persist=False) assert out['recommendation'] == "success" assert not out["result"]["recommendations"][0]["companion"] assert not out["result"]["recommendations"][0]["alternate"] assert not out["result"]["recommendations"][0]["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) assert out['recommendation'] == "database error"