-
Notifications
You must be signed in to change notification settings - Fork 20
[OJ-54951] Honor backpopulation_window_days from server endpoint #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
80c363f
ae7b86d
08565f5
488e79b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import json | ||
| import unittest | ||
| from unittest import TestCase | ||
| from unittest.mock import MagicMock | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import yaml | ||
| from jf_ingest.config import AzureDevopsAuthConfig as JFIngestAzureDevopsAuthConfig | ||
|
|
@@ -10,9 +10,52 @@ | |
| GitConfig, | ||
| _get_git_config_from_yaml, | ||
| _get_jf_ingest_git_auth_config, | ||
| get_ingest_config, | ||
| ) | ||
|
|
||
|
|
||
| def _build_ado_git_config() -> GitConfig: | ||
|
Check warning on line 17 in tests/test_config_file.py
|
||
| return GitConfig( | ||
| git_url='https://ado.com', | ||
| git_provider='ado', | ||
| git_instance_slug='ado-instance-1', | ||
| git_include_projects=[], | ||
| git_exclude_projects=[], | ||
| git_include_all_repos_inside_projects=[], | ||
| git_exclude_all_repos_inside_projects=[], | ||
| git_include_repos=[], | ||
| git_exclude_repos=[], | ||
| git_include_branches={}, | ||
| git_strip_text_content=False, | ||
| git_redact_names_and_urls=False, | ||
| gitlab_per_page_override=False, | ||
| git_verbose=False, | ||
| gitlab_keep_base_url=False, | ||
| creds_envvar_prefix='ORG1', | ||
| git_include_bbcloud_projects=[], | ||
| git_exclude_bbcloud_projects=[], | ||
| ) | ||
|
|
||
|
|
||
| def _build_ingest_config_inputs(endpoint_git_instance_info: dict): | ||
|
Check warning on line 40 in tests/test_config_file.py
|
||
| config = MagicMock() | ||
| config.jira_url = None | ||
| config.git_configs = [_build_ado_git_config()] | ||
| config.skip_ssl_verification = False | ||
| config.run_mode_includes_send = False | ||
| config.jira_skip_saving_data_locally = False | ||
| config.outdir = '/tmp/agent-output' | ||
|
Check failure on line 47 in tests/test_config_file.py
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| config.jellyfish_api_base = 'https://api.jellyfish.co' | ||
|
|
||
| creds = MagicMock() | ||
| creds.git_instance_to_creds = {'ado-instance-1': {'ado_token': 'token-1'}} | ||
| creds.jellyfish_api_token = 'jf-token' | ||
|
|
||
| endpoint_git_instances_info = {'ado-instance-1': endpoint_git_instance_info} | ||
|
|
||
| return config, creds, endpoint_git_instances_info | ||
|
|
||
|
|
||
| class TestGitConfigGeneration(TestCase): | ||
| def test_get_git_config_from_yaml_ado_default(self): | ||
| ado_yaml_content = """ | ||
|
|
@@ -183,3 +226,82 @@ | |
| assert auth_config.token == 'token-2' | ||
| assert auth_config.api_version == '7.0' | ||
| assert auth_config.verify is True | ||
|
|
||
|
|
||
| class TestBackpopulationWindowDaysPassthrough(TestCase): | ||
| """ | ||
| Verifies the optional `backpopulation_window_days` value from the server endpoint | ||
| is forwarded into JFIngestGitConfig only when present, so that jf-ingest's default | ||
| applies otherwise. | ||
| """ | ||
|
|
||
| @patch('jf_agent.config_file_reader.IngestionConfig') | ||
| @patch('jf_agent.config_file_reader.JFIngestGitConfig') | ||
| @patch('jf_agent.config_file_reader._get_jf_ingest_git_auth_config') | ||
| @patch('jf_agent.config_file_reader.get_company_info') | ||
| def test_backpopulation_window_days_forwarded_when_present( | ||
|
Check warning on line 242 in tests/test_config_file.py
|
||
| self, | ||
| mock_get_company_info, | ||
|
Check warning on line 244 in tests/test_config_file.py
|
||
| mock_get_auth, | ||
|
Check warning on line 245 in tests/test_config_file.py
|
||
| mock_jf_ingest_git_config, | ||
|
Check warning on line 246 in tests/test_config_file.py
|
||
| mock_ingestion_config, | ||
|
Check warning on line 247 in tests/test_config_file.py
|
||
| ): | ||
| mock_get_company_info.return_value = {'company_slug': 'test-co'} | ||
| mock_get_auth.return_value = MagicMock() | ||
|
|
||
| config, creds, endpoint_git_instances_info = _build_ingest_config_inputs( | ||
| endpoint_git_instance_info={ | ||
| 'slug': 'ado-instance-1', | ||
| 'key': 'ado-key', | ||
| 'repos_dict_v2': {}, | ||
| 'pull_from': '2024-01-01T00:00:00', | ||
| 'backpopulation_window_days': 90, | ||
| } | ||
| ) | ||
|
|
||
| get_ingest_config( | ||
| config=config, | ||
| creds=creds, | ||
| endpoint_jira_info={}, | ||
| endpoint_git_instances_info=endpoint_git_instances_info, | ||
| jf_options={}, | ||
| ) | ||
|
|
||
| self.assertEqual(mock_jf_ingest_git_config.call_count, 1) | ||
| kwargs = mock_jf_ingest_git_config.call_args.kwargs | ||
| self.assertEqual(kwargs.get('backpopulation_window_days'), 90) | ||
|
|
||
| @patch('jf_agent.config_file_reader.IngestionConfig') | ||
| @patch('jf_agent.config_file_reader.JFIngestGitConfig') | ||
| @patch('jf_agent.config_file_reader._get_jf_ingest_git_auth_config') | ||
| @patch('jf_agent.config_file_reader.get_company_info') | ||
| def test_backpopulation_window_days_omitted_when_absent( | ||
|
Check warning on line 278 in tests/test_config_file.py
|
||
| self, | ||
| mock_get_company_info, | ||
|
Check warning on line 280 in tests/test_config_file.py
|
||
| mock_get_auth, | ||
|
Check warning on line 281 in tests/test_config_file.py
|
||
| mock_jf_ingest_git_config, | ||
|
Check warning on line 282 in tests/test_config_file.py
|
||
| mock_ingestion_config, | ||
|
Check warning on line 283 in tests/test_config_file.py
|
||
| ): | ||
| mock_get_company_info.return_value = {'company_slug': 'test-co'} | ||
| mock_get_auth.return_value = MagicMock() | ||
|
|
||
| config, creds, endpoint_git_instances_info = _build_ingest_config_inputs( | ||
| endpoint_git_instance_info={ | ||
| 'slug': 'ado-instance-1', | ||
| 'key': 'ado-key', | ||
| 'repos_dict_v2': {}, | ||
| 'pull_from': '2024-01-01T00:00:00', | ||
| } | ||
| ) | ||
|
|
||
| get_ingest_config( | ||
| config=config, | ||
| creds=creds, | ||
| endpoint_jira_info={}, | ||
| endpoint_git_instances_info=endpoint_git_instances_info, | ||
| jf_options={}, | ||
| ) | ||
|
|
||
| self.assertEqual(mock_jf_ingest_git_config.call_count, 1) | ||
| kwargs = mock_jf_ingest_git_config.call_args.kwargs | ||
| self.assertNotIn('backpopulation_window_days', kwargs) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added unit coverage in
tests/test_config_file.py(TestBackpopulationWindowDaysPassthrough): one test assertsbackpopulation_window_daysis forwarded intoJFIngestGitConfigwhen present inendpoint_git_instance_info, and a second asserts the kwarg is omitted when absent so jf-ingest's default applies. Pushed in 08565f5.