Skip to content

Commit

Permalink
Fix nightly parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Nov 5, 2024
1 parent b03fdac commit abb3e18
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
20 changes: 13 additions & 7 deletions prestashop_docker/version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


class VersionManager:
NIGHTLY = 'nightly'

def __init__(self, directory_path):
'''
Constructor
Expand Down Expand Up @@ -62,24 +64,28 @@ def parse_version(self, version):
@rtype: dict
'''

# 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))

data = self.get_version_from_string(version)
if data is not None and data['ps_version'] == self.NIGHTLY:
ps_version = self.NIGHTLY
else:
# 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))
ps_version = split_version['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 / split_version['version']
ps_version_path = self.directory_path / ps_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(split_version['version'], php_version, container)] = str(container_path)
result[self.create_version(ps_version, php_version, container)] = str(container_path)

return result

Expand Down
52 changes: 48 additions & 4 deletions tests/prestashop_docker/test_version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def setUp(self, docker_api):
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.fs.create_dir('/tmp/images/nightly/7.2-fpm')
self.fs.create_dir('/tmp/images/nightly/7.2-apache')
self.fs.create_dir('/tmp/images/nightly/7.3-fpm')
self.fs.create_dir('/tmp/images/nightly/7.3-apache')
self.version_manager = self.create_instance()

def create_instance(self):
Expand All @@ -53,7 +57,7 @@ def create_instance(self):
'8.1.3': ('7.2', '7.3', '7.4', '8.0', '8.1'),
'8.1.x': ('7.2', '7.3', '7.4', '8.0', '8.1'),
'9.0.x': ('8.1', '8.2', '8.3'),
'nightly': ('7.1',)
'nightly': ('7.1','7.2','7.3')
}

@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
Expand Down Expand Up @@ -165,7 +169,7 @@ def test_get_version_from_string_with_ps_version(self):
# Nightly version uses develop as the branch
result = self.version_manager.get_version_from_string('nightly')
self.assertEqual(
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.1',), 'container_version': None},
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.1','7.2','7.3'), 'container_version': None},
result
)

Expand Down Expand Up @@ -193,6 +197,11 @@ def test_get_version_from_string_with_container_version(self):
{'ps_version': '9.0.0', 'branch_version': '9.0.x', 'php_versions': ('8.2',), 'container_version': None},
result
)
result = self.version_manager.get_version_from_string('nightly-7.2')
self.assertEqual(
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.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 @@ -211,6 +220,11 @@ def test_get_version_from_string_with_container_version_and_type(self):
{'ps_version': '9.0.0', 'branch_version': '9.0.x', 'php_versions': ('8.2',), 'container_version': 'fpm'},
result
)
result = self.version_manager.get_version_from_string('nightly-7.2-fpm')
self.assertEqual(
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.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 @@ -287,6 +301,17 @@ def test_parse_version_with_valid_version(self):
},
self.version_manager.parse_version('9.0.x')
)
self.assertEqual(
{
'nightly-7.1-apache': '/tmp/images/nightly/7.1-apache',
'nightly-7.1-fpm': '/tmp/images/nightly/7.1-fpm',
'nightly-7.2-apache': '/tmp/images/nightly/7.2-apache',
'nightly-7.2-fpm': '/tmp/images/nightly/7.2-fpm',
'nightly-7.3-apache': '/tmp/images/nightly/7.3-apache',
'nightly-7.3-fpm': '/tmp/images/nightly/7.3-fpm',
},
self.version_manager.parse_version('nightly')
)

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

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

@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
def test_get_versions(self):
Expand Down Expand Up @@ -436,6 +474,10 @@ def test_get_versions(self):
'9.0.x-8.3-apache': '/tmp/images/9.0.x/8.3-apache',
'nightly-7.1-fpm': '/tmp/images/nightly/7.1-fpm',
'nightly-7.1-apache': '/tmp/images/nightly/7.1-apache',
'nightly-7.2-fpm': '/tmp/images/nightly/7.2-fpm',
'nightly-7.2-apache': '/tmp/images/nightly/7.2-apache',
'nightly-7.3-fpm': '/tmp/images/nightly/7.3-fpm',
'nightly-7.3-apache': '/tmp/images/nightly/7.3-apache',
}
# Useful for debug
# pprint.pp(manager_versions)
Expand Down Expand Up @@ -624,8 +666,10 @@ def test_get_aliases(self):
'9.0.x-8.2-apache': ['9.0.x-8.2'],
'9.0.x-8.3-apache': ['9.0.x-8.3', '9.0.x', '9.0.x-apache'],
'9.0.x-8.3-fpm': ['9.0.x-fpm'],
'nightly-7.1-apache': ['nightly-7.1', 'nightly', 'nightly-apache'],
'nightly-7.1-fpm': ['nightly-fpm'],
'nightly-7.1-apache': ['nightly-7.1'],
'nightly-7.2-apache': ['nightly-7.2'],
'nightly-7.3-apache': ['nightly-7.3', 'nightly', 'nightly-apache'],
'nightly-7.3-fpm': ['nightly-fpm'],
}
manager_aliases = self.version_manager.get_aliases()
# Useful for debug
Expand Down

0 comments on commit abb3e18

Please sign in to comment.