Skip to content

Commit

Permalink
HDX-9010 - adding test and validator for title (include inactive)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmihaila committed Sep 19, 2023
1 parent da6c26e commit 6f15b8b
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,21 @@ def active_if_missing(key, data, errors, context):
if value is missing or value is None:
data[key] = 'active'

def set_inactive_if_closed_organization(key, data, errors, context):
value = data.get(key)
title = data.get(('title',))
if title:
if value=='true' or value=='True':
title= title.replace('(closed)','')
if not 'inactive' in title:
if title.endswith(' '):
title = title + '(inactive)'
else:
title = title + ' (inactive)'
else:
title = title.replace('(closed)', '')
title = title.replace('(inactive)', '')
if title.endswith(' '):
title = title[:-1]
data[('title',)]= title

232 changes: 116 additions & 116 deletions ckanext-hdx_org_group/ckanext/hdx_org_group/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_actions(self):
'invalidate_data_completeness_for_location': update_actions.invalidate_data_completeness_for_location,
'hdx_organization_follower_list': get_actions.hdx_organization_follower_list,
'hdx_user_invite': create_actions.hdx_user_invite,
'member_create': create_actions.hdx_member_create
'member_create': create_actions.hdx_member_create

}

Expand Down Expand Up @@ -106,8 +106,8 @@ def get_validators(self):
return {
'correct_hdx_org_type': custom_validator.general_value_in_list(org_type_keys, False),
'hdx_org_keep_prev_value_if_empty_unless_sysadmin': org_custom_validator.hdx_org_keep_prev_value_if_empty_unless_sysadmin,
'active_if_missing': org_custom_validator.active_if_missing

'active_if_missing': org_custom_validator.active_if_missing,
'set_inactive_if_closed_organization': org_custom_validator.set_inactive_if_closed_organization
}

def _modify_group_schema(self, schema):
Expand All @@ -122,7 +122,9 @@ def _modify_group_schema(self, schema):
tk.get_converter('convert_to_extras')],
'custom_org': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
'request_membership': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
'closed_organization': [tk.get_validator('hdx_boolean_string_converter'), tk.get_converter('convert_to_extras')],
'closed_organization': [tk.get_validator('hdx_boolean_string_converter'),
tk.get_validator('set_inactive_if_closed_organization'),
tk.get_converter('convert_to_extras')],
'customization': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
# 'less': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
'visualization_config': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
Expand Down Expand Up @@ -191,118 +193,118 @@ def db_to_form_schema(self):
return None

# def after_map(self, map):
# map.connect('organization_read', '/organization/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='read')
# map.connect('organization_members', '/organization/members/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='members')
# map.connect('organization_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# map.connect('organization_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# map.connect('organization_activity_offset', '/organization/activity/{id}/{offset}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# return map
# map.connect('organization_read', '/organization/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='read')
# map.connect('organization_members', '/organization/members/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='members')
# map.connect('organization_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# map.connect('organization_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# map.connect('organization_activity_offset', '/organization/activity/{id}/{offset}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# return map

# def before_map(self, map):
# map.connect('organization_bulk_process',
# '/organization/bulk_process/{org_id}',
# controller='ckanext.hdx_org_group.controllers.redirect_controller:RedirectController',
# action='redirect_to_org_list')
# map.connect('organization_bulk_process_no_id', '/organization/bulk_process',
# controller='ckanext.hdx_org_group.controllers.redirect_controller:RedirectController',
# action='redirect_to_org_list')
# map.connect('organizations_index', '/organization',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='index')
# map.connect('organization_new', '/organization/new',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='new')
# map.connect('organization_edit', '/organization/edit/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='edit', ckan_icon='edit')
# map.connect('request_membership', '/organization/{org_id}/request_membership',
# controller='ckanext.hdx_org_group.controllers.request_controller:HDXReqsOrgController', action='request_membership')
# map.connect('request_editing_rights', '/organization/{org_id}/request_editing_rights',
# controller='ckanext.hdx_org_group.controllers.request_controller:HDXReqsOrgController',
# action='request_editor_for_org')
# map.connect('/organization/request_new',
# controller='ckanext.hdx_org_group.controllers.request_controller:HDXReqsOrgController',
# action='request_new_organization')
# map.connect('organization_members',
# '/organization/members/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='members')
# map.connect(
# '/organization/member_new/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='member_new')
# map.connect(
# '/organization/member_delete/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='member_delete')

# map.connect('/organization/bulk_member_new/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='bulk_member_new')

# map.connect('organization_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream'
# # conditions={'function': organization_controller.is_not_custom}
# )
# map.connect('organization_activity_offset', '/organization/activity/{id}/{offset:([0-9]+)}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# map.connect('custom_org_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.custom_org_controller:CustomOrgController',
# action='activity_stream')

# since the pattern of organization_read is so general it needs to be the last
# otherwise it will override other /organization routes
# map.connect('organization_read', '/organization/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='read')

# map.connect('hdx_organization_stats', '/organization/stats/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='stats')

# map.connect('browse_list', '/browse',
# controller='ckanext.hdx_org_group.controllers.browse_controller:BrowseController', action='index')

# map.connect('browse_list', '/browse',
# controller='ckanext.hdx_org_group.controllers.redirect_controller:RedirectController',
# action='redirect_to_group_list')

# map.connect('group_index', '/group',
# controller='ckanext.hdx_org_group.controllers.group_controller:HDXGroupController', action='index',
# highlight_actions='index search')
# map.connect('group_worldmap', '/worldmap',
# controller='ckanext.hdx_org_group.controllers.group_controller:HDXGroupController', action='group_worldmap')
#
# map.connect('group_eaa_worldmap', '/eaa-worldmap',
# controller='ckanext.hdx_org_group.controllers.group_controller:HDXGroupController', action='group_eaa_worldmap')

# map.connect('group_new', '/group/new', controller='group', action='new')

# map.connect('country_read', '/group/{id}',
# controller='ckanext.hdx_org_group.controllers.country_controller:CountryController', action='country_read')
#
# map.connect('country_topline', '/country/topline/{id}',
# controller='ckanext.hdx_org_group.controllers.country_controller:CountryController', action='country_topline')

# map.connect('feed_org_atom', '/feeds/organization/{id}.atom', controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='feed_organization')

# map.connect(
# 'custom_org_read', '/org/{id}', controller='ckanext.hdx_org_group.controllers.custom_org_controller:CustomOrgController', action='org_read')

# return map
# map.connect('organization_bulk_process',
# '/organization/bulk_process/{org_id}',
# controller='ckanext.hdx_org_group.controllers.redirect_controller:RedirectController',
# action='redirect_to_org_list')
# map.connect('organization_bulk_process_no_id', '/organization/bulk_process',
# controller='ckanext.hdx_org_group.controllers.redirect_controller:RedirectController',
# action='redirect_to_org_list')
# map.connect('organizations_index', '/organization',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='index')
# map.connect('organization_new', '/organization/new',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='new')
# map.connect('organization_edit', '/organization/edit/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='edit', ckan_icon='edit')
# map.connect('request_membership', '/organization/{org_id}/request_membership',
# controller='ckanext.hdx_org_group.controllers.request_controller:HDXReqsOrgController', action='request_membership')
# map.connect('request_editing_rights', '/organization/{org_id}/request_editing_rights',
# controller='ckanext.hdx_org_group.controllers.request_controller:HDXReqsOrgController',
# action='request_editor_for_org')
# map.connect('/organization/request_new',
# controller='ckanext.hdx_org_group.controllers.request_controller:HDXReqsOrgController',
# action='request_new_organization')
# map.connect('organization_members',
# '/organization/members/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='members')
# map.connect(
# '/organization/member_new/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='member_new')
# map.connect(
# '/organization/member_delete/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='member_delete')

# map.connect('/organization/bulk_member_new/{id}',
# controller='ckanext.hdx_org_group.controllers.member_controller:HDXOrgMemberController',
# action='bulk_member_new')

# map.connect('organization_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream'
# # conditions={'function': organization_controller.is_not_custom}
# )
# map.connect('organization_activity_offset', '/organization/activity/{id}/{offset:([0-9]+)}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='activity_stream')
# map.connect('custom_org_activity', '/organization/activity/{id}',
# controller='ckanext.hdx_org_group.controllers.custom_org_controller:CustomOrgController',
# action='activity_stream')

