From 589079351943eec54a011c6865072d36257e7255 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 12 Dec 2013 10:22:04 +0000 Subject: [PATCH] [#1208] Fix tests Pep8 and horrible and unmaintaineble dictization tests --- ckan/new_tests/factories.py | 24 ++++-- ckan/tests/lib/test_dictization.py | 132 +++-------------------------- 2 files changed, 29 insertions(+), 127 deletions(-) diff --git a/ckan/new_tests/factories.py b/ckan/new_tests/factories.py index 79bbdda426f..b049038b6dc 100644 --- a/ckan/new_tests/factories.py +++ b/ckan/new_tests/factories.py @@ -126,24 +126,27 @@ def _create(cls, target_class, *args, **kwargs): if args: assert False, "Positional args aren't supported, use keyword args." - #TODO: we will need to be able to define this when creating the instance - # perhaps passing a 'user' param? + #TODO: we will need to be able to define this when creating the + # instance perhaps passing a 'user' param? context = { 'user': helpers.call_action('get_site_user')['name'] } - group_dict = helpers.call_action('group_create', context=context, **kwargs) + group_dict = helpers.call_action('group_create', + context=context, + **kwargs) return group_dict class Organization(factory.Factory): '''A factory class for creating CKAN organizations.''' - # This is the class that OrganizationFactory will create and return instances - # of. + # This is the class that OrganizationFactory will create and return + # instances of. FACTORY_FOR = ckan.model.Group - # These are the default params that will be used to create new organizations. + # These are the default params that will be used to create new + # organizations. type = 'organization' is_organization = True @@ -163,15 +166,18 @@ def _create(cls, target_class, *args, **kwargs): if args: assert False, "Positional args aren't supported, use keyword args." - #TODO: we will need to be able to define this when creating the instance - # perhaps passing a 'user' param? + #TODO: we will need to be able to define this when creating the + # instance perhaps passing a 'user' param? context = { 'user': helpers.call_action('get_site_user')['name'] } - group_dict = helpers.call_action('organization_create', context=context, **kwargs) + group_dict = helpers.call_action('organization_create', + context=context, + **kwargs) return group_dict + class MockUser(factory.Factory): '''A factory class for creating mock CKAN users using the mock library.''' diff --git a/ckan/tests/lib/test_dictization.py b/ckan/tests/lib/test_dictization.py index 815f7a80ec4..92b75db00db 100644 --- a/ckan/tests/lib/test_dictization.py +++ b/ckan/tests/lib/test_dictization.py @@ -881,8 +881,6 @@ def test_16_group_dictized(self): context = {"model": model, "session": model.Session} - pkg = model.Session.query(model.Package).filter_by(name='annakarenina3').first() - simple_group_dict = {'name': 'simple', 'title': 'simple', 'type': 'organization', @@ -900,7 +898,7 @@ def test_16_group_dictized(self): 'approval_status': 'approved', 'extras': [{'key': 'genre', 'value': u'"horror"'}, {'key': 'media', 'value': u'"dvd"'}], - 'packages':[{'name': 'annakarenina2'}, {'id': pkg.id, 'capacity': 'in'}], + 'packages':[{'name': 'annakarenina2'}], 'users':[{'name': 'annafan'}], 'groups':[{'name': 'simple'}], 'tags':[{'name': 'russian'}] @@ -951,21 +949,23 @@ def test_16_group_dictized(self): 'display_name': u'help', 'image_url': u'', 'image_display_url': u'', - 'package_count': 2, + 'package_count': 1, 'is_organization': False, 'packages': [{u'author': None, u'author_email': None, u'creator_user_id': None, u'extras': [], - u'groups': [{u'approval_status': u'approved', - u'capacity': u'public', - u'description': u'', - u'image_url': u'', - u'is_organization': False, - u'name': u'help', - u'state': u'active', - u'title': u'help', - u'type': u'group'}], + u'groups':[{u'approval_status': u'approved', + u'capacity': u'public', + u'description': u'', + u'display_name': u'help', + u'image_display_url': u'', + u'image_url': u'', + u'is_organization': False, + u'name': u'help', + u'state': u'active', + u'title': u'help', + u'type': u'group'}] , u'isopen': True, u'license_id': u'other-open', u'license_title': u'Other (Open)', @@ -988,111 +988,7 @@ def test_16_group_dictized(self): u'type': u'dataset', u'url': u'http://www.annakarenina.com', u'version': u'0.7a'}, - {u'author': None, - u'author_email': None, - u'creator_user_id': None, - u'extras': [{u'key': u'genre', - u'state': u'active', - u'value': u'romantic novel'}, - {u'key': u'original media', - u'state': u'active', - u'value': u'book'}], - u'groups': [{u'approval_status': u'approved', - u'capacity': u'in', - u'description': u'', - u'image_url': u'', - u'is_organization': False, - u'name': u'help', - u'state': u'active', - u'title': u'help', - u'type': u'group'}, - {u'approval_status': u'approved', - u'capacity': u'public', - u'description': u'These are books that David likes.', - u'image_url': u'', - u'is_organization': False, - u'name': u'david', - u'state': u'active', - u'title': u"Dave's books", - u'type': u'group'}, - {u'approval_status': u'approved', - u'capacity': u'public', - u'description': u'Roger likes these books.', - u'image_url': u'', - u'is_organization': False, - u'name': u'roger', - u'state': u'active', - u'title': u"Roger's books", - u'type': u'group'}], - u'isopen': True, - u'license_id': u'other-open', - u'license_title': u'Other (Open)', - u'maintainer': None, - u'maintainer_email': None, - u'name': u'annakarenina3', - u'notes': u'Some test notes\n\n### A 3rd level heading\n\n**Some bolded text.**\n\n*Some italicized text.*\n\nForeign characters:\nu with umlaut \xfc\n66-style quote \u201c\nforeign word: th\xfcmb\n\nNeeds escaping:\nleft arrow <\n\n\n\n', - u'num_resources': 2, - u'num_tags': 3, - u'organization': None, - u'owner_org': None, - u'private': False, - u'relationships_as_object': [], - u'relationships_as_subject': [], - u'resources': [{u'alt_url': u'alt123', - u'cache_last_updated': None, - u'cache_url': None, - u'description': u'Full text. Needs escaping: " Umlaut: \xfc', - u'format': u'plain text', - u'hash': u'abc123', - u'last_modified': None, - u'mimetype': None, - u'mimetype_inner': None, - u'name': None, - u'position': 0, - u'resource_type': None, - u'size': None, - u'size_extra': u'123', - u'state': u'active', - u'tracking_summary': {u'recent': 0, u'total': 0}, - u'url': u'http://www.annakarenina.com/download/x=1&y=2', - u'url_type': None, - u'webstore_last_updated': None, - u'webstore_url': None}, - {u'alt_url': u'alt345', - u'cache_last_updated': None, - u'cache_url': None, - u'description': u'Index of the novel', - u'format': u'JSON', - u'hash': u'def456', - u'last_modified': None, - u'mimetype': None, - u'mimetype_inner': None, - u'name': None, - u'position': 1, - u'resource_type': None, - u'size': None, - u'size_extra': u'345', - u'state': u'active', - u'tracking_summary': {u'recent': 0, u'total': 0}, - u'url': u'http://www.annakarenina.com/index.json', - u'url_type': None, - u'webstore_last_updated': None, - u'webstore_url': None}], - u'state': u'active', - u'tags': [{u'display_name': u'Flexible \u30a1', - u'name': u'Flexible \u30a1', - u'state': u'active'}, - {u'display_name': u'russian', - u'name': u'russian', - u'state': u'active'}, - {u'display_name': u'tolstoy', - u'name': u'tolstoy', - u'state': u'active'}], - u'title': u'A Novel By Tolstoy', - u'tracking_summary': {u'recent': 0, u'total': 0}, - u'type': u'dataset', - u'url': u'http://www.annakarenina.com', - u'version': u'0.7a'}], + ], 'state': u'active', 'approval_status': u'approved', 'title': u'help',