applications: auto scan deps on generation (#69651)
gitea-wip/hobo/pipeline/head There was a failure building this commit Details
gitea/hobo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2022-10-18 11:43:33 +02:00
parent 7215ca84bd
commit fce0d6b80f
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 19 additions and 12 deletions

View File

@ -170,17 +170,16 @@ class AppDeleteElementView(DeleteView):
delete_element = AppDeleteElementView.as_view()
def scandeps(request, app_slug):
def scan(app_slug):
app = Application.objects.get(slug=app_slug)
app.relation_set.filter(auto_dependency=True).delete()
relations = app.relation_set.select_related('element')
elements = {(x.element.type, x.element.slug): x.element for x in relations}
elements = {(x.element.type, x.element.slug): (x.element, x) for x in relations}
finished = False
while not finished:
finished = True
for (type, slug), element in list(elements.items()):
dependencies_url = element.cache['urls'].get('dependencies')
element.done = True
for el in [x[0] for x in elements.values()]:
dependencies_url = el.cache['urls'].get('dependencies')
if not dependencies_url:
continue
response = requests.get(dependencies_url)
@ -198,13 +197,19 @@ def scandeps(request, app_slug):
if created:
relation.auto_dependency = True
relation.save()
elements[(element.type, element.slug)] = element
elements[(element.type, element.slug)] = (element, relation)
return elements
def scandeps(request, app_slug):
scan(app_slug)
return HttpResponseRedirect(reverse('application-manifest', kwargs={'app_slug': app_slug}))
def generate(request, app_slug):
app = Application.objects.get(slug=app_slug)
elements = scan(app_slug)
version = Version(application=app)
version.save()
@ -219,8 +224,7 @@ def generate(request, app_slug):
'elements': [],
}
for relation in app.relation_set.all().select_related('element'):
element = relation.element
for element, relation in elements.values():
manifest_json['elements'].append(
{
'type': element.type,

View File

@ -150,7 +150,8 @@ def mocked_http(url, request):
return {'content': '{}', 'status_code': 200}
def test_create_application(app, admin_user, settings):
@pytest.mark.parametrize('analyze', [True, False])
def test_create_application(app, admin_user, settings, analyze):
Wcs.objects.create(base_url='https://wcs.example.invalid', slug='foobar', title='Foobar')
settings.KNOWN_SERVICES = {
@ -198,12 +199,14 @@ def test_create_application(app, admin_user, settings):
assert Application.objects.get(slug='test').elements.count() == 1
element = Application.objects.get(slug='test').elements.all()[0]
assert element.slug == 'test-form'
assert 'Test Card' not in resp.text
resp = resp.click('Scan dependencies').follow()
assert Application.objects.get(slug='test').elements.count() == 2
assert 'Test Card' in resp.text
if analyze:
resp = resp.click('Scan dependencies').follow()
assert Application.objects.get(slug='test').elements.count() == 2
resp = resp.click('Generate application bundle').follow()
assert 'Test Card' in resp.text
resp = resp.click('Download')
assert resp.content_type == 'application/x-tar'
# uncompressed tar, primitive check of contents