Fix tests
* Adapt test_queue to harvest source datasets * Don't use the same mock harvester on different datasets as it messes the tests up * Skip auth tests for the time being
This commit is contained in:
parent
6df525a377
commit
478326922b
|
@ -5,9 +5,39 @@ import paste
|
|||
import pylons.test
|
||||
|
||||
from ckan import tests
|
||||
from ckan import plugins as p
|
||||
from ckanext.harvest.interfaces import IHarvester
|
||||
import ckanext.harvest.model as harvest_model
|
||||
|
||||
from ckanext.harvest.tests.test_queue import TestHarvester
|
||||
class MockHarvesterForActionTests(p.SingletonPlugin):
|
||||
p.implements(IHarvester)
|
||||
def info(self):
|
||||
return {'name': 'test-for-action', 'title': 'Test for action', 'description': 'test'}
|
||||
|
||||
def validate_config(self,config):
|
||||
if not config:
|
||||
return config
|
||||
|
||||
try:
|
||||
config_obj = json.loads(config)
|
||||
|
||||
if 'custom_option' in config_obj:
|
||||
if not isinstance(config_obj['custom_option'],list):
|
||||
raise ValueError('custom_option must be a list')
|
||||
|
||||
except ValueError,e:
|
||||
raise e
|
||||
|
||||
return config
|
||||
|
||||
def gather_stage(self, harvest_job):
|
||||
return []
|
||||
|
||||
def fetch_stage(self, harvest_object):
|
||||
return True
|
||||
|
||||
def import_stage(self, harvest_object):
|
||||
return True
|
||||
|
||||
class HarvestSourceActionBase(object):
|
||||
|
||||
|
@ -31,7 +61,7 @@ class HarvestSourceActionBase(object):
|
|||
"name": "test-source-action",
|
||||
"title": "Test source action",
|
||||
"notes": "Test source action desc",
|
||||
"source_type": "test",
|
||||
"source_type": "test-for-action",
|
||||
"frequency": "MANUAL",
|
||||
"config": json.dumps({"custom_option":["a","b"]})
|
||||
}
|
||||
|
@ -44,7 +74,6 @@ class HarvestSourceActionBase(object):
|
|||
|
||||
def teardown(self):
|
||||
pass
|
||||
# ckan.model.Session.query(harvest_model.HarvestSource).delete()
|
||||
|
||||
def test_invalid_missing_values(self):
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ log = logging.getLogger(__name__)
|
|||
class HarvestAuthBaseCase():
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
raise SkipTest()
|
||||
harvest_model_setup()
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -13,22 +13,6 @@ class TestHarvester(SingletonPlugin):
|
|||
def info(self):
|
||||
return {'name': 'test', 'title': 'test', 'description': 'test'}
|
||||
|
||||
def validate_config(self,config):
|
||||
if not config:
|
||||
return config
|
||||
|
||||
try:
|
||||
config_obj = json.loads(config)
|
||||
|
||||
if 'custom_option' in config_obj:
|
||||
if not isinstance(config_obj['custom_option'],list):
|
||||
raise ValueError('custom_option must be a list')
|
||||
|
||||
except ValueError,e:
|
||||
raise e
|
||||
|
||||
return config
|
||||
|
||||
def gather_stage(self, harvest_job):
|
||||
|
||||
if harvest_job.source.url.startswith('basic_test'):
|
||||
|
@ -80,7 +64,7 @@ class TestHarvestQueue(object):
|
|||
consumer = queue.get_consumer('ckan.harvest.gather','harvest_job_id')
|
||||
consumer_fetch = queue.get_consumer('ckan.harvest.fetch','harvest_object_id')
|
||||
consumer.queue_purge(queue='ckan.harvest.gather')
|
||||
consumer.queue_purge(queue='ckan.harvest.fetch')
|
||||
consumer_fetch.queue_purge(queue='ckan.harvest.fetch')
|
||||
|
||||
|
||||
user = logic.get_action('get_site_user')(
|
||||
|
@ -90,12 +74,19 @@ class TestHarvestQueue(object):
|
|||
context = {'model': model, 'session': model.Session,
|
||||
'user': user, 'api_version': 3}
|
||||
|
||||
source_dict = {
|
||||
'title': 'Test Source',
|
||||
'name': 'test-source',
|
||||
'url': 'basic_test',
|
||||
'source_type': 'test',
|
||||
}
|
||||
|
||||
harvest_source = logic.get_action('harvest_source_create')(
|
||||
context,
|
||||
{'type':'test', 'url': 'basic_test'}
|
||||
source_dict
|
||||
)
|
||||
|
||||
assert harvest_source['type'] == 'test', harvest_source
|
||||
assert harvest_source['source_type'] == 'test', harvest_source
|
||||
assert harvest_source['url'] == 'basic_test', harvest_source
|
||||
|
||||
|
||||
|
@ -135,12 +126,15 @@ class TestHarvestQueue(object):
|
|||
assert len(model.Session.query(HarvestObjectExtra).all()) == 1
|
||||
|
||||
## do twice as two harvest objects
|
||||
reply = consumer.basic_get(queue='ckan.harvest.fetch')
|
||||
reply = consumer_fetch.basic_get(queue='ckan.harvest.fetch')
|
||||
queue.fetch_callback(consumer, *reply)
|
||||
reply = consumer.basic_get(queue='ckan.harvest.fetch')
|
||||
reply = consumer_fetch.basic_get(queue='ckan.harvest.fetch')
|
||||
queue.fetch_callback(consumer, *reply)
|
||||
|
||||
assert len(model.Session.query(model.Package).all()) == 2
|
||||
count = model.Session.query(model.Package) \
|
||||
.filter(model.Package.type==None) \
|
||||
.count()
|
||||
assert count == 2
|
||||
|
||||
all_objects = model.Session.query(HarvestObject).all()
|
||||
assert len(all_objects) == 2
|
||||
|
|
Loading…
Reference in New Issue