-
Notifications
You must be signed in to change notification settings - Fork 16
Support qualifier-first versions like final-1.2.3 during migration #301
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed bug related to qualifier-first versions like final-1.2.3 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ def group_artifact_version_filename(relative_path): | |
| """ | ||
| sub_path, filename = path.split(relative_path) | ||
| sub_path, version = path.split(sub_path) | ||
| pattern = re.compile(r"\d+(\.\d+)?(\.\d+)?([.-][a-zA-Z0-9]+)*") | ||
| pattern = re.compile(r"^((?:[A-Za-z0-9]+[.-])+\d+(?:\.\d+){0,2}|\d+(?:\.\d+){0,2}(?:[.-][A-Za-z0-9]+)*)$") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would 1.2.3.4.5.6 be a valid version? Can you add some negative test cases too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdellweg @bvladimir Maybe we should remove version regexp-ing at all?
So, if some package in most well-known repo https://repo1.maven.org/maven2/ has "irregular" version - it could fail to load to Pulp... |
||
| if pattern.match(version) is None: | ||
| artifact_id = version | ||
| version = None | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,99 @@ | ||
| from django.test import TestCase | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use pytest to run these tests, and pytest-django is available. Any chance I could ask you to redesign these around the and
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want, you can also just test the regex in complete isolation. |
||
| """ | ||
| Unit tests for MavenContentMixin version parsing. | ||
|
|
||
| These tests can run without Django installed by mocking Django dependencies. | ||
| They test the actual code from pulp_maven.app.models, not a copy. | ||
| """ | ||
| import sys | ||
| import unittest | ||
| from unittest.mock import MagicMock, Mock | ||
|
|
||
| class TestNothing(TestCase): | ||
| """Test Nothing (placeholder).""" | ||
| # Create a proper mock for Django models with correct metaclass | ||
| class MockModel: | ||
| """Mock base class for Django models.""" | ||
| pass | ||
|
|
||
| def test_nothing_at_all(self): | ||
| """Test that the tests are running and that's it.""" | ||
| self.assertTrue(True) | ||
| # Mock Django modules before importing | ||
| django_models_mock = MagicMock() | ||
| django_models_mock.Model = MockModel | ||
| django_models_mock.CharField = MagicMock | ||
| django_models_mock.ForeignKey = MagicMock | ||
| django_models_mock.PROTECT = MagicMock | ||
|
|
||
| pulpcore_models_mock = MagicMock() | ||
| pulpcore_models_mock.Content = MockModel | ||
| pulpcore_models_mock.Remote = MockModel | ||
| pulpcore_models_mock.Repository = MockModel | ||
| pulpcore_models_mock.Distribution = MockModel | ||
|
|
||
| sys.modules['django'] = MagicMock() | ||
| sys.modules['django.db'] = MagicMock() | ||
| sys.modules['django.db.models'] = django_models_mock | ||
| sys.modules['pulpcore'] = MagicMock() | ||
| sys.modules['pulpcore.plugin'] = MagicMock() | ||
| sys.modules['pulpcore.plugin.models'] = pulpcore_models_mock | ||
| sys.modules['pulpcore.plugin.util'] = MagicMock() | ||
|
|
||
| # Mock get_domain_pk function | ||
| sys.modules['pulpcore.plugin.util'].get_domain_pk = MagicMock(return_value=1) | ||
|
|
||
| # Now import the actual code from the module | ||
| from pulp_maven.app.models import MavenContentMixin | ||
|
|
||
|
|
||
| class TestMavenContentMixin(unittest.TestCase): | ||
| """Test MavenContentMixin version parsing.""" | ||
|
|
||
| def test_standard_version_format(self): | ||
| """Test standard semantic version format (1.2.3).""" | ||
| relative_path = "org/example/myapp/1.2.3/myapp-1.2.3.jar" | ||
| group_id, artifact_id, version, filename = MavenContentMixin.group_artifact_version_filename( | ||
| relative_path | ||
| ) | ||
|
|
||
| self.assertEqual(group_id, "org.example") | ||
| self.assertEqual(artifact_id, "myapp") | ||
| self.assertEqual(version, "1.2.3") | ||
| self.assertEqual(filename, "myapp-1.2.3.jar") | ||
|
|
||
| def test_version_with_suffix(self): | ||
| """Test version with suffix format (1.2.3-rc, 1.2.3-SNAPSHOT).""" | ||
| test_cases = [ | ||
| ("org/example/myapp/1.2.3-rc/myapp-1.2.3-rc.jar", "1.2.3-rc"), | ||
| ("org/example/myapp/1.2.3-SNAPSHOT/myapp-1.2.3-SNAPSHOT.jar", "1.2.3-SNAPSHOT"), | ||
| ("org/example/myapp/1.2.3-beta1/myapp-1.2.3-beta1.jar", "1.2.3-beta1"), | ||
| ] | ||
|
|
||
| for relative_path, expected_version in test_cases: | ||
| with self.subTest(version=expected_version): | ||
| group_id, artifact_id, version, filename = MavenContentMixin.group_artifact_version_filename( | ||
| relative_path | ||
| ) | ||
|
|
||
| self.assertEqual(group_id, "org.example") | ||
| self.assertEqual(artifact_id, "myapp") | ||
| self.assertEqual(version, expected_version) | ||
| self.assertEqual(filename, f"myapp-{expected_version}.jar") | ||
|
|
||
| def test_version_with_prefix(self): | ||
| """Test version with prefix format (rc-1.2.3, SNAPSHOT-1.2.3) - Artifactory compatibility.""" | ||
| test_cases = [ | ||
| ("org/example/myapp/rc-1.2.3/myapp-rc-1.2.3.jar", "rc-1.2.3"), | ||
| ("org/example/myapp/SNAPSHOT-1.2.3/myapp-SNAPSHOT-1.2.3.jar", "SNAPSHOT-1.2.3"), | ||
| ("org/example/myapp/beta1-1.2.3/myapp-beta1-1.2.3.jar", "beta1-1.2.3"), | ||
| ("org/example/myapp/v1-1.2/myapp-v1-1.2.jar", "v1-1.2"), | ||
| ] | ||
|
|
||
| for relative_path, expected_version in test_cases: | ||
| with self.subTest(version=expected_version): | ||
| group_id, artifact_id, version, filename = MavenContentMixin.group_artifact_version_filename( | ||
| relative_path | ||
| ) | ||
|
|
||
| self.assertEqual(group_id, "org.example") | ||
| self.assertEqual(artifact_id, "myapp") | ||
| self.assertEqual(version, expected_version) | ||
| self.assertEqual(filename, f"myapp-{expected_version}.jar") | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
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.
Maybe give the user more details: