Esempio n. 1
0
    def test_cached_get_group_package_stuff(self):
        global num_filter_focus_countries

        # calling the function to make sure it's cached
        caching.cached_get_group_package_stuff()
        # resetting counter
        num_filter_focus_countries = 0

        # the result should have been cached so filter_focus_countries should not be called
        caching.cached_get_group_package_stuff()
        assert (
            num_filter_focus_countries == 0
        ), "number of calls to filter_focus_countries should be 0 , instead {num}".format(
            num=num_filter_focus_countries
        )

        caching.invalidate_group_caches()
        # the result should have been removed from cache so filter_focus_countries should be called
        caching.cached_get_group_package_stuff()
        assert (
            num_filter_focus_countries == 1
        ), "number of calls to filter_focus_countries should be 1 , instead {num}".format(
            num=num_filter_focus_countries
        )

        # the result should have been cached so the num of calls to filter_focus_countries shouldn't increase
        caching.cached_get_group_package_stuff()
        assert (
            num_filter_focus_countries == 1
        ), "number of calls to filter_focus_countries should be 1 , instead {num}".format(
            num=num_filter_focus_countries
        )
Esempio n. 2
0
    def test_cached_group_list(self):
        global num_cached_group_list_called

        # calling the function to make sure it's cached
        tk.get_action("cached_group_list")()
        # resetting counter
        num_cached_group_list_called = 0

        # the result should have been cached so group_list should not be called
        tk.get_action("cached_group_list")()
        assert num_cached_group_list_called == 0, "number of calls to group_list should be 0 , instead {num}".format(
            num=num_cached_group_list_called
        )

        caching.invalidate_group_caches()
        # the result should have been removed from cache so group_list should be called
        tk.get_action("cached_group_list")()
        assert num_cached_group_list_called == 1, "number of calls to group_list should be 1 , instead {num}".format(
            num=num_cached_group_list_called
        )

        # the result should have been cached so the number of calls to group_list shouldn't increase
        tk.get_action("cached_group_list")()
        assert num_cached_group_list_called == 1, "number of calls to group_list should be 1 , instead {num}".format(
            num=num_cached_group_list_called
        )
Esempio n. 3
0
    def setup_class(cls):
#         p.load('metadata_fields')
#         TestMetadataFields.get_app()
        search.clear()
        model.Session.remove()
        ctd.CreateTestData.create()
        # Need to invalidate the caches to make sure the new data is being served
        caching.invalidate_group_caches()
Esempio n. 4
0
    def setup_class(cls):
        cls.original_config = config.copy()

        # so that we can search for strings in the HTTP response
        config['ckan.use_pylons_response_cleanup_middleware'] = False
        cls._change_config(config)

        search.clear_all()
        helpers.reset_db()
        caching.invalidate_group_caches()
        # cls._load_plugins()
        cls.app = _get_test_app()

        cls.replace_package_create()

        cls._create_test_data()
Esempio n. 5
0
    def test_cached_group_list(self):
        global num_cached_group_list_called

        # calling the function to make sure it's cached
        tk.get_action('cached_group_list')()
        # resetting counter
        num_cached_group_list_called = 0

        # the result should have been cached so group_list should not be called
        tk.get_action('cached_group_list')()
        assert num_cached_group_list_called == 0, \
            'number of calls to group_list should be 0 , instead {num}'.format(num=num_cached_group_list_called)

        caching.invalidate_group_caches()
        # the result should have been removed from cache so group_list should be called
        tk.get_action('cached_group_list')()
        assert num_cached_group_list_called == 1, \
            'number of calls to group_list should be 1 , instead {num}'.format(num=num_cached_group_list_called)

        # the result should have been cached so the number of calls to group_list shouldn't increase
        tk.get_action('cached_group_list')()
        assert num_cached_group_list_called == 1, \
            'number of calls to group_list should be 1 , instead {num}'.format(num=num_cached_group_list_called)
Esempio n. 6
0
    def _create_test_data(cls):

        # we need to invalidate the group caches, otherwise we get data from other tests
        caching.invalidate_group_caches()

        super(TestContributeFlowController, cls)._create_test_data()

        # def wrapped_request_config(original=False):
        #     result = original_request_config(original)
        #     result.__setattr__('host', 'test.ckan.org')
        #     result.__setattr__('protocol', 'http')
        #     return result
        #
        # routes_util.request_config = wrapped_request_config

        c = {
            'ignore_auth': True,
            'model': model,
            'session': model.Session,
            'user': '******'
        }

        organization = {
            'name': 'hdx-test-org',
            'title': 'Hdx Test Org',
            'hdx_org_type': ORGANIZATION_TYPE_LIST[0][1],
            'org_acronym': 'HTO',
            'org_url': 'http://test-org.test',
            'description': 'This is a test organization',
            'users': [{
                'name': 'testsysadmin'
            }, {
                'name': 'janedoe3'
            }]
        }

        package = {
            "package_creator": "testsysadmin",
            "private": False,
            "dataset_date": "01/01/1960-12/31/2012",
            "indicator": "0",
            "caveats": "These are the caveats",
            "license_other": "TEST OTHER LICENSE",
            "methodology": "This is a test methodology",
            "dataset_source": "World Bank",
            "license_id": "hdx-other",
            "name": "test_contribute_ds",
            "notes":
            "This is a dataset for testing the contribute flow controller",
            "title": "Test Contribute Dataset",
            "groups": [{
                "name": "roger"
            }],
            "owner_org": "hdx-test-org"
        }

        resource = {
            'package_id': 'test_contribute_ds',
            'url': 'hdx_contribute_test.csv',
            'resource_type': 'file.upload',
            'url_type': 'upload',
            'format': 'CSV',
            'name': 'hdx_contribute_test.csv'
        }

        tk.get_action('organization_create')(c, organization)
        tk.get_action('package_create')(c, package)
        tk.get_action('resource_create')({
            'ignore_auth': True,
            'model': model,
            'session': model.Session,
            'user': '******',
            'return_id_only': True
        }, resource)
Esempio n. 7
0
def invalidate_cache_for_groups(context, data_dict):
    _check_access('invalidate_cache_for_groups', context, data_dict)
    caching.invalidate_group_caches()
Esempio n. 8
0
 def edit(self, entity):
     caching.invalidate_group_caches()
Esempio n. 9
0
 def create(self, entity):
     caching.invalidate_group_caches()