Skip to content

Commit

Permalink
cleanup for v1.0.0 release (wip) (#1389)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jun 26, 2024
1 parent 5063bc8 commit c2ca153
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 71 deletions.
2 changes: 0 additions & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,6 @@ def set_logging(level=None):
SODAR_API_DEFAULT_HOST = env.url(
'SODAR_API_DEFAULT_HOST', 'http://0.0.0.0:8000'
)
# Default page size for paginated REST API list views
SODAR_API_PAGE_SIZE = env.int('SODAR_API_PAGE_SIZE', 100)


# Projectroles app settings
Expand Down
9 changes: 9 additions & 0 deletions docs/source/app_projectroles_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ environment settings. Example:
SODAR_API_DEFAULT_HOST = env.url('SODAR_API_DEFAULT_HOST', 'http://0.0.0.0:8000')
For enabling page size customization for pagination, it's recommended to set
``REST_FRAMEWORK['PAGE_SIZE']`` using an environment variable as follows:

.. code-block:: python
REST_FRAMEWORK = {
'PAGE_SIZE': env.int('SODAR_API_PAGE_SIZE', 100),
}
LDAP/AD Configuration (Optional)
================================
Expand Down
2 changes: 1 addition & 1 deletion example_project_app/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'options': get_example_setting_options,
'description': 'Example callable project user setting with options',
},
'project_category_bool_setting': {
'category_bool_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'BOOLEAN',
'label': 'Category boolean setting',
Expand Down
1 change: 0 additions & 1 deletion projectroles/static/projectroles/css/projectroles.css
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ dl dd {
color: #ffffff !important;
}


/* HACK for Bootstrap v4 button group alignment with dropdown enabled */
.btn {
height: 2.35em;
Expand Down
9 changes: 5 additions & 4 deletions projectroles/tests/test_app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,11 @@ def test_set_multi_project_user(self):

def test_set_invalid_project_types(self):
"""Test set() with invalid project types scope"""
# Should fail because project_category_bool_setting has CATEGORY scope
# Should fail because category_bool_setting has CATEGORY scope
with self.assertRaises(ValueError):
app_settings.set(
plugin_name=EXAMPLE_APP_NAME,
setting_name='project_category_bool_setting',
setting_name='category_bool_setting',
project=self.project,
value=True,
)
Expand Down Expand Up @@ -732,7 +732,7 @@ def test_get_definitions_project(self):
'description': 'Example callable project setting with options',
'user_modifiable': True,
},
'project_category_bool_setting': {
'category_bool_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'BOOLEAN',
'label': 'Category boolean setting',
Expand Down Expand Up @@ -880,7 +880,8 @@ def test_get_definitions_project_user(self):
'type': 'STRING',
'default': get_example_setting_default,
'options': get_example_setting_options,
'description': 'Example callable project user setting with options',
'description': 'Example callable project user setting with '
'options',
},
}
defs = app_settings.get_definitions(
Expand Down
65 changes: 32 additions & 33 deletions projectroles/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def make_project(
archive=False,
sodar_uuid=None,
):
"""Make and save a Project"""
"""Create a Project object"""
values = {
'title': title,
'type': type,
Expand Down Expand Up @@ -115,7 +115,7 @@ class RoleAssignmentMixin:

@classmethod
def make_assignment(cls, project, user, role):
"""Make and save a RoleAssignment"""
"""Create a RoleAssignment object"""
values = {'project': project, 'user': user, 'role': role}
result = RoleAssignment(**values)
result.save()
Expand All @@ -136,7 +136,7 @@ def make_invite(
date_expire=None,
secret=None,
):
"""Make and save a ProjectInvite"""
"""Create a ProjectInvite object"""
values = {
'email': email,
'project': project,
Expand Down Expand Up @@ -177,7 +177,7 @@ def make_setting(
user=None,
sodar_uuid=None,
):
"""Make and save a AppSetting"""
"""Create an AppSetting object"""
values = {
'app_plugin': (
None
Expand Down Expand Up @@ -214,7 +214,7 @@ def make_site(
secret=build_secret(),
sodar_uuid=None,
):
"""Make and save a RemoteSite"""
"""Create a RemoteSite object"""
values = {
'name': name,
'url': url,
Expand All @@ -237,7 +237,7 @@ class RemoteProjectMixin:
def make_remote_project(
cls, project_uuid, site, level, date_access=None, project=None
):
"""Make and save a RemoteProject"""
"""Create a RemoteProject object"""
if isinstance(project_uuid, str):
project_uuid = uuid.UUID(project_uuid)
values = {
Expand Down Expand Up @@ -295,6 +295,7 @@ def make_sodar_user(
sodar_uuid=None,
password='password',
):
"""Create a SODARUser object"""
user = self.make_user(username, password)
user.name = name
user.first_name = first_name
Expand Down Expand Up @@ -323,7 +324,7 @@ def make_email(self, user, email, verified=True, secret=None):


class TestProject(ProjectMixin, RoleMixin, RoleAssignmentMixin, TestCase):
"""Tests for model.Project"""
"""Tests for Project"""

def setUp(self):
# Set up category and project
Expand Down Expand Up @@ -436,41 +437,41 @@ def test_get_absolute_url(self):
self.assertEqual(self.project.get_absolute_url(), expected_url)

def test_get_children_category(self):
"""Test children getting function for top category"""
"""Test get_children() with top category"""
children = self.category.get_children()
self.assertEqual(children[0], self.project)

def test_get_children_project(self):
"""Test children getting function for sub project"""
"""Test get_children() with sub project"""
children = self.project.get_children()
self.assertEqual(children.count(), 0)

def test_get_depth_category(self):
"""Test project depth getting function for top category"""
"""Test get_depth() with top category"""
self.assertEqual(self.category.get_depth(), 0)

def test_get_depth_project(self):
"""Test children getting function for sub project"""
"""Test get_depth() with sub project"""
self.assertEqual(self.project.get_depth(), 1)

def test_get_parents_category(self):
"""Test get parents function for top category"""
"""Test get_parents() with top category"""
self.assertEqual(self.category.get_parents(), [])

def test_get_parents_project(self):
"""Test get parents function for sub project"""
"""Test get_parents() with sub project"""
self.assertEqual(list(self.project.get_parents()), [self.category])

def test_is_remote(self):
"""Test Project.is_remote() without remote projects"""
"""Test is_remote() without remote projects"""
self.assertEqual(self.project.is_remote(), False)

def test_is_revoked(self):
"""Test Project.is_revoked() without remote projects"""
"""Test is_revoked() without remote projects"""
self.assertEqual(self.project.is_revoked(), False)

def test_set_public(self):
"""Test Project.set_public()"""
"""Test set_public()"""
self.assertFalse(self.project.public_guest_access)
self.project.set_public() # Default = True
self.assertTrue(self.project.public_guest_access)
Expand All @@ -482,7 +483,7 @@ def test_set_public(self):
self.category.set_public(True)

def test_set_archive(self):
"""Test Project.set_archive()"""
"""Test set_archive()"""
self.assertFalse(self.project.archive)
self.project.set_archive() # Default = True
self.assertTrue(self.project.archive)
Expand All @@ -492,13 +493,13 @@ def test_set_archive(self):
self.assertTrue(self.project.archive)

def test_set_archive_category(self):
"""Test Project.set_archive() for a category (should fail)"""
"""Test set_archive() with category (should fail)"""
self.assertFalse(self.category.archive)
with self.assertRaises(ValidationError):
self.category.set_archive()

def test_get_log_title(self):
"""Test Project.get_log_title()"""
"""Test get_log_title()"""
expected = '"{}" ({})'.format(
self.project.title, self.project.sodar_uuid
)
Expand All @@ -516,7 +517,7 @@ def test_get_role(self):
self.assertEqual(self.project.get_role(self.user_bob), project_as)

def test_get_role_inherit_only(self):
"""Test get_role() with only an inherited role"""
"""Test get_role() with only inherited role"""
self.assertEqual(
self.project.get_role(self.user_alice), self.owner_as_cat
)
Expand Down Expand Up @@ -998,8 +999,8 @@ def setUp(self):
description='YYY',
)

def test_find_all(self):
"""Test find() with any project type"""
def test_find(self):
"""Test find()"""
result = Project.objects.find(['test'], project_type=None)
self.assertEqual(len(result), 2)
result = Project.objects.find(['ThisFails'], project_type=None)
Expand Down Expand Up @@ -1055,7 +1056,7 @@ def test_find_multi_fields(self):
self.assertEqual(len(result), 2)


class TestProjectSetting(
class TestProjectAppSetting(
ProjectMixin, RoleAssignmentMixin, AppSettingMixin, TestCase
):
"""Tests for AppSetting with PROJECT scope"""
Expand Down Expand Up @@ -1193,7 +1194,7 @@ def test_get_value_json(self):
self.assertEqual(val, {'Testing': 'good'})


class TestUserSetting(
class TestUserAppSetting(
ProjectMixin, RoleAssignmentMixin, AppSettingMixin, TestCase
):
"""Tests for AppSetting with USER scope"""
Expand Down Expand Up @@ -1379,7 +1380,7 @@ def test__repr__(self):
self.assertEqual(repr(self.site), expected)

def test_validate_mode(self):
"""Test _validate_mode() with an invalid mode (should fail)"""
"""Test _validate_mode() with invalid mode (should fail)"""
with self.assertRaises(ValidationError):
self.make_site(
name='New site',
Expand Down Expand Up @@ -1538,16 +1539,14 @@ def test_is_revoked_target(self):
@override_settings(PROJECTROLES_SITE_MODE=SITE_MODE_TARGET)
@override_settings(PROJECTROLES_DELEGATE_LIMIT=1)
def test_validate_remote_delegates(self):
"""Test delegate validation: can add for remote project with limit"""
"""Test remot project delegate validation"""
self.site.mode = SITE_MODE_SOURCE
self.site.save()
self.make_assignment(self.project, self.user_bob, self.role_delegate)
try:
self.make_assignment(
self.project, self.user_alice, self.role_delegate
)
except ValidationError as e:
self.fail(e)
remote_as = self.make_assignment(
self.project, self.user_alice, self.role_delegate
)
self.assertIsNotNone(remote_as)

def test_get_project(self):
"""Test get_project() with project and project_uuid"""
Expand Down Expand Up @@ -1577,7 +1576,7 @@ def setUp(self):
self.user = self.make_user()

def test__str__(self):
"""Test __str__()"""
"""Test SODARUser __str__()"""
self.assertEqual(
self.user.__str__(), 'testuser'
) # This is the default username for self.make_user()
Expand Down
2 changes: 1 addition & 1 deletion projectroles/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
PROJECT_SELECT_CSS = 'div[id="div_id_type"] div select[id="id_type"]'
PROJECT_SETTING_ID = 'div_id_settings.example_project_app.project_int_setting'
CATEGORY_SETTING_ID = (
'div_id_settings.example_project_app.project_category_bool_setting'
'div_id_settings.example_project_app.category_bool_setting'
)
PUBLIC_ACCESS_ID = 'id_public_guest_access'
REMOTE_SITE_UUID = uuid.uuid4()
Expand Down
4 changes: 2 additions & 2 deletions projectroles/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ def test_post_top_level_category(self):
settings = AppSetting.objects.filter(project=category)
self.assertEqual(settings.count(), 1)
setting = settings.first()
self.assertEqual(setting.name, 'project_category_bool_setting')
self.assertEqual(setting.name, 'category_bool_setting')

# Assert owner role assignment
owner_as = RoleAssignment.objects.get(
Expand Down Expand Up @@ -1492,7 +1492,7 @@ def test_post_category(self):
settings = AppSetting.objects.filter(project=self.category)
self.assertEqual(settings.count(), 1)
setting = settings.first()
self.assertEqual(setting.name, 'project_category_bool_setting')
self.assertEqual(setting.name, 'category_bool_setting')
# Assert redirect
with self.login(self.user):
self.assertRedirects(
Expand Down
2 changes: 1 addition & 1 deletion projectroles/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@ def test_post_invalid_scope(self):

def test_post_invalid_project_type(self):
"""Test POST with unaccepted project type (should fail)"""
setting_name = 'project_category_bool_setting'
setting_name = 'category_bool_setting'
post_data = {
'plugin_name': EX_APP_NAME,
'setting_name': setting_name,
Expand Down
Loading

0 comments on commit c2ca153

Please sign in to comment.