Skip to content

Commit

Permalink
Adapt VersionManager::parse_version and its tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Nov 4, 2024
1 parent de07d30 commit ee423af
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
12 changes: 7 additions & 5 deletions prestashop_docker/version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,24 @@ def parse_version(self, version):
@rtype: dict
'''

data = self.get_version_from_string(version)
if data is None or not (self.directory_path / data['ps_version']).exists():
# Initial PS version(can also be a branch like 9.0.x)
split_version = self.split_prestashop_version(version)
if split_version is None or not (self.directory_path / split_version['version']).exists():
raise ValueError('{} is not a valid version'.format(version))

if data['container_version'] is None:
data = self.get_version_from_string(version)
if data is None or data['container_version'] is None:
containers = ('fpm', 'apache',)
else:
containers = (data['container_version'],)

ps_version_path = self.directory_path / data['ps_version']
ps_version_path = self.directory_path / split_version['version']
result = {}
for php_version in data['php_versions']:
for container in containers:
container_path = ps_version_path / (php_version + '-' + container)
if container_path.exists():
result[self.create_version(data['ps_version'], php_version, container)] = str(container_path)
result[self.create_version(split_version['version'], php_version, container)] = str(container_path)

return result

Expand Down
36 changes: 36 additions & 0 deletions tests/prestashop_docker/test_version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def setUp(self, docker_api):
self.fs.create_dir('/tmp/images/9.0.x/8.1-apache')
self.fs.create_dir('/tmp/images/9.0.x/8.2-fpm')
self.fs.create_dir('/tmp/images/9.0.x/8.2-apache')
self.fs.create_dir('/tmp/images/9.0.x/8.3-fpm')
self.fs.create_dir('/tmp/images/9.0.x/8.3-apache')
self.fs.create_dir('/tmp/images/nightly/7.1-fpm')
self.fs.create_dir('/tmp/images/nightly/7.1-apache')
self.version_manager = self.create_instance()
Expand Down Expand Up @@ -186,6 +188,11 @@ def test_get_version_from_string_with_container_version(self):
{'ps_version': '8.0.0', 'branch_version': '8.0.x', 'php_versions': ('7.2',), 'container_version': None},
result
)
result = self.version_manager.get_version_from_string('9.0.x-8.2')
self.assertEqual(
{'ps_version': '9.0.0', 'branch_version': '9.0.x', 'php_versions': ('8.2',), 'container_version': None},
result
)

@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
def test_get_version_from_string_with_container_version_and_type(self):
Expand All @@ -199,6 +206,11 @@ def test_get_version_from_string_with_container_version_and_type(self):
{'ps_version': '8.0.0', 'branch_version': '8.0.x', 'php_versions': ('7.2',), 'container_version': 'fpm'},
result
)
result = self.version_manager.get_version_from_string('9.0.x-8.2-fpm')
self.assertEqual(
{'ps_version': '9.0.0', 'branch_version': '9.0.x', 'php_versions': ('8.2',), 'container_version': 'fpm'},
result
)

@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
def test_get_version_from_string_with_pre_release_and_without_container_version_and_type(self):
Expand Down Expand Up @@ -264,6 +276,17 @@ def test_parse_version_with_valid_version(self):
},
self.version_manager.parse_version('8.0.0')
)
self.assertEqual(
{
'9.0.x-8.1-apache': '/tmp/images/9.0.x/8.1-apache',
'9.0.x-8.1-fpm': '/tmp/images/9.0.x/8.1-fpm',
'9.0.x-8.2-apache': '/tmp/images/9.0.x/8.2-apache',
'9.0.x-8.2-fpm': '/tmp/images/9.0.x/8.2-fpm',
'9.0.x-8.3-apache': '/tmp/images/9.0.x/8.3-apache',
'9.0.x-8.3-fpm': '/tmp/images/9.0.x/8.3-fpm',
},
self.version_manager.parse_version('9.0.x')
)

@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
def test_parse_version_with_valid_version_and_php_version(self):
Expand All @@ -281,6 +304,13 @@ def test_parse_version_with_valid_version_and_php_version(self):
},
self.version_manager.parse_version('8.1.0-7.2')
)
self.assertEqual(
{
'9.0.x-8.2-apache': '/tmp/images/9.0.x/8.2-apache',
'9.0.x-8.2-fpm': '/tmp/images/9.0.x/8.2-fpm',
},
self.version_manager.parse_version('9.0.x-8.2')
)

@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
def test_parse_version_with_valid_version_php_version_and_container(self):
Expand All @@ -296,6 +326,12 @@ def test_parse_version_with_valid_version_php_version_and_container(self):
},
self.version_manager.parse_version('8.1.3-7.2-apache')
)
self.assertEqual(
{
'9.0.x-8.2-apache': '/tmp/images/9.0.x/8.2-apache',
},
self.version_manager.parse_version('9.0.x-8.2-apache')
)

@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
def test_get_versions(self):
Expand Down

0 comments on commit ee423af

Please sign in to comment.