def test_generate_template_data(self, helper_c_mock, controller_c_mock,
                                    req_mock, data_access_cls):
        def mock_get_top_line_items():
            return top_line_items

        data_access_cls.return_value.get_top_line_items.side_effect = mock_get_top_line_items
        req_mock.params = {}
        controller_c_mock.user = '******'
        custom_org_controller = controller.CustomOrgController()
        org_info = {
            'display_name': 'HDX Test Org',
            'name': 'hdx-test-org',
            'id': 'hdx-test-org',
            'visualization_config': json_config_wfp,
            'topline_resource': 'test-topline-resource'
        }

        template_data = custom_org_controller.generate_template_data(org_info)

        assert 'data' in template_data and 'top_line_items' in template_data[
            'data']

        top_lines = template_data['data']['top_line_items']
        assert len(top_lines) == 1

        assert top_lines[0]['latest_date'] == 'Jun 01, 2015'
        assert top_lines[0]['formatted_value'] == '34.6'

        assert 'member_count' in template_data['data']
        assert template_data['data']['member_count'] == 4
    def activity_stream(self, id, org_meta=None, offset=0):
        '''
         Modified core functionality to use the new OrgMetaDao class
        for fetching information needed on all org-related pages.

        Render this group's public activity stream page.

        :param id:
        :type id: str
        :param offset:
        :type offset: int
        :param org_meta:
        :type org_meta: org_meta_dao.OrgMetaDao
        :return:
        '''
        if not org_meta:
            org_meta = org_meta_dao.OrgMetaDao(id, c.user or c.author, c.userobj)
        c.org_meta = org_meta
        org_meta.fetch_all()

        c.group_dict = org_meta.org_dict

        # Add the group's activity stream (already rendered to HTML) to the
        # template context for the group/read.html template to retrieve later.
        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author, 'for_view': True}
        c.group_activity_stream = self._action('group_activity_list_html')(
            context, {'id': c.group_dict['id'], 'offset': offset})

        if org_meta.is_custom:
            return render(custom_org.CustomOrgController()._activity_template('organization'))
        else:
            return render(self._activity_template('organization'))
    def test_assemble_viz_config(self):
        custom_org_controller = controller.CustomOrgController()

        # Testing the WFP viz part
        config = custom_org_controller.assemble_viz_config(json_config_wfp)

        assert config == {
            'title': 'Test Visualization Title',
            'data_link_url':
            'https://data.humdata.org/dataset/wfp-food-prices',
            'type': 'WFP',
            'embedded': 'true',
            # 'resource_id': 'test-resource-id',
            'datastore_id': 'test-resource-id'
        }

        # Testing the 3W viz part
        config = custom_org_controller.assemble_viz_config(json_config_3w)

        assert config, 'Config dict should not be empty'
        assert config == {
            'type': '3W-dashboard',
            'title': "Who's doing what and where ?",
            'geotype': 'filestore',
            'geo':
            '/dataset/json-repository/resource_download/07c835cd-7b47-4d76-97e0-ff0fd5cc09c5',
            'data_link_url':
            'https://data.humdata.org/dataset/3w-matrix-for-somalia-ngo-consortium',
            'data':
            '/api/action/datastore_search?resource_id=1d5b6821-fe99-4a5d-a0cf-d6987868027b&limit=10000000',
            'datatype': 'datastore',
            'joinAttribute': 'DIS_CODE',
            'whereFieldName': 'DIST_NO',
            'whoFieldName': 'Organisation',
            'whatFieldName': 'Sector',
            'startFieldName': '2000',
            'endFieldName': '2015',
            'formatFieldName': 'YYYY/MM/DD',
            'nameAttribute': 'DIST_NAME',
            'colors': ["red", "green", "blue"]
        }
Пример #4
0
        c.org_meta = org_meta = org_meta_dao.OrgMetaDao(
            id, c.user or c.author, c.userobj)
        try:
            org_meta.fetch_all()
        except NotFound, e:
            abort(404)
        except NotAuthorized, e:
            abort(403, _('Not authorized to see this page'))

        helper.org_add_last_updated_field([org_meta.org_dict])

        c.group_dict = org_meta.org_dict

        # If custom_org set to true, redirect to the correct route
        if org_meta.is_custom:
            custom_org_controller = custom_org.CustomOrgController()
            return custom_org_controller.org_read(id, org_meta)
        else:
            org_info = self._get_org(id)
            c.full_facet_info = self._get_dataset_search_results(
                org_info['name'])

            # setting the count with the value that was populated from search_controller so that templates find it
            c.group_dict['package_count'] = c.count
            c.group_dict['type'] = 'organization'

            # This was moved in OrgMetaDao
            # allow_basic_user_info = self.check_access('hdx_basic_user_info')
            # allow_req_membership = not h.user_in_org_or_group(org_info['id']) and allow_basic_user_info
            # c.request_membership = allow_req_membership
            # c.request_membership_url = h.url_for('request_membership', org_id=org_info['id'])