# since the pattern of organization_read is so general it needs to be the last
# otherwise it will override other /organization routes
# map.connect('organization_read', '/organization/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='read')

# map.connect('hdx_organization_stats', '/organization/stats/{id}',
# controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='stats')

# map.connect('browse_list', '/browse',
# controller='ckanext.hdx_org_group.controllers.browse_controller:BrowseController', action='index')

# map.connect('browse_list', '/browse',
# controller='ckanext.hdx_org_group.controllers.redirect_controller:RedirectController',
# action='redirect_to_group_list')

# map.connect('group_index', '/group',
# controller='ckanext.hdx_org_group.controllers.group_controller:HDXGroupController', action='index',
# highlight_actions='index search')
# map.connect('group_worldmap', '/worldmap',
# controller='ckanext.hdx_org_group.controllers.group_controller:HDXGroupController', action='group_worldmap')
#
# map.connect('group_eaa_worldmap', '/eaa-worldmap',
# controller='ckanext.hdx_org_group.controllers.group_controller:HDXGroupController', action='group_eaa_worldmap')

# map.connect('group_new', '/group/new', controller='group', action='new')

# map.connect('country_read', '/group/{id}',
# controller='ckanext.hdx_org_group.controllers.country_controller:CountryController', action='country_read')
#
# map.connect('country_topline', '/country/topline/{id}',
# controller='ckanext.hdx_org_group.controllers.country_controller:CountryController', action='country_topline')

# map.connect('feed_org_atom', '/feeds/organization/{id}.atom', controller='ckanext.hdx_org_group.controllers.organization_controller:HDXOrganizationController',
# action='feed_organization')

# map.connect(
# 'custom_org_read', '/org/{id}', controller='ckanext.hdx_org_group.controllers.custom_org_controller:CustomOrgController', action='org_read')

# return map

# IOrganizationController
def create(self, org):
Expand Down Expand Up @@ -387,7 +389,6 @@ def form_to_db_schema(self):

# IGroupForm
def db_to_form_schema(self):

schema = super(HDXGroupPlugin, self).form_to_db_schema()
schema.update({
'language_code': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
Expand Down Expand Up @@ -446,4 +447,3 @@ def get_blueprint(self):
import ckanext.hdx_org_group.views.group as group
import ckanext.hdx_org_group.views.light_group as light_group
return [group.hdx_group, group.hdx_country_topline, light_group.hdx_light_group, light_group.hdx_group_eaa_maps]

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'''
reCreated on 19 Sep, 2023
@author: dan
'''

import pytest
import logging as logging
import ckan.model as model
import ckan.plugins.toolkit as tk

_get_action = tk.get_action
NotAuthorized = tk.NotAuthorized
log = logging.getLogger(__name__)


@pytest.mark.usefixtures('keep_db_tables_on_clean', 'clean_db', 'clean_index', 'setup_user_data',
'with_request_context')
class TestClosedOrg(object):

def test_closed_organization(self, app):

orgadmin = 'orgadmin'
context = {'model': model, 'session': model.Session, 'user': orgadmin}

org_dict = _get_action('organization_show')(context, {'id': 'hdx-test-org', 'include_users':True})

org_dict['closed_organization'] = True
result = _get_action('organization_update')(context, org_dict)
org_dict = _get_action('organization_show')(context, {'id': 'hdx-test-org', 'include_users':True})
assert '(inactive)' in org_dict.get('title')

org_dict['closed_organization'] = False
context = {'model': model, 'session': model.Session, 'user': orgadmin}
result = _get_action('organization_update')(context, org_dict)
org_dict = _get_action('organization_show')(context, {'id': 'hdx-test-org', 'include_users':True})
assert '(inactive)' not in org_dict.get('title')

org_dict['closed_organization'] = True
org_dict['title'] = 'HDX TEST ORG 123 (closed)'
context = {'model': model, 'session': model.Session, 'user': orgadmin}
result = _get_action('organization_update')(context, org_dict)
org_dict = _get_action('organization_show')(context, {'id': 'hdx-test-org'})
assert '(inactive)' in org_dict.get('title')
assert '123' in org_dict.get('title')
Loading

0 comments on commit 6f15b8b

Please sign in to comment.