diff --git a/reports/tests/test_utils.py b/reports/tests/test_utils.py index b139669b..0f99c83a 100644 --- a/reports/tests/test_utils.py +++ b/reports/tests/test_utils.py @@ -227,6 +227,35 @@ def test_process_repo_json_rpm(self): # RPM priority is negated self.assertEqual(priority, -99) + def test_process_repo_no_rename_on_existing_mirror(self): + """Repo found by mirror URL should keep its original name. + + Repo names are set at creation and should not be overwritten by + client reports — the admin may have renamed the repo in the UI. + """ + repo, _ = process_repo( + r_type=Repository.RPM, + r_name='Zabbix Official Repository - x86_64 x86_64', + r_id='zabbix', + r_priority=-99, + urls=['https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64'], + arch='x86_64', + ) + self.assertEqual(repo.name, 'Zabbix Official Repository - x86_64 x86_64') + + # updated client reports same URL with corrected name + repo2, _ = process_repo( + r_type=Repository.RPM, + r_name='Zabbix Official Repository - x86_64', + r_id='zabbix', + r_priority=-99, + urls=['https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64'], + arch='x86_64', + ) + # should return the same repo, name unchanged + self.assertEqual(repo2.id, repo.id) + self.assertEqual(repo2.name, 'Zabbix Official Repository - x86_64 x86_64') + @override_settings( CELERY_TASK_ALWAYS_EAGER=True, diff --git a/reports/utils.py b/reports/utils.py index 9b2a4196..4fea67d3 100644 --- a/reports/utils.py +++ b/reports/utils.py @@ -258,9 +258,6 @@ def process_repo(r_type, r_name, r_id, r_priority, urls, arch): if r_id and repository.repo_id != r_id: repository.repo_id = r_id - if r_name and repository.name != r_name: - repository.name = r_name - for url in unknown: Mirror.objects.create(repo=repository, url=url.rstrip('/'))