Skip to content

Commit 602f83d

Browse files
authored
Merge pull request #402 from PrestaShop/fix-nightly-parsing
Fix nightly parsing
2 parents b03fdac + 0d78c6c commit 602f83d

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

prestashop_docker/version_manager.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
class VersionManager:
13+
NIGHTLY = 'nightly'
14+
1315
def __init__(self, directory_path):
1416
'''
1517
Constructor
@@ -62,24 +64,28 @@ def parse_version(self, version):
6264
@rtype: dict
6365
'''
6466

65-
# Initial PS version(can also be a branch like 9.0.x)
66-
split_version = self.split_prestashop_version(version)
67-
if split_version is None or not (self.directory_path / split_version['version']).exists():
68-
raise ValueError('{} is not a valid version'.format(version))
69-
7067
data = self.get_version_from_string(version)
68+
if data is not None and data['ps_version'] == self.NIGHTLY:
69+
ps_version = self.NIGHTLY
70+
else:
71+
# Initial PS version(can also be a branch like 9.0.x)
72+
split_version = self.split_prestashop_version(version)
73+
if split_version is None or not (self.directory_path / split_version['version']).exists():
74+
raise ValueError('{} is not a valid version'.format(version))
75+
ps_version = split_version['version']
76+
7177
if data is None or data['container_version'] is None:
7278
containers = ('fpm', 'apache',)
7379
else:
7480
containers = (data['container_version'],)
7581

76-
ps_version_path = self.directory_path / split_version['version']
82+
ps_version_path = self.directory_path / ps_version
7783
result = {}
7884
for php_version in data['php_versions']:
7985
for container in containers:
8086
container_path = ps_version_path / (php_version + '-' + container)
8187
if container_path.exists():
82-
result[self.create_version(split_version['version'], php_version, container)] = str(container_path)
88+
result[self.create_version(ps_version, php_version, container)] = str(container_path)
8389

8490
return result
8591

tests/prestashop_docker/test_version_manager.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def setUp(self, docker_api):
3131
self.fs.create_dir('/tmp/images/9.0.x/8.3-apache')
3232
self.fs.create_dir('/tmp/images/nightly/7.1-fpm')
3333
self.fs.create_dir('/tmp/images/nightly/7.1-apache')
34+
self.fs.create_dir('/tmp/images/nightly/7.2-fpm')
35+
self.fs.create_dir('/tmp/images/nightly/7.2-apache')
36+
self.fs.create_dir('/tmp/images/nightly/7.3-fpm')
37+
self.fs.create_dir('/tmp/images/nightly/7.3-apache')
3438
self.version_manager = self.create_instance()
3539

3640
def create_instance(self):
@@ -53,7 +57,7 @@ def create_instance(self):
5357
'8.1.3': ('7.2', '7.3', '7.4', '8.0', '8.1'),
5458
'8.1.x': ('7.2', '7.3', '7.4', '8.0', '8.1'),
5559
'9.0.x': ('8.1', '8.2', '8.3'),
56-
'nightly': ('7.1',)
60+
'nightly': ('7.1', '7.2', '7.3'),
5761
}
5862

5963
@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
@@ -165,7 +169,7 @@ def test_get_version_from_string_with_ps_version(self):
165169
# Nightly version uses develop as the branch
166170
result = self.version_manager.get_version_from_string('nightly')
167171
self.assertEqual(
168-
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.1',), 'container_version': None},
172+
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.1', '7.2', '7.3'), 'container_version': None},
169173
result
170174
)
171175

@@ -193,6 +197,11 @@ def test_get_version_from_string_with_container_version(self):
193197
{'ps_version': '9.0.0', 'branch_version': '9.0.x', 'php_versions': ('8.2',), 'container_version': None},
194198
result
195199
)
200+
result = self.version_manager.get_version_from_string('nightly-7.2')
201+
self.assertEqual(
202+
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.2',), 'container_version': None},
203+
result
204+
)
196205

197206
@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
198207
def test_get_version_from_string_with_container_version_and_type(self):
@@ -211,6 +220,11 @@ def test_get_version_from_string_with_container_version_and_type(self):
211220
{'ps_version': '9.0.0', 'branch_version': '9.0.x', 'php_versions': ('8.2',), 'container_version': 'fpm'},
212221
result
213222
)
223+
result = self.version_manager.get_version_from_string('nightly-7.2-fpm')
224+
self.assertEqual(
225+
{'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.2',), 'container_version': 'fpm'},
226+
result
227+
)
214228

