parent
3f856c3b8c
commit
e305957cbe
|
@ -280,7 +280,10 @@ class HarvesterBase(SingletonPlugin):
|
||||||
data_dict = {}
|
data_dict = {}
|
||||||
data_dict['id'] = package_dict['id']
|
data_dict['id'] = package_dict['id']
|
||||||
try:
|
try:
|
||||||
existing_package_dict = get_action('package_show')(context, data_dict)
|
package_show_context = {'model': model, 'session': Session,
|
||||||
|
'ignore_auth': True}
|
||||||
|
existing_package_dict = get_action('package_show')(
|
||||||
|
package_show_context, data_dict)
|
||||||
|
|
||||||
# In case name has been modified when first importing. See issue #101.
|
# In case name has been modified when first importing. See issue #101.
|
||||||
package_dict['name'] = existing_package_dict['name']
|
package_dict['name'] = existing_package_dict['name']
|
||||||
|
|
|
@ -447,7 +447,6 @@ class CKANHarvester(HarvesterBase):
|
||||||
user = model.User.get(user_name)
|
user = model.User.get(user_name)
|
||||||
pkg_role = model.PackageRole(package=package, user=user, role=model.Role.READER)
|
pkg_role = model.PackageRole(package=package, user=user, role=model.Role.READER)
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except ValidationError,e:
|
except ValidationError,e:
|
||||||
self._save_object_error('Invalid package with GUID %s: %r' % (harvest_object.guid, e.error_dict),
|
self._save_object_error('Invalid package with GUID %s: %r' % (harvest_object.guid, e.error_dict),
|
||||||
|
|
|
@ -440,7 +440,7 @@ REVISIONS = [
|
||||||
"approved_timestamp": None,
|
"approved_timestamp": None,
|
||||||
"packages":
|
"packages":
|
||||||
[
|
[
|
||||||
"dataset1"
|
DATASETS[1]['name']
|
||||||
],
|
],
|
||||||
"groups": [ ]
|
"groups": [ ]
|
||||||
},
|
},
|
||||||
|
@ -452,7 +452,7 @@ REVISIONS = [
|
||||||
"approved_timestamp": None,
|
"approved_timestamp": None,
|
||||||
"packages":
|
"packages":
|
||||||
[
|
[
|
||||||
"dataset1"
|
DATASETS[1]['name']
|
||||||
],
|
],
|
||||||
"groups": [ ]
|
"groups": [ ]
|
||||||
}]
|
}]
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
import copy
|
||||||
from nose.tools import assert_equal
|
from nose.tools import assert_equal
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from mock import patch
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ckan.tests.helpers import reset_db
|
from ckan.tests.helpers import reset_db
|
||||||
from ckan.tests.factories import Organization
|
from ckan.tests.factories import Organization
|
||||||
|
@ -92,15 +95,23 @@ class TestCkanHarvester(object):
|
||||||
run_harvest(
|
run_harvest(
|
||||||
url='http://localhost:%s/' % mock_ckan.PORT,
|
url='http://localhost:%s/' % mock_ckan.PORT,
|
||||||
harvester=CKANHarvester())
|
harvester=CKANHarvester())
|
||||||
|
|
||||||
|
# THIS TEST WILL WORK WHEN FIX #179 IS MERGED
|
||||||
|
from nose.plugins.skip import SkipTest; raise SkipTest()
|
||||||
|
# change the modified date
|
||||||
|
datasets = copy.deepcopy(mock_ckan.DATASETS)
|
||||||
|
datasets[1]['metadata_modified'] = '2050-05-09T22:00:01.486366'
|
||||||
|
with patch('ckanext.harvest.tests.harvesters.mock_ckan.DATASETS',
|
||||||
|
datasets):
|
||||||
results_by_guid = run_harvest(
|
results_by_guid = run_harvest(
|
||||||
url='http://localhost:%s/' % mock_ckan.PORT,
|
url='http://localhost:%s/' % mock_ckan.PORT,
|
||||||
harvester=CKANHarvester())
|
harvester=CKANHarvester())
|
||||||
|
|
||||||
# updated the dataset which has revisions
|
# updated the dataset which has revisions
|
||||||
result = results_by_guid['dataset1']
|
result = results_by_guid[mock_ckan.DATASETS[1]['name']]
|
||||||
assert_equal(result['state'], 'COMPLETE')
|
assert_equal(result['state'], 'COMPLETE')
|
||||||
assert_equal(result['report_status'], 'updated')
|
assert_equal(result['report_status'], 'updated')
|
||||||
assert_equal(result['dataset']['name'], mock_ckan.DATASETS[0]['name'])
|
assert_equal(result['dataset']['name'], mock_ckan.DATASETS[1]['name'])
|
||||||
assert_equal(result['errors'], [])
|
assert_equal(result['errors'], [])
|
||||||
|
|
||||||
# the other dataset is unchanged and not harvested
|
# the other dataset is unchanged and not harvested
|
||||||
|
@ -134,3 +145,22 @@ class TestCkanHarvester(object):
|
||||||
config=json.dumps(config))
|
config=json.dumps(config))
|
||||||
assert 'dataset1-id' in results_by_guid
|
assert 'dataset1-id' in results_by_guid
|
||||||
assert mock_ckan.DATASETS[1]['id'] not in results_by_guid
|
assert mock_ckan.DATASETS[1]['id'] not in results_by_guid
|
||||||
|
|
||||||
|
def test_harvest_not_modified(self):
|
||||||
|
run_harvest(
|
||||||
|
url='http://localhost:%s/' % mock_ckan.PORT,
|
||||||
|
harvester=CKANHarvester())
|
||||||
|
|
||||||
|
results_by_guid = run_harvest(
|
||||||
|
url='http://localhost:%s/' % mock_ckan.PORT,
|
||||||
|
harvester=CKANHarvester())
|
||||||
|
|
||||||
|
# The metadata_modified was the same for this dataset so the import
|
||||||
|
# would have returned None
|
||||||
|
result = results_by_guid[mock_ckan.DATASETS[1]['name']]
|
||||||
|
assert_equal(result['state'], 'COMPLETE')
|
||||||
|
# Strangely this is reported as "deleted", but this will be fixed in
|
||||||
|
# #177 with 'not modified' returned from import_stage
|
||||||
|
assert_equal(result['report_status'], 'deleted')
|
||||||
|
assert 'dataset' not in result
|
||||||
|
assert_equal(result['errors'], [])
|
||||||
|
|
Loading…
Reference in New Issue