Skip to content

Commit

Permalink
Merge pull request #152 from wooey/wooey-type-commandless
Browse files Browse the repository at this point in the history
Scripts without any arguments fail to run
  • Loading branch information
Chris7 authored Sep 5, 2016
2 parents 15a56fe + 44659de commit 4b10c6f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
13 changes: 8 additions & 5 deletions wooey/forms/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,19 @@ def get_group_forms(self, script_version=None, pk=None, initial_dict=None, rende
})
group['fields'][param.slug] = field
group_map[group_id] = group

pk = script_version.pk
form = WooeyForm(initial={'wooey_type': pk})
form.fields['wooey_type'] = script_id_field
form.fields['wooey_type'].initial = pk
d = {'action': script_version.get_url(), 'wooey_form': form}

# create individual forms for each group
d['groups'] = []
group_map = OrderedDict([(i, group_map[i]) for i in sorted(group_map.keys())])
d = {'action': script_version.get_url(), 'groups': []}
pk = script_version.pk
for group_index, group in enumerate(six.iteritems(group_map)):
group_pk, group_info = group
form = WooeyForm()
if group_index == 0:
form.fields['wooey_type'] = script_id_field
form.fields['wooey_type'].initial = pk
for field_pk, field in six.iteritems(group_info['fields']):
form.fields[field_pk] = field

Expand Down
1 change: 1 addition & 0 deletions wooey/templates/wooey/scripts/script_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h3 id="wooey-script-title">{{ script.script_name }}</h3>

<form id="wooey-job-form" method="POST" action="{{ form.action }}" enctype="multipart/form-data">
{% csrf_token %}
{{ form.wooey_form }}

<div class="panel panel-default">
<div class="panel-heading">
Expand Down
9 changes: 8 additions & 1 deletion wooey/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,11 @@ def test_without_args_form(self):
job.submit_to_celery()
# get the job again
job = WooeyJob.objects.get(pk=job.pk)
self.assertEqual(job.status, WooeyJob.COMPLETED)
self.assertEqual(job.status, WooeyJob.COMPLETED)

def test_wooey_form(self):
# Make sure wooey form exists and has everything we need in it
script_version = self.without_args
forms = utils.get_form_groups(script_version=self.without_args)
wooey_form = forms['wooey_form']
self.assertDictEqual(wooey_form.initial, {'wooey_type': script_version.pk})
21 changes: 21 additions & 0 deletions wooey/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO: Test for viewing a user's job as an anonymous user (fail case)

import json
from itertools import chain

from django.test import TestCase, RequestFactory, Client
from django.core.urlresolvers import reverse
Expand All @@ -10,6 +11,7 @@
from nose.tools import raises

from . import factories, mixins, config
from ..backend import utils
from ..views import wooey_celery
from .. import views as wooey_views
from .. import settings
Expand Down Expand Up @@ -173,3 +175,22 @@ def test_multiple_choice(self):
job = WooeyJob.objects.latest('created_date')
new_files = [i.value.url for i in job.get_parameters() if i.parameter.slug == 'multiple_file_choices']
self.assertEqual(len(new_files), len(files))


def test_form_groups(self):
# Make sure forms groups work to validate
script_version = self.without_args
forms = utils.get_form_groups(script_version=self.without_args)
data = {}
for form in chain(forms['groups'], [forms['wooey_form']]):
initial = form.initial
initial.update(config.SCRIPT_DATA['without_args'].get('data'))
data.update(initial)

url = reverse('wooey:wooey_script', kwargs={'slug': script_version.script.slug})
request = self.factory.post(url, data=data)
user = factories.UserFactory()
request.user = user
response = self.script_view_func(request)
d = load_JSON_dict(response.content)
self.assertTrue(d['valid'], d)

0 comments on commit 4b10c6f

Please sign in to comment.