215229
@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
216230
def test_get_version_from_string_with_pre_release_and_without_container_version_and_type(self):
@@ -287,6 +301,17 @@ def test_parse_version_with_valid_version(self):
287301
},
288302
self.version_manager.parse_version('9.0.x')
289303
)
304+
self.assertEqual(
305+
{
306+
'nightly-7.1-apache': '/tmp/images/nightly/7.1-apache',
307+
'nightly-7.1-fpm': '/tmp/images/nightly/7.1-fpm',
308+
'nightly-7.2-apache': '/tmp/images/nightly/7.2-apache',
309+
'nightly-7.2-fpm': '/tmp/images/nightly/7.2-fpm',
310+
'nightly-7.3-apache': '/tmp/images/nightly/7.3-apache',
311+
'nightly-7.3-fpm': '/tmp/images/nightly/7.3-fpm',
312+
},
313+
self.version_manager.parse_version('nightly')
314+
)
290315

291316
@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
292317
def test_parse_version_with_valid_version_and_php_version(self):
@@ -311,6 +336,13 @@ def test_parse_version_with_valid_version_and_php_version(self):
311336
},
312337
self.version_manager.parse_version('9.0.x-8.2')
313338
)
339+
self.assertEqual(
340+
{
341+
'nightly-7.2-apache': '/tmp/images/nightly/7.2-apache',
342+
'nightly-7.2-fpm': '/tmp/images/nightly/7.2-fpm',
343+
},
344+
self.version_manager.parse_version('nightly-7.2')
345+
)
314346

315347
@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
316348
def test_parse_version_with_valid_version_php_version_and_container(self):
@@ -332,6 +364,12 @@ def test_parse_version_with_valid_version_php_version_and_container(self):
332364
},
333365
self.version_manager.parse_version('9.0.x-8.2-apache')
334366
)
367+
self.assertEqual(
368+
{
369+
'nightly-7.2-apache': '/tmp/images/nightly/7.2-apache',
370+
},
371+
self.version_manager.parse_version('nightly-7.2-apache')
372+
)
335373

336374
@patch('prestashop_docker.version_manager.VERSIONS', all_versions)
337375
def test_get_versions(self):
@@ -436,6 +474,10 @@ def test_get_versions(self):
436474
'9.0.x-8.3-apache': '/tmp/images/9.0.x/8.3-apache',
437475
'nightly-7.1-fpm': '/tmp/images/nightly/7.1-fpm',
438476
'nightly-7.1-apache': '/tmp/images/nightly/7.1-apache',
477+
'nightly-7.2-fpm': '/tmp/images/nightly/7.2-fpm',
478+
'nightly-7.2-apache': '/tmp/images/nightly/7.2-apache',
479+
'nightly-7.3-fpm': '/tmp/images/nightly/7.3-fpm',
480+
'nightly-7.3-apache': '/tmp/images/nightly/7.3-apache',
439481
}
440482
# Useful for debug
441483
# pprint.pp(manager_versions)
@@ -624,8 +666,10 @@ def test_get_aliases(self):
624666
'9.0.x-8.2-apache': ['9.0.x-8.2'],
625667
'9.0.x-8.3-apache': ['9.0.x-8.3', '9.0.x', '9.0.x-apache'],
626668
'9.0.x-8.3-fpm': ['9.0.x-fpm'],
627-
'nightly-7.1-apache': ['nightly-7.1', 'nightly', 'nightly-apache'],
628-
'nightly-7.1-fpm': ['nightly-fpm'],
669+
'nightly-7.1-apache': ['nightly-7.1'],
670+
'nightly-7.2-apache': ['nightly-7.2'],
671+
'nightly-7.3-apache': ['nightly-7.3', 'nightly', 'nightly-apache'],
672+
'nightly-7.3-fpm': ['nightly-fpm'],
629673
}
630674
manager_aliases = self.version_manager.get_aliases()
631675
# Useful for debug

0 commit comments

Comments
 (0)