applications: install & new version only if number changed (#69655)
This commit is contained in:
parent
92aeb41e55
commit
b48bd6e23b
|
@ -315,11 +315,14 @@ class Install(FormView):
|
|||
relation.save()
|
||||
|
||||
# always create a new version on install
|
||||
version = Version(
|
||||
application=app,
|
||||
number=manifest.get('version_number') or 'unknown',
|
||||
notes=manifest.get('version_notes') or '',
|
||||
)
|
||||
version_number = manifest.get('version_number') or 'unknown'
|
||||
latest_version = app.version_set.order_by('last_update_timestamp').last()
|
||||
if latest_version and latest_version.number == version_number:
|
||||
version = latest_version
|
||||
else:
|
||||
version = Version(application=app)
|
||||
version.number = version_number
|
||||
version.notes = manifest.get('version_notes') or ''
|
||||
version.bundle.save('%s.tar' % app.slug, content=ContentFile(tar_io.getvalue()))
|
||||
version.save()
|
||||
|
||||
|
|
|
@ -431,7 +431,7 @@ def get_bundle(with_icon=False):
|
|||
'icon': 'foo.png' if with_icon else None,
|
||||
'description': '',
|
||||
'documentation_url': 'http://foo.bar',
|
||||
'version_number': '42.0',
|
||||
'version_number': '43.0' if with_icon else '42.0',
|
||||
'version_notes': 'foo bar blah',
|
||||
'elements': [
|
||||
{'type': 'forms', 'slug': 'test', 'name': 'test', 'auto-dependency': False},
|
||||
|
@ -471,27 +471,47 @@ def test_deploy_application(app, admin_user, settings, app_bundle, app_bundle_wi
|
|||
|
||||
login(app)
|
||||
|
||||
resp = app.get('/applications/')
|
||||
for i in range(3):
|
||||
bundles = [app_bundle, app_bundle_with_icon, app_bundle]
|
||||
def install(resp, bundle):
|
||||
resp = resp.click('Install')
|
||||
resp.form['bundle'] = Upload('app.tar', bundles[i], 'application/x-tar')
|
||||
resp.form['bundle'] = Upload('app.tar', bundle, 'application/x-tar')
|
||||
with HTTMock(mocked_http):
|
||||
resp = resp.form.submit().follow()
|
||||
|
||||
assert Application.objects.count() == 1
|
||||
app = Application.objects.get(slug='test')
|
||||
assert app.name == 'Test'
|
||||
if i == 1:
|
||||
assert re.match(r'applications/icons/foo(_\w+)?.png', app.icon.name)
|
||||
application = Application.objects.get(slug='test')
|
||||
assert application.name == 'Test'
|
||||
if bundle == app_bundle_with_icon:
|
||||
assert re.match(r'applications/icons/foo(_\w+)?.png', application.icon.name)
|
||||
else:
|
||||
assert app.icon.name == ''
|
||||
assert app.documentation_url == 'http://foo.bar'
|
||||
assert app.version_set.count() == i + 1
|
||||
version = app.version_set.all()[i]
|
||||
assert version.number == '42.0'
|
||||
assert application.icon.name == ''
|
||||
assert application.documentation_url == 'http://foo.bar'
|
||||
version = application.version_set.latest('pk')
|
||||
if bundle == app_bundle_with_icon:
|
||||
assert version.number == '43.0'
|
||||
else:
|
||||
assert version.number == '42.0'
|
||||
assert version.notes == 'foo bar blah'
|
||||
assert app.elements.count() == 3
|
||||
assert application.elements.count() == 3
|
||||
return version
|
||||
|
||||
resp = app.get('/applications/')
|
||||
version1 = install(resp, app_bundle)
|
||||
assert version1.application.version_set.count() == 1
|
||||
version2 = install(resp, app_bundle)
|
||||
assert version2.application.version_set.count() == 1
|
||||
assert version1.pk == version2.pk
|
||||
assert version1.creation_timestamp == version2.creation_timestamp
|
||||
assert version1.last_update_timestamp < version2.last_update_timestamp
|
||||
version3 = install(resp, app_bundle_with_icon)
|
||||
assert version2.application.version_set.count() == 2
|
||||
assert version2.pk != version3.pk
|
||||
assert version2.creation_timestamp < version3.creation_timestamp
|
||||
assert version2.last_update_timestamp < version3.last_update_timestamp
|
||||
version4 = install(resp, app_bundle)
|
||||
assert version4.application.version_set.count() == 3
|
||||
assert version3.pk != version4.pk
|
||||
assert version3.creation_timestamp < version4.creation_timestamp
|
||||
assert version3.last_update_timestamp < version4.last_update_timestamp
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
Loading…
Reference in New Issue