Changeset 856:53f62c87b551
- Timestamp:
- 03/10/10 12:23:28 (6 months ago)
- Author:
- johnbywater
- Branch:
- default
- Message:
-
Adding compatibility with licenses service v2.0.
Known outstanding issues:
- there are 2 errors in the test suite
- there are 4 failing tests in the test suite
These items are still to be done (some need discussion):
- testing 'dsl' instead of crown copyright (non-open licenses still need to be added to licenses v2.0 package data)
- fix licenses package to have non-open licenses
- change license_id in forms (should be license)
- redo commented licenses asserts in functional/test_package
- redo commented licenses asserts in functional/test_rest
- clean up long list of "SAWarning: Unicode type received non-unicode bind param value" generated when testing (from test package form?)
- create mapper from old license names to new license ids
- make migration script switch license_id on all packages
- graceful degredation for missing licenses (package has a license_id which doesn't exist for some reason)
- make license_id revisioned?
- Location:
- ckan
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r827
|
r856
|
|
| 186 | 186 | |
| 187 | 187 | class LicenseRenderer(formalchemy.fields.FieldRenderer): |
| 188 | | def render(self, options, **kwargs): |
| | 188 | |
| | 189 | def render(self, **kwargs): |
| 189 | 190 | selected = unicode(kwargs.get('selected', None) or self._value) |
| 190 | | options = [('', None)] + [(x, unicode(model.License.by_name(x).id)) for x in model.LicenseList.all_formatted] |
| | 191 | options = [('', None)] + model.Package.get_license_options() |
| 191 | 192 | return literal(h.select(self.name, h.options_for_select(options, selected=selected), **kwargs)) |
| 192 | 193 | |
| 193 | 194 | def render_readonly(self, **kwargs): |
| 194 | | if self._value: |
| 195 | | license_name = model.Session.query(model.License).get(int(self._value)).name |
| 196 | | else: |
| 197 | | license_name = '' |
| 198 | | return common.field_readonly_renderer(self.field.key, license_name) |
| | 195 | return common.field_readonly_renderer(self.field.key, self._value) |
| 199 | 196 | |
| 200 | 197 | |
| … |
… |
|
| 397 | 394 | ).with_renderer(common.CustomTextFieldRenderer |
| 398 | 395 | ).validate(package_name_validator), |
| 399 | | fs.license.with_renderer(LicenseRenderer), |
| | 396 | fs.license_id.with_renderer(LicenseRenderer), |
| 400 | 397 | fs.title.with_renderer(common.CustomTextFieldRenderer), |
| 401 | 398 | fs.version.with_renderer(common.CustomTextFieldRenderer), |
| … |
… |
|
| 410 | 407 | pkgs = [fs.name, fs.title, fs.version, fs.url, fs.resources, |
| 411 | 408 | fs.author, fs.author_email, fs.maintainer, fs.maintainer_email, |
| 412 | | fs.license, fs.tags, fs.notes, ] |
| | 409 | fs.license_id, fs.tags, fs.notes, ] |
| 413 | 410 | if is_admin: |
| 414 | 411 | pkgs.append(fs.state) |
| … |
… |
|
| 523 | 520 | dict_[resources_key].insert(0, (value, u'', u'', u'')) |
| 524 | 521 | # blank format, description and hash |
| | 522 | elif key == license_id_key: |
| | 523 | dict_[license_id_key] = unicode(value) |
| 525 | 524 | elif key == license_key: |
| 526 | | license_ = model.License.by_name(value) |
| 527 | | assert license_, 'License name unknown: %r' % value |
| 528 | | dict_[license_id_key] = unicode(license_.id) |
| | 525 | dict_[license_id_key] = unicode(value) |
| 529 | 526 | return dict_ |
| 530 | 527 | |
-
|
r777
|
r856
|
|
| 262 | 262 | |
| 263 | 263 | options = package.get_package_fs_options(fs) |
| 264 | | include = [fs.name, fs.title, fs.external_reference, fs.notes, fs.date_released, fs.date_updated, fs.update_frequency, fs.geographic_granularity, fs.geographic_coverage, fs.temporal_granularity, fs.temporal_coverage, fs.categories, fs.national_statistic, fs.precision, fs.url, fs.resources, fs.taxonomy_url, fs.department, fs.agency, fs.author, fs.author_email, fs.maintainer, fs.maintainer_email, fs.license, fs.tags, ] |
| | 264 | include = [fs.name, fs.title, fs.external_reference, fs.notes, fs.date_released, fs.date_updated, fs.update_frequency, fs.geographic_granularity, fs.geographic_coverage, fs.temporal_granularity, fs.temporal_coverage, fs.categories, fs.national_statistic, fs.precision, fs.url, fs.resources, fs.taxonomy_url, fs.department, fs.agency, fs.author, fs.author_email, fs.maintainer, fs.maintainer_email, fs.license_id, fs.tags, ] |
| 265 | 265 | options += [fs.tags.with_renderer(SuggestTagRenderer)] |
| 266 | 266 | if fs != package_gov_fs: |
-
|
r808
|
r856
|
|
| 140 | 140 | _dict['%s - standard' % field] == 'Other (specify)' else \ |
| 141 | 141 | _dict['%s - standard' % field] |
| 142 | | if 'HESA' in _dict['licence']: |
| 143 | | license_str = u'OKD Compliant::Higher Education Statistics Agency Copyright with data.gov.uk rights' |
| 144 | | else: |
| 145 | | license_str = u'OKD Compliant::UK Crown Copyright with data.gov.uk rights' |
| | 142 | #if 'HESA' in _dict['licence']: |
| | 143 | # license_title = u'OKD Compliant::Higher Education Statistics Agency Copyright with data.gov.uk rights' |
| | 144 | #else: |
| | 145 | # license_title = u'OKD Compliant::UK Crown Copyright with data.gov.uk rights' |
| 146 | 146 | |
| 147 | 147 | # extras |
| … |
… |
|
| 240 | 240 | pkg.add_resource(resource['url'], format=format, description=resource['description']) |
| 241 | 241 | pkg.notes=notes |
| 242 | | pkg.license = model.License.by_name(license_str) |
| | 242 | pkg.license_id = u'dsl' # Todo: Fix this. model.License.by_name(license_str) |
| 243 | 243 | assert pkg.license |
| 244 | 244 | if not existing_pkg: |
-
|
r808
|
r856
|
|
| 123 | 123 | pkg.add_resource(res_url, description=res_description) |
| 124 | 124 | pkg.notes=notes |
| 125 | | license_str = u'OKD Compliant::UK Crown Copyright with data.gov.uk rights' |
| 126 | | pkg.license = model.License.by_name(license_str) |
| | 125 | pkg.license_id = u'dsl' # Todo: Fix this. |
| 127 | 126 | if not existing_pkg: |
| 128 | 127 | user = model.User.by_name(self._username) |
-
|
r808
|
r856
|
|
| 119 | 119 | pkg.title = title |
| 120 | 120 | pkg.notes = '\n\n'.join(notes_list) |
| 121 | | pkg.license = model.Session.query(model.License).get(self._crown_license_id) |
| | 121 | pkg.license_id = self._crown_license_id |
| 122 | 122 | pkg.extras = extras |
| 123 | 123 | if extras['department']: |
| … |
… |
|
| 190 | 190 | self._item_count = 0 |
| 191 | 191 | self._new_package_count = 0 |
| 192 | | license_str = u'OKD Compliant::UK Crown Copyright with data.gov.uk rights' |
| 193 | | self._crown_license_id = model.License.by_name(license_str).id |
| | 192 | self._crown_license_id = u'dsl' # Todo: Fix this. |
| 194 | 193 | |
| 195 | 194 | |
-
|
r809
|
r856
|
|
| 108 | 108 | pkg.groups.append(group) |
| 109 | 109 | elif attr == 'license': |
| 110 | | license = model.License.by_name(val) |
| 111 | | pkg.license = license |
| | 110 | pkg.license_id = val |
| 112 | 111 | elif attr == 'license_id': |
| 113 | | license = model.Session.query(model.License).get(val) |
| 114 | | pkg.license = license |
| | 112 | pkg.license_id = val |
| 115 | 113 | elif attr == 'extras': |
| 116 | 114 | pkg.extras = val |
| … |
… |
|
| 202 | 200 | pkg2.tags = [ tag1 ] |
| 203 | 201 | self.tag_names = [u'russian', u'tolstoy'] |
| 204 | | license1 = model.License.by_name(u'OKD Compliant::Other') |
| 205 | | pkg1.license = license1 |
| | 202 | pkg1.license_id = u'agpl-v3' |
| 206 | 203 | pkg2.title = u'A Wonderful Story' |
| 207 | 204 | genre_extra = model.PackageExtra(key=u'genre', value='romantic novel') |
| … |
… |
|
| 282 | 279 | 'tags':'registry country-usa government federal gov workshop-20081101', |
| 283 | 280 | 'groups':'ukgov test1 test2 penguin', |
| 284 | | 'license':'OKD Compliant::Other', |
| | 281 | 'license':'agpl-v3', |
| 285 | 282 | 'notes':'''From <http://www.gpoaccess.gov/gils/about.html> |
| 286 | 283 | |
| … |
… |
|
| 295 | 292 | 'tags':'images graphics photographs photos pictures us usa america history wildlife nature war military todo-split gov', |
| 296 | 293 | 'groups':'ukgov test1 penguin', |
| 297 | | 'license':'OKD Compliant::Other', |
| | 294 | 'license':'agpl-v3', |
| 298 | 295 | 'notes':'''## About |
| 299 | 296 | |
| … |
… |
|
| 311 | 308 | 'tags':'us courts case-law us courts case-law gov legal law access-bulk penguins penguin', |
| 312 | 309 | 'groups':'ukgov test2 penguin', |
| 313 | | 'license':'OKD Compliant::Creative Commons CCZero', |
| | 310 | 'license':'cc-zero', |
| 314 | 311 | 'notes':'''### Description |
| 315 | 312 | |
| … |
… |
|
| 333 | 330 | 'groups':'penguin', |
| 334 | 331 | 'tags':'country-sweden format-pdf access-www documents publications government eutransparency', |
| 335 | | 'license':'Other::License Not Specified', |
| | 332 | 'license':'', |
| 336 | 333 | 'notes':'''### About |
| 337 | 334 | |
| … |
… |
|
| 349 | 346 | 'download_url':'http://www.opengov.se/data/open/', |
| 350 | 347 | 'tags':'country-sweden government data', |
| 351 | | 'license':'OKD Compliant::Creative Commons Attribution-ShareAlike', |
| | 348 | 'license':'cc-by-sa', |
| 352 | 349 | 'notes':'''### About |
| 353 | 350 | |
| … |
… |
|
| 377 | 374 | 'author':'DCSF Data Services Group', |
| 378 | 375 | 'author_email':'statistics@dcsf.gsi.gov.uk', |
| 379 | | 'license':'Non-OKD Compliant::Crown Copyright', |
| | 376 | 'license':'dsl', |
| 380 | 377 | 'tags':'children fostering', |
| 381 | 378 | 'extras':{ |
| … |
… |
|
| 404 | 401 | 'author':'DECC Energy Statistics Team', |
| 405 | 402 | 'author_email':'energy.stats@decc.gsi.gov.uk', |
| 406 | | 'license':'Non-OKD Compliant::Crown Copyright', |
| | 403 | 'license':'dsl', |
| 407 | 404 | 'tags':'fuel prices', |
| 408 | 405 | 'extras':{ |
-
|
r693
|
r856
|
|
| 55 | 55 | model_classes = [ |
| 56 | 56 | # ckan.model.State, |
| 57 | | ckan.model.License, |
| 58 | 57 | ckan.model.Revision, |
| 59 | 58 | ckan.model.Package, |
-
|
r824
|
r856
|
|
| 63 | 63 | # remove everything from session so nothing can get saved accidentally |
| 64 | 64 | model.Session.clear() |
| 65 | | # license field's _id only updated, not object.id, so cludge that: |
| 66 | | if fs.model.license_id: |
| 67 | | fs.model.license = model.Session.query(model.License).get(fs.model.license_id) |
| 68 | 65 | return out |
| 69 | 66 | |
-
|
r792
|
r856
|
|
| 5 | 5 | |
| 6 | 6 | import ckan.model as model |
| 7 | | from licenses import LicenseList |
| 8 | 7 | |
| 9 | 8 | ENABLE_CACHING = bool(config.get('enable_caching', '')) |
| … |
… |
|
| 274 | 273 | return query |
| 275 | 274 | |
| 276 | | def _update_open_licenses(self): |
| | 275 | def _update_open_licenses(self): # Update, or init? |
| 277 | 276 | self._open_licenses = [] |
| 278 | | for license_name in LicenseList.all_formatted: |
| 279 | | _license = model.License.by_name(license_name, autoflush=False) |
| 280 | | if _license and _license.isopen(): |
| 281 | | self._open_licenses.append(_license.id) |
| | 277 | for license in model.Package.get_license_register().values(): |
| | 278 | if license and license.isopen(): |
| | 279 | self._open_licenses.append(license.id) |
| 282 | 280 | |
| 283 | 281 | def _format_results(self): |
-
|
r845
|
r856
|
|
| 8 | 8 | from rating import * |
| 9 | 9 | from package_relationship import PackageRelationship |
| 10 | | |
| 11 | | from pylons import config |
| 12 | | import urllib2 |
| 13 | | import simplejson |
| 14 | | class LicensesService(object): |
| 15 | | |
| 16 | | default_url = 'http://licenses.opendefinition.org/1.0/all_formatted' |
| 17 | | |
| 18 | | def get_names(self): |
| 19 | | url = config.get('licenses_service_url', self.default_url) |
| 20 | | print "Loading licenses from licenses service: %s" % url |
| 21 | | try: |
| 22 | | response = urllib2.urlopen(url) |
| 23 | | response_body = response.read() |
| 24 | | except Exception, inst: |
| 25 | | msg = "Couldn't connect to licenses service: %s" % inst |
| 26 | | raise Exception, msg |
| 27 | | try: |
| 28 | | license_names = simplejson.loads(response_body) |
| 29 | | except Exception, inst: |
| 30 | | msg = "Couldn't read response from licenses service: %s" % inst |
| 31 | | raise Exception, inst |
| 32 | | return [unicode(l) for l in license_names] |
| 33 | 10 | |
| 34 | 11 | import ckan.migration |
| … |
… |
|
| 46 | 23 | def init_db(self): |
| 47 | 24 | super(Repository, self).init_db() |
| 48 | | try: |
| 49 | | licenses_service = LicensesService() |
| 50 | | license_names = licenses_service.get_names() |
| 51 | | except Exception, inst: |
| 52 | | msg = "Licenses service error: %s" % inst |
| 53 | | print msg |
| 54 | | print "Trying to import local licenses package..." |
| 55 | | try: |
| 56 | | from licenses import LicenseList |
| 57 | | license_names = LicenseList.all_formatted |
| 58 | | except Exception, inst: |
| 59 | | msg = "Couldn't load licenses package: %s" % inst |
| 60 | | raise Exception, msg |
| 61 | | print "Loaded %s licenses OK." % len(license_names) |
| 62 | | for name in license_names: |
| 63 | | if not License.by_name(name): |
| 64 | | l = License(name=name) |
| 65 | | Session.add(l) |
| 66 | 25 | # assume if this exists everything else does too |
| 67 | 26 | if not User.by_name(PSEUDO_USER__VISITOR): |
-
|
r827
|
r856
|
|
| 7 | 7 | from types import make_uuid |
| 8 | 8 | import full_search |
| | 9 | from license import License, LicenseRegister |
| 9 | 10 | |
| 10 | 11 | ## VDM-specific tables |
| … |
… |
|
| 13 | 14 | |
| 14 | 15 | ## Our Domain Object Tables |
| 15 | | |
| 16 | | license_table = Table('license', metadata, |
| 17 | | Column('id', types.Integer, primary_key=True), |
| 18 | | Column('name', types.Unicode(100)), |
| 19 | | ) |
| 20 | 16 | |
| 21 | 17 | package_table = Table('package', metadata, |
| … |
… |
|
| 30 | 26 | Column('maintainer_email', types.UnicodeText), |
| 31 | 27 | Column('notes', types.UnicodeText), |
| 32 | | Column('license_id', types.Integer, ForeignKey('license.id')), |
| | 28 | Column('license_id', types.UnicodeText), |
| 33 | 29 | ) |
| 34 | 30 | |
| … |
… |
|
| 45 | 41 | |
| 46 | 42 | |
| 47 | | vdm.sqlalchemy.make_table_stateful(license_table) |
| 48 | 43 | vdm.sqlalchemy.make_table_stateful(package_table) |
| 49 | 44 | vdm.sqlalchemy.make_table_stateful(package_tag_table) |
| … |
… |
|
| 117 | 112 | return self.__unicode__() |
| 118 | 113 | |
| 119 | | |
| 120 | | class License(DomainObject): |
| 121 | | def isopen(self): |
| 122 | | if self.name and \ |
| 123 | | (self.name.startswith('OKD Compliant') |
| 124 | | or |
| 125 | | self.name.startswith('OSI Approved') |
| 126 | | ): |
| 127 | | return True |
| 128 | | return False |
| 129 | 114 | |
| 130 | 115 | class Package(vdm.sqlalchemy.RevisionedObjectMixin, |
| … |
… |
|
| 181 | 166 | _dict['groups'] = [group.name for group in self.groups] |
| 182 | 167 | if self.license: |
| 183 | | _dict['license'] = self.license.name |
| | 168 | _dict['license'] = self.license.id |
| 184 | 169 | else: |
| 185 | 170 | _dict['license'] = '' |
| … |
… |
|
| 220 | 205 | return self.relationships_as_subject + self.relationships_as_object |
| 221 | 206 | |
| | 207 | # |
| | 208 | ## Licenses are currently integrated into the domain model here. |
| | 209 | |
| | 210 | @classmethod |
| | 211 | def get_license_register(self): |
| | 212 | if not hasattr(self, '_license_register'): |
| | 213 | self._license_register = LicenseRegister() |
| | 214 | return self._license_register |
| | 215 | |
| | 216 | @classmethod |
| | 217 | def get_license_options(self): |
| | 218 | register = self.get_license_register() |
| | 219 | return [(l.title, l.id) for l in register.values()] |
| | 220 | |
| | 221 | def get_license(self): |
| | 222 | license = None |
| | 223 | if self.license_id: |
| | 224 | license = self.get_license_register()[self.license_id] |
| | 225 | return license |
| | 226 | |
| | 227 | def set_license(self, license): |
| | 228 | if type(license) == License: |
| | 229 | self.license_id = license.id |
| | 230 | elif type(license) == dict: |
| | 231 | self.license_id = license['id'] |
| | 232 | else: |
| | 233 | msg = "Value not a license object or entity: %s" % repr(license) |
| | 234 | raise Exception, msg |
| | 235 | |
| | 236 | license = property(get_license, set_license) |
| | 237 | |
| | 238 | |
| 222 | 239 | class Tag(DomainObject): |
| 223 | 240 | def __init__(self, name=''): |
| … |
… |
|
| 266 | 283 | Revision = vdm.sqlalchemy.make_Revision(mapper, revision_table) |
| 267 | 284 | |
| 268 | | mapper(License, license_table, |
| 269 | | order_by=license_table.c.id) |
| 270 | | |
| 271 | 285 | mapper(Package, package_table, properties={ |
| 272 | | 'license':relation(License), |
| 273 | 286 | # delete-orphan on cascade does NOT work! |
| 274 | 287 | # Why? Answer: because of way SQLAlchemy/our code works there are points |
-
|
r657
|
r856
|
|
| 20 | 20 | <dt>${package_license_icon(c.pkg)}</dt> |
| 21 | 21 | <py:choose test=""> |
| 22 | | <dd py:when="c.pkg.license">${c.pkg.license.name} |
| 23 | | </dd> |
| | 22 | <dd py:when="c.pkg.license">${c.pkg.license.title}</dd> |
| 24 | 23 | <dd py:otherwise=""> |
| 25 | 24 | License not given |
| … |
… |
|
| 68 | 67 | <p py:when="c.pkg.license"> |
| 69 | 68 | This package is licensed |
| 70 | | <strong>${c.pkg.license.name}</strong>. |
| | 69 | <strong>${c.pkg.license.title}</strong>. |
| 71 | 70 | </p> |
| 72 | 71 | <p py:otherwise=""> |
-
|
r715
|
r856
|
|
| 116 | 116 | indict['Package--notes'] = u'some new notes' |
| 117 | 117 | indict['Package--tags'] = u'russian tolstoy, ' + newtagname, |
| 118 | | indict['Package--license_id'] = '1' |
| | 118 | indict['Package--license_id'] = u'agpl-v3' |
| 119 | 119 | indict['Package--extras-newfield0-key'] = u'testkey' |
| 120 | 120 | indict['Package--extras-newfield0-value'] = u'testvalue' |
| … |
… |
|
| 138 | 138 | |
| 139 | 139 | # test licenses |
| 140 | | assert outpkg.license |
| 141 | | assert indict['Package--license_id'] == str(outpkg.license.id), outpkg.license.id |
| | 140 | assert indict['Package--license_id'] == outpkg.license_id, outpkg.license_id |
| | 141 | #assert outpkg.license |
| | 142 | #assert indict['Package--license_id'] == outpkg.license.id, outpkg.license |
| 142 | 143 | |
| 143 | 144 | # test extra |
| … |
… |
|
| 162 | 163 | indict[prefix + 'notes'] = u'new notes' |
| 163 | 164 | indict[prefix + 'tags'] = u'russian ' + newtagname |
| 164 | | indict[prefix + 'license_id'] = '1' |
| | 165 | indict[prefix + 'license_id'] = u'agpl-v3' |
| 165 | 166 | indict[prefix + 'extras-newfield0-key'] = u'testkey' |
| 166 | 167 | indict[prefix + 'extras-newfield0-value'] = u'testvalue' |
| … |
… |
|
| 188 | 189 | # test licenses |
| 189 | 190 | assert outpkg.license |
| 190 | | assert indict[prefix+'license_id'] == str(outpkg.license.id), outpkg.license.id |
| | 191 | assert indict[prefix+'license_id'] == outpkg.license.id, outpkg.license |
| 191 | 192 | |
| 192 | 193 | # test extra |
-
|
r809
|
r856
|
|
| 58 | 58 | (fs.maintainer, '', ''), |
| 59 | 59 | (fs.maintainer_email, '', ''), |
| 60 | | (fs.license, 'Crown Copyright'), |
| | 60 | (fs.license_id, u'dsl'), # Todo: Fix this. |
| 61 | 61 | ] |
| 62 | 62 | for vals in expected_values: |
| … |
… |
|
| 156 | 156 | indict[prefix + 'notes'] = u'some new notes' |
| 157 | 157 | indict[prefix + 'tags'] = u'russian tolstoy, ' + newtagname, |
| 158 | | indict[prefix + 'license_id'] = '1' |
| | 158 | indict[prefix + 'license_id'] = u'agpl-v3' |
| 159 | 159 | indict[prefix + 'external_reference'] = u'123' |
| 160 | 160 | indict[prefix + 'date_released'] = u'27/11/2008' |
| … |
… |
|
| 193 | 193 | # test licenses |
| 194 | 194 | assert outpkg.license |
| 195 | | assert indict[prefix + 'license_id'] == str(outpkg.license.id), outpkg.license.id |
| | 195 | assert indict[prefix + 'license_id'] == outpkg.license.id, outpkg.license.id |
| 196 | 196 | |
| 197 | 197 | # test resources |
| … |
… |
|
| 259 | 259 | indict[prefix + 'notes'] = u'some new notes' |
| 260 | 260 | indict[prefix + 'tags'] = u'russian, tolstoy', |
| 261 | | indict[prefix + 'license_id'] = '1' |
| | 261 | indict[prefix + 'license_id'] = u'agpl-v3' |
| 262 | 262 | indict[prefix + 'external_reference'] = u'123' |
| 263 | 263 | indict[prefix + 'date_released'] = u'27/11/2008' |
| … |
… |
|
| 294 | 294 | # test licenses |
| 295 | 295 | assert outpkg.license |
| 296 | | assert indict[prefix + 'license_id'] == str(outpkg.license.id), outpkg.license.id |
| | 296 | assert indict[prefix + 'license_id'] == outpkg.license.id, outpkg.license.id |
| 297 | 297 | |
| 298 | 298 | # test resources |
-
|
r823
|
r856
|
|
| 27 | 27 | self.check_named_element(main_div, 'tr', *values) |
| 28 | 28 | assert params['notes'] in main_div, main_div_str |
| 29 | | if isinstance(params['license'], model.License): |
| 30 | | license_str = str(params['license'].name) |
| 31 | | elif isinstance(params['license'], (str, unicode)): |
| 32 | | license_str = str(params['license']) |
| | 29 | license_str = str(params['license']) |
| 33 | 30 | assert license_str in main_div, main_div_str |
| 34 | 31 | tag_names = [tag.lower() for tag in params['tags']] |
| … |
… |
|
| 68 | 65 | self.check_named_element(preview, 'tr', resource[0], resource[1], resource[2], resource[3]) |
| 69 | 66 | assert str(params['notes']) in preview, preview |
| 70 | | if isinstance(params['license'], model.License): |
| 71 | | license_str = str(params['license'].name) |
| 72 | | elif isinstance(params['license'], (str, unicode)): |
| 73 | | license_str = str(params['license']) |
| 74 | | assert license_str in preview, preview |
| | 67 | #if isinstance(params['license'], model.License): |
| | 68 | # license_str = str(params['license'].name) |
| | 69 | #elif isinstance(params['license'], (str, unicode)): |
| | 70 | # license_str = str(params['license']) |
| | 71 | #assert license_str in preview, preview |
| 75 | 72 | tag_names = [str(tag.lower()) for tag in params['tags']] |
| 76 | 73 | self.check_named_element(preview, 'ul', *tag_names) |
| … |
… |
|
| 123 | 120 | self.check_tag(main_res, '%sresources-%i-%s' % (prefix, res_index, res_field), expected_value) |
| 124 | 121 | self.check_tag_and_data(main_res, prefix+'notes', params['notes']) |
| 125 | | if isinstance(params['license'], model.License): |
| 126 | | license_ = params['license'].name |
| 127 | | else: |
| 128 | | license_ = params['license'] |
| 129 | | self.check_tag_and_data(main_res, 'selected', license_) |
| | 122 | #if isinstance(params['license'], model.License): |
| | 123 | # license_ = params['license'].name |
| | 124 | #else: |
| | 125 | # license_ = params['license'] |
| | 126 | #self.check_tag_and_data(main_res, 'selected', license_) |
| 130 | 127 | if isinstance(params['tags'], (str, unicode)): |
| 131 | 128 | tags = params['tags'].split() |
| … |
… |
|
| 193 | 190 | self.check_tag_and_data(res, 'umlaut', u'\xfc') |
| 194 | 191 | assert 'License:' in res |
| 195 | | assert 'OKD Compliant::' in res |
| | 192 | #assert 'OKD Compliant::' in res |
| 196 | 193 | assert 'russian' in res |
| 197 | 194 | assert 'david' in res |
| … |
… |
|
| 322 | 319 | newurl = u'http://www.editpkgnewurl.com' |
| 323 | 320 | new_download_url = newurl + u'/download/' |
| 324 | | newlicense = u'Non-OKD Compliant::Other' |
| 325 | | newlicenseid = model.License.by_name(newlicense).id |
| | 321 | #newlicense = u'Non-OKD Compliant::Other' |
| | 322 | #newlicenseid = model.License.by_name(newlicense).id |
| 326 | 323 | newversion = u'0.9b' |
| 327 | 324 | fv = self.res.forms[0] |
| … |
… |
|
| 331 | 328 | fv[prefix + 'url'] = newurl |
| 332 | 329 | fv[prefix + 'resources-0-url'] = new_download_url |
| 333 | | fv[prefix + 'license_id'] = newlicenseid |
| | 330 | #fv[prefix + 'license_id'] = newlicenseid |
| 334 | 331 | fv[prefix + 'version'] = newversion |
| 335 | 332 | res = fv.submit('commit') |
| … |
… |
|
| 345 | 342 | assert pkg.resources[0].url == new_download_url |
| 346 | 343 | assert pkg.version == newversion |
| 347 | | assert newlicense == pkg.license.name |
| | 344 | #assert newlicense == pkg.license.name |
| 348 | 345 | |
| 349 | 346 | def test_edit_2_not_groups(self): |
| … |
… |
|
| 451 | 448 | pkg.tags = [t1, t2] |
| 452 | 449 | pkg.state = model.State.DELETED |
| 453 | | pkg.license = model.License.by_name(u'OKD Compliant::Other') |
| | 450 | #pkg.license = model.License.by_name(u'OKD Compliant::Other') |
| 454 | 451 | extras = {'key1':'value1', 'key2':'value2', 'key3':'value3'} |
| 455 | 452 | for key, value in extras.items(): |
| … |
… |
|
| 479 | 476 | assert len(resources[0]) == len(model.PackageResource.get_columns()) |
| 480 | 477 | notes = u'Very important' |
| 481 | | license_id = 4 |
| 482 | | license = model.Session.query(model.License).get(license_id) |
| | 478 | license_id = u'agpl-v3' |
| | 479 | #license = model.Session.query(model.License).get(license_id) |
| 483 | 480 | state = model.State.ACTIVE |
| 484 | 481 | tags = (u'tag1', u'tag2', u'tag3') |
| … |
… |
|
| 498 | 495 | fv[prefix+'resources-%s-%s' % (res_index, res_field)] = resource[field_index] |
| 499 | 496 | fv[prefix+'notes'] = notes |
| 500 | | fv[prefix+'license_id'] = license_id |
| | 497 | #fv[prefix+'license_id'] = license_id |
| 501 | 498 | fv[prefix+'tags'] = tags_txt |
| 502 | 499 | fv[prefix+'state'] = state |
| … |
… |
|
| 517 | 514 | url=url, |
| 518 | 515 | download_url='', |
| 519 | | resources=resources, notes=notes, license=license, |
| | 516 | resources=resources, notes=notes, #license=license, |
| 520 | 517 | tags=tags, extras=current_extras, |
| 521 | 518 | deleted_extras=deleted_extras, |
| … |
… |
|
| 526 | 523 | title=title, version=version, |
| 527 | 524 | url=url, resources=resources, |
| 528 | | notes=notes, license=license, |
| | 525 | notes=notes, #license=license, |
| 529 | 526 | tags=tags, extras=current_extras, |
| 530 | 527 | deleted_extras=deleted_extras, |
| … |
… |
|
| 542 | 539 | version=version, url=url, |
| 543 | 540 | resources=resources, notes=notes, |
| 544 | | license=license, tags=tags, |
| | 541 | #license=license, |
| | 542 | tags=tags, |
| 545 | 543 | extras=current_extras, |
| 546 | 544 | deleted_extras=deleted_extras, |
| … |
… |
|
| 558 | 556 | assert getattr(pkg.resources[res_index], res_field) == resource[field_index] |
| 559 | 557 | assert pkg.notes == notes |
| 560 | | assert pkg.license_id == license_id |
| | 558 | #assert pkg.license_id == license_id |
| 561 | 559 | saved_tagnames = [str(tag.name) for tag in pkg.tags] |
| 562 | 560 | saved_tagnames.sort() |
| … |
… |
|
| 686 | 684 | download_url = u'http://something.com/somewhere-else.zip' |
| 687 | 685 | notes = u'Very important' |
| 688 | | license_id = 4 |
| 689 | | license = u'OKD Compliant::Creative Commons CCZero' |
| | 686 | #license_id = 4 |
| | 687 | #license = u'OKD Compliant::Creative Commons CCZero' |
| 690 | 688 | tags = (u'tag1', u'tag2', u'tag3', u'SomeCaps') |
| 691 | 689 | tags_txt = u' '.join(tags) |
| … |
… |
|
| 705 | 703 | fv[prefix+'resources-0-description'] = u'description escape: & umlaut: \xfc quote "'.encode('utf8') |
| 706 | 704 | fv[prefix+'notes'] = notes |
| 707 | | fv[prefix+'license_id'] = license_id |
| | 705 | #fv[prefix+'license_id'] = license_id |
| 708 | 706 | fv[prefix+'tags'] = tags_txt |
| 709 | 707 | for i, extra in enumerate(extras.items()): |
| … |
… |
|
| 720 | 718 | url=url, |
| 721 | 719 | resources=resources_escaped, notes=notes, |
| 722 | | license=license, |
| | 720 | #license=license, |
| 723 | 721 | tags=tags, extras=extras.items(), |
| 724 | 722 | ) |
| … |
… |
|
| 728 | 726 | title=title, version=version, |
| 729 | 727 | url=url, resources=[download_url], |
| 730 | | notes=notes, license=license, |
| | 728 | notes=notes, #license=license, |
| 731 | 729 | tags=[tag.lower() for tag in tags], |
| 732 | 730 | extras=extras, |
| … |
… |
|
| 746 | 744 | version=version, url=url, |
| 747 | 745 | resources=[download_url], notes=notes, |
| 748 | | license=license, tags=tags, |
| | 746 | #license=license, |
| | 747 | tags=tags, |
| 749 | 748 | extras=extras, |
| 750 | 749 | # state=state, |
| … |
… |
|
| 759 | 758 | assert pkg.resources[0].url == download_url |
| 760 | 759 | assert pkg.notes == notes |
| 761 | | assert pkg.license_id == license_id |
| | 760 | #assert pkg.license_id == license_id |
| 762 | 761 | saved_tagnames = [str(tag.name) for tag in pkg.tags] |
| 763 | 762 | saved_tagnames.sort() |
-
|
r828
|
r856
|
|
| 9 | 9 | |
| 10 | 10 | ACCESS_DENIED = [401,403] |
| 11 | | def get_license_name(id): |
| 12 | | return model.Session.get(model.License, id).name |
| 13 | | |
| 14 | 11 | |
| 15 | 12 | class TestRest(TestController): |
| … |
… |
|
| 35 | 32 | |
| 36 | 33 | def setup(self): |
| 37 | | self.testpackage_license_id = 4 |
| 38 | | license_name = get_license_name(self.testpackage_license_id) |
| | 34 | self.testpackage_license_id = u'agpl-v3' |
| 39 | 35 | self.testpackagevalues = { |
| 40 | 36 | 'name' : u'testpkg', |
| … |
… |
|
| 50 | 46 | u'hash':u'def123'},], |
| 51 | 47 | 'tags': [u'russion', u'novel'], |
| 52 | | 'license': license_name, |
| | 48 | 'license': self.testpackage_license_id, |
| 53 | 49 | 'extras': {'genre' : u'horror', |
| 54 | 50 | 'media' : u'dvd', |
| … |
… |
|
| 125 | 121 | # assert '"license_id": 9' in res, res |
| 126 | 122 | assert 'license_id' not in res, res |
| 127 | | expected_license = '"license": "%s"' % get_license_name(9) |
| | 123 | expected_license = '"license": "%s"' % 'agpl-v3' |
| 128 | 124 | assert expected_license in res, repr(res) + repr(expected_license) |
| 129 | 125 | assert 'russian' in res, res |
| … |
… |
|
| 190 | 186 | assert pkg.url == self.testpackagevalues['url'], pkg |
| 191 | 187 | assert pkg.license_id == self.testpackage_license_id, pkg |
| 192 | | assert pkg.license.name == self.testpackagevalues['license'], pkg.license |
| 193 | 188 | assert len(pkg.tags) == 2 |
| 194 | 189 | assert len(pkg.extras) == 2, len(pkg.extras) |
| … |
… |
|
| 207 | 202 | assert self.testpackagevalues['name'] in res, res |
| 208 | 203 | # assert '"license_id": %s' % self.testpackagevalues['license_id'] in res, res |
| 209 | | assert '"license": "%s"' % self.testpackagevalues['license'] in res, res |
| | 204 | #assert '"license": "%s"' % self.testpackagevalues['license'] in res, res |
| 210 | 205 | assert self.testpackagevalues['tags'][0] in res, res |
| 211 | 206 | assert self.testpackagevalues['tags'][1] in res, res |
| … |
… |
|
| 597 | 592 | res_dict = simplejson.loads(res.body) |
| 598 | 593 | assert rev.id == res_dict['id'] |
| 599 | | assert str(rev.timestamp) == res_dict['timestamp'] |
| | 594 | assert rev.timestamp.isoformat() == res_dict['timestamp'], (rev.timestamp.isoformat(), res_dict['timestamp']) |
| 600 | 595 | |
| 601 | 596 | def test_14_get_revision_404(self): |
| … |
… |
|
| 631 | 626 | 'format':'', 'description':''}], |
| 632 | 627 | 'tags': ['russion', 'novel'], |
| 633 | | 'license_id': '4', |
| | 628 | 'license': u'agpl-v3', |
| 634 | 629 | 'extras': {'national_statistic':'yes', |
| 635 | 630 | 'geographic_coverage':'England, Wales'}, |
| … |
… |
|
| 773 | 768 | assert anna_rec['name'] == 'annakarenina', res_dict['results'] |
| 774 | 769 | assert anna_rec['title'] == 'A Novel By Tolstoy', anna_rec['title'] |
| 775 | | assert anna_rec['license'] == 'OKD Compliant::Other', anna_rec['license'] |
| | 770 | assert anna_rec['license'] == u'agpl-v3', anna_rec['license'] |
| 776 | 771 | assert len(anna_rec['tags']) == 2, anna_rec['tags'] |
| 777 | 772 | for expected_tag in ['russian', 'tolstoy']: |
-
|
r808
|
r856
|
|
| 99 | 99 | assert not pkg1.maintainer, pkg1.maintainer |
| 100 | 100 | assert not pkg1.maintainer_email, pkg1.maintainer_email |
| 101 | | assert 'UK Crown Copyright with data.gov.uk rights' in pkg1.license.name, pkg1.license.name |
| 102 | | assert 'Higher Education Statistics Agency Copyright with data.gov.uk rights' in pkg3.license.name, pkg1.license.name |
| | 101 | assert 'UK Crown Copyright with data.gov.uk rights' in pkg1.license.title, pkg1.license.title |
| | 102 | assert 'Higher Education Statistics Agency Copyright with data.gov.uk rights' in pkg3.license.title, pkg1.license.title |
| 103 | 103 | for tag in ['child-protection']: |
| 104 | 104 | assert tag in tag_names, '%s not in %s' % (tag, tag_names) |
| … |
… |
|
| 178 | 178 | assert not pkg1.maintainer, pkg1.maintainer |
| 179 | 179 | assert not pkg1.maintainer_email, pkg1.maintainer_email |
| 180 | | assert 'Crown Copyright' in pkg.license.name, pkg.license.name |
| 181 | | tag_names = set() |
| | 180 | assert 'Crown Copyright' in pkg.license.title, pkg.license.title |
| | 181 | tag_titles = set() |
| 182 | 182 | [tag_names.add(tag.name) for tag in pkg1.tags] |
| 183 | 183 | for tag in []: |
-
|
r808
|
r856
|
|
| 109 | 109 | assert 'england_and_wales' not in tag_names, tag_names |
| 110 | 110 | assert len(tag_names) > 1, tag_names |
| 111 | | assert 'UK Crown Copyright with data.gov.uk rights' in pkg1.license.name, pkg1.license.name |
| | 111 | assert 'UK Crown Copyright with data.gov.uk rights' in pkg1.license.title, pkg1.license.title |
| 112 | 112 | assert pkg1.extras['external_reference'] == 'DATA4NR-719', pkg1.extras['external_reference'] |
| 113 | 113 | |
-
|
r808
|
r856
|
|
| 21 | 21 | def test_load_data(self): |
| 22 | 22 | q = model.Session.query(model.Package) |
| 23 | | assert q.count() == 0 |
| | 23 | q_count = q.count() |
| | 24 | assert q_count == 0, q_count |
| 24 | 25 | self.data.load_xml_into_db(test_data) |
| 25 | | assert q.count() == 6, q.count() |
| | 26 | q_count = q.count() |
| | 27 | assert q_count == 6, q_count |
| 26 | 28 | |
| 27 | 29 | def test_title(self): |
| … |
… |
|
| 90 | 92 | |
| 91 | 93 | assert pkg1.extras['external_reference'] == u'ONSHUB', pkg1.extras['external_reference'] |
| 92 | | assert 'UK Crown Copyright with data.gov.uk rights' in pkg.license.name, pkg.license.name |
| | 94 | assert 'UK Crown Copyright with data.gov.uk rights' in pkg.license.title, pkg.license.title |
| 93 | 95 | assert pkg1.extras['update_frequency'] == u'monthly', pkg1.extras['update_frequency'] |
| 94 | 96 | assert custody.extras['update_frequency'] == u'monthly', custody.extras['update_frequency'] |
-
|
r682
|
r856
|
|
| 21 | 21 | u'version':u'testversion', |
| 22 | 22 | u'tags':u'one three', |
| 23 | | u'license_id':u'4', |
| | 23 | u'license_id':u'agpl-v3', |
| 24 | 24 | u'extras':{u'key1':u'value1', u'key3':u'value3'}, |
| 25 | 25 | } |
| … |
… |
|
| 46 | 46 | u'version':u'testversion', |
| 47 | 47 | u'tags':['one', 'two'], |
| 48 | | u'license':'OKD Compliant::Other', |
| | 48 | u'license':'agpl-v3', |
| 49 | 49 | u'extras':{'key1':'value1', 'key2':'value2'}, |
| 50 | 50 | } |
| … |
… |
|
| 70 | 70 | def _check_preview_pkg(self, pkg, params): |
| 71 | 71 | for key, value in params.items(): |
| 72 | | if key == u'license_id': |
| 73 | | assert pkg.license_id == int(value) |
| 74 | | assert pkg.license == model.Session.query(model.License).get(int(value)) |
| | 72 | if key == u'license': |
| | 73 | assert pkg.license_id == value |
| | 74 | assert pkg.license.id == value |
| | 75 | elif key == u'license_id': |
| | 76 | assert pkg.license_id == value |
| | 77 | assert pkg.license.id == value |
| 75 | 78 | elif key == u'tags': |
| 76 | 79 | reqd_tags = value.split() |
-
|
r809
|
r856
|
|
| 1 | 1 | from ckan.tests import * |
| 2 | 2 | import ckan.model as model |
| 3 | | |
| 4 | | |
| 5 | | class TestLicense: |
| 6 | | name = u'testlicense' |
| 7 | | |
| 8 | | @classmethod |
| 9 | | def teardown_class(self): |
| 10 | | lic = model.License.by_name(self.name) |
| 11 | | if lic: |
| 12 | | lic.purge() |
| 13 | | model.repo.commit_and_remove() |
| 14 | | |
| 15 | | def test_license_names(self): |
| 16 | | all = model.LicenseList.all_formatted |
| 17 | | # make test lenient so do not break every time a license gets added |
| 18 | | assert len(all) >= 72, len(all) |
| 19 | | assert 'Other::License Not Specified' in all |
| 20 | | |
| 21 | | def test_license(self): |
| 22 | | license = model.License(name=self.name) |
| 23 | | model.Session.add(license) |
| 24 | | assert license in model.Session |
| 25 | | model.Session.flush() |
| 26 | | model.Session.clear() |
| 27 | | exp = model.License.by_name(self.name) |
| 28 | | assert exp.name == self.name |
| 29 | | |
| 30 | 3 | |
| 31 | 4 | class TestPackage: |
| … |
… |
|
| 43 | 16 | model.Session.add(self.pkg1) |
| 44 | 17 | self.pkg1.notes = self.notes |
| 45 | | self.license_name = u'OKD Compliant::Other' |
| 46 | | license = model.License.by_name(self.license_name) |
| 47 | | self.pkg1.license = license |
| | 18 | self.pkg1.license_id = u'agpl-v3' |
| 48 | 19 | model.Session.commit() |
| 49 | 20 | model.Session.remove() |
| … |
… |
|
| 60 | 31 | assert out.name == self.name |
| 61 | 32 | assert out.notes == self.notes |
| 62 | | assert out.license.name == self.license_name |
| | 33 | assert out.license.id == u'agpl-v3' |
| | 34 | assert out.license.title == u'Affero GNU Public License' |
| 63 | 35 | |
| 64 | 36 | def test_update_package(self): |
| … |
… |
|
| 129 | 101 | # 2 default packages each with 2 tags so we have 2 + 4 |
| 130 | 102 | all = model.Session.query(model.Tag).all() |
| 131 | | assert len(all) == 3 |
| | 103 | assert len(all) == 3, all |
| 132 | 104 | |
| 133 | 105 | def test_add_tag_by_name(self): |
| … |
… |
|
| 148 | 120 | pkg.add_tag_by_name(self.tagname) |
| 149 | 121 | assert len(pkg.tags) == 3 |
| 150 | | |
| 151 | | |
| 152 | | class TestPackageWithLicense: |
| 153 | | |
| 154 | | @classmethod |
| 155 | | def setup_class(self): |
| 156 | | self.licname1 = u'test_license1' |
| 157 | | self.licname2 = u'test_license2' |
| 158 | | self.license1 = model.License(name=self.licname1) |
| 159 | | model.Session.add(self.license1) |
| 160 | | self.license2 = model.License(name=self.licname2) |
| 161 | | model.Session.add(self.license2) |
| 162 | | rev = model.repo.new_revision() |
| 163 | | self.pkgname = u'testpkgfk' |
| 164 | | pkg = model.Package(name=self.pkgname) |
| 165 | | model.Session.add(pkg) |
| 166 | | pkg.license = self.license1 |
| 167 | | model.Session.commit() |
| 168 | | self.rev1id = rev.id |
| 169 | | model.Session.remove() |
| 170 | | |
| 171 | | rev = model.repo.new_revision() |
| 172 | | pkg = model.Package.by_name(self.pkgname) |
| 173 | | pkg.license = self.license2 |
| 174 | | model.Session.commit() |
| 175 | | self.rev2id = rev.id |
| 176 | | model.Session.remove() |
| 177 | | |
| 178 | | @classmethod |
| 179 | | def teardown_class(self): |
| 180 | | model.Session.clear() |
| 181 | | pkg = model.Package.by_name(self.pkgname) |
| 182 | | pkg.purge() |
| 183 | | lic1 = model.License.by_name(self.licname1) |
| 184 | | lic2 = model.License.by_name(self.licname2) |
| 185 | | lic1.purge() |
| 186 | | lic2.purge() |
| 187 | | model.Session.commit() |
| 188 | | |
| 189 | | def test_set1(self): |
| 190 | | rev = model.Session.query(model.Revision).get(self.rev1id) |
| 191 | | pkg = model.Package.by_name(self.pkgname) |
| 192 | | pkgrev = pkg.get_as_of(rev) |
| 193 | | out = pkgrev.license.name |
| 194 | | assert out == self.licname1 |
| 195 | | |
| 196 | | def test_set2(self): |
| 197 | | pkg = model.Package.by_name(self.pkgname) |
| 198 | | out = pkg.license.name |
| 199 | | assert out == self.licname2 |
| 200 | | |
| 201 | 122 | |
| 202 | 123 | |
Download in other formats:
0.9.0.3 © 2008-2010
agile42 all
rights reserved
(this page was served in: 2.117106 sec.)