Skip to content

Commit

Permalink
Refactor test harvester classes
Browse files Browse the repository at this point in the history
After changes in ckan/ckan#7976 all plugins need to be instances of
`p.SingletonPlugin`, they can't inherit from a base class that is an
instance.

eg move from this:

```
class TestRDFHarvester(p.SingletonPlugin):

    p.implements(IDCATRDFHarvester)

    def some_method(self):
        pass

class TestRDFNullHarvester(TestRDFHarvester):

    p.implements(IDCATRDFHarvester)
```

To this

```
class BaseRDFHarvester():

    def some_method(self):
        pass

class TestRDFHarvester(p.SingletonPlugin, BaseRDFHarvester):

    p.implements(IDCATRDFHarvester)

class TestRDFNullHarvester(TestRDFHarvester, BaseRDFHarvester):

    p.implements(IDCATRDFHarvester)

```
  • Loading branch information
amercader committed Jun 10, 2024
1 parent 1479ccd commit 83495ba
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ckanext/dcat/tests/test_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def wrapper(plugin_name):
return wrapper


class TestRDFHarvester(p.SingletonPlugin):

p.implements(IDCATRDFHarvester)
class BaseTestRDFHarvester(object):

calls = defaultdict(int)
# change return values of after_parsing via this parameter
Expand Down Expand Up @@ -111,8 +109,14 @@ def update_package_schema_for_update(self, package_schema):
return package_schema


class TestRDFNullHarvester(TestRDFHarvester):
class TestRDFHarvester(p.SingletonPlugin, BaseTestRDFHarvester):

p.implements(IDCATRDFHarvester)


class TestRDFNullHarvester(p.SingletonPlugin, BaseTestRDFHarvester):
p.implements(IDCATRDFHarvester)

def before_update(self, harvest_object, dataset_dict, temp_dict):
super(TestRDFNullHarvester, self).before_update(harvest_object, dataset_dict, temp_dict)
dataset_dict.clear()
Expand All @@ -122,7 +126,7 @@ def before_create(self, harvest_object, dataset_dict, temp_dict):
dataset_dict.clear()


class TestRDFExceptionHarvester(TestRDFHarvester):
class TestRDFExceptionHarvester(p.SingletonPlugin, BaseTestRDFHarvester):
p.implements(IDCATRDFHarvester)

raised_exception = False
Expand Down Expand Up @@ -1498,7 +1502,6 @@ def test_harvest_import_extensions_point_gets_called(self, reset_calls_counter):
status=405, content_type=content_type)

harvest_source = self._create_harvest_source(url)

# First run, will create two datasets as previously tested
self._run_full_job(harvest_source['id'], num_objects=2)

Expand Down

0 comments on commit 83495ba

Please sign in to comment.