Skip to content

Commit

Permalink
test_views_api
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Mar 16, 2023
1 parent 9f210df commit 61c2862
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
10 changes: 1 addition & 9 deletions projectroles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,7 @@ def _set_app_setting_widget(self, app_name, s_field, s_key, s_val):

# Set project type
s_project_types = s_val.get('project_types') or [PROJECT_TYPE_PROJECT]
if PROJECT_TYPE_PROJECT in s_project_types:
s_widget_attrs['data-project-types'] = 'project'
elif PROJECT_TYPE_CATEGORY in s_project_types:
s_widget_attrs['data-project-types'] = 'category'
elif (
PROJECT_TYPE_PROJECT in s_project_types
and PROJECT_TYPE_CATEGORY in s_project_types
):
s_widget_attrs['data-project-types'] = 'project,category'
s_widget_attrs['data-project-types'] = ','.join(s_project_types).lower()

if 'placeholder' in s_val:
s_widget_attrs['placeholder'] = s_val.get('placeholder')
Expand Down
12 changes: 6 additions & 6 deletions projectroles/migrations/0026_delete_category_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ def clean_up_app_settings(apps, schema_editor):
AppSetting = apps.get_model('projectroles', 'AppSetting')

# Find all app settings with project type 'CATEGORY'
app_settings = AppSetting.objects.filter(project__type='CATEGORY')
app_settings = AppSetting.objects.exclude(project=None)

for app_setting in app_settings:
try:
setting = app_settings_api.get_definition(
setting_def = app_settings_api.get_definition(
app_name=app_setting.app_plugin.name, name=app_setting.name
)
except ValueError:
# AppSetting is already deleted
continue
except AttributeError:
# app_plugin is None, what means that the app plugin is projectroles
setting = app_settings_api.get_definition(
setting_def = app_settings_api.get_definition(
app_name='projectroles', name=app_setting.name
)

if (
not setting.get('project_types', None)
or setting.get('project_types', None)
and 'CATEGORY' not in setting['project_types']
app_setting.project.type not in setting_def.get(
'project_types', ['PROJECT']
)
):
# Delete app setting if it is not restricted to any project types
app_setting.delete()
Expand Down
2 changes: 1 addition & 1 deletion projectroles/static/projectroles/js/project_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $(document).ready(function() {
}
});
}
if ($('#object-type').text() == 'Update Category') {
if ($('#object-type').text() == 'Update Category' || $('#object-type').text() == 'Create Top Level Category') {
$('div[id^="div_id_settings"]').each(function () {
var $parentDiv = $(this);
var $categoryElements = $parentDiv.find('select[data-project-types="category"]')
Expand Down
2 changes: 1 addition & 1 deletion projectroles/templates/projectroles/project_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h2>Create {{ project_display }} or {{ category_display }} Under {{ parent.title
{% elif disable_categories %}
<h2>Create {{ project_display }}</h2>
{% else %}
<h2>Create Top Level {{ category_display }}</h2>
<h2 id="object-type">Create Top Level {{ category_display }}</h2>
{% endif %}
</div>

Expand Down
16 changes: 16 additions & 0 deletions projectroles/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2971,6 +2971,22 @@ def test_set_invalid_scope(self):
self.assertEqual(response.status_code, 400, msg=response.content)
self.assertEqual(AppSetting.objects.count(), 0)

def test_set_invalid_project_type(self):
"""Test setting app setting with the wrong project type (should fail)"""
setting_name = 'project_category_bool_setting'
url = reverse(
'projectroles:api_project_setting_set',
kwargs={'project': self.project.sodar_uuid},
)
post_data = {
'app_name': EX_APP_NAME,
'setting_name': setting_name,
'value': True,
}
response = self.request_knox(url, method='POST', data=post_data)
self.assertEqual(response.status_code, 400, msg=response.content)
self.assertEqual(AppSetting.objects.count(), 0)

def test_set_no_value(self):
"""Test setting without value (should fail)"""
self.assertEqual(AppSetting.objects.count(), 0)
Expand Down

0 comments on commit 61c2862

Please sign in to comment.