Ran 2to3 on unittests, same sort of manual fixups as before

This commit is contained in:
2017-03-03 12:07:11 +01:00
parent b65dd49aa6
commit b454b011b0
16 changed files with 405 additions and 413 deletions

View File

@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
from __future__ import absolute_import
import datetime
from bson import tz_util, ObjectId
@@ -11,202 +11,202 @@ from pillar.api.projects.utils import get_node_type
EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID = ObjectId('5673541534134154134513c3')
EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA = {
u'_created': datetime.datetime(2015, 12, 17, 13, 22, 56, tzinfo=tz_util.utc),
u'_etag': u'cc4643e98d3606f87bbfaaa200bfbae941b642f3',
u'_id': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
u'_updated': datetime.datetime(2016, 1, 7, 18, 59, 4, tzinfo=tz_util.utc),
u'category': u'assets',
u'description': u'Welcome to this curated collection of Blender Institute textures and image '
u'resources. This collection is an on-going project, as with each project we '
u'create a number of textures based on our own resources (photographs, scans, '
u'etc.) or made completely from scratch. At the moment you can find all the '
u'textures from the past Open Projects that were deemed re-usable. \r\n\r\n'
u'People who have contributed to these textures:\r\n\r\nAndrea Weikert, Andy '
u'Goralczyk, Basse Salmela, Ben Dansie, Campbell Barton, Enrico Valenza, Ian '
u'Hubert, Kjartan Tysdal, Manu J\xe4rvinen, Massimiliana Pulieso, Matt Ebb, '
u'Pablo Vazquez, Rob Tuytel, Roland Hess, Sarah Feldlaufer, S\xf6nke M\xe4ter',
u'is_private': False,
u'name': u'Unittest project',
u'node_types': [
{u'description': u'Group for texture node type',
u'dyn_schema': {u'order': {u'type': u'integer'},
u'status': {u'allowed': [u'published', u'pending'],
u'type': u'string'},
u'url': {u'type': u'string'}},
u'form_schema': {},
u'name': u'group_texture',
u'parent': [u'group_texture', u'project']},
{u'description': u'Folder node',
u'dyn_schema': {u'notes': {u'maxlength': 256, u'type': u'string'},
u'order': {u'type': u'integer'},
u'status': {u'allowed': [u'published', u'pending'],
u'type': u'string'},
u'url': {u'type': u'string'}},
u'form_schema': {},
u'name': u'group',
u'parent': [u'group', u'project']},
{u'description': u'Basic Asset Type',
u'dyn_schema': {
u'attachments': {u'schema': {u'schema': {u'field': {u'type': u'string'},
u'files': {u'schema': {
u'schema': {u'file': {
u'data_relation': {
u'embeddable': True,
u'field': u'_id',
u'resource': u'files'},
u'type': u'objectid'},
u'size': {
u'type': u'string'},
u'slug': {
u'minlength': 1,
u'type': u'string'}},
u'type': u'dict'},
u'type': u'list'}},
u'type': u'dict'},
u'type': u'list'},
u'categories': {u'type': u'string'},
u'content_type': {u'type': u'string'},
u'file': {u'data_relation': {u'embeddable': True,
u'field': u'_id',
u'resource': u'files'},
u'type': u'objectid'},
u'order': {u'type': u'integer'},
u'status': {u'allowed': [u'published',
u'pending',
u'processing'],
u'type': u'string'},
u'tags': {u'schema': {u'type': u'string'}, u'type': u'list'}},
u'form_schema': {u'attachments': {u'visible': False},
u'content_type': {u'visible': False},
u'file': {u'visible': False}},
u'name': u'asset',
u'parent': [u'group']},
{u'description': u'Entrypoint to a remote or local storage solution',
u'dyn_schema': {u'backend': {u'type': u'string'},
u'subdir': {u'type': u'string'}},
u'form_schema': {u'backend': {}, u'subdir': {}},
u'name': u'storage',
u'parent': [u'group', u'project'],
u'permissions': {u'groups': [{u'group': ctd.EXAMPLE_ADMIN_GROUP_ID,
u'methods': [u'GET', u'PUT', u'POST']},
{u'group': ctd.EXAMPLE_PROJECT_READONLY_GROUP_ID,
u'methods': [u'GET']},
{u'group': ctd.EXAMPLE_PROJECT_READONLY_GROUP2_ID,
u'methods': [u'GET']}],
u'users': [],
u'world': []}},
{u'description': u'Comments for asset nodes, pages, etc.',
u'dyn_schema': {u'confidence': {u'type': u'float'},
u'content': {u'minlength': 5, u'type': u'string'},
u'is_reply': {u'type': u'boolean'},
u'rating_negative': {u'type': u'integer'},
u'rating_positive': {u'type': u'integer'},
u'ratings': {u'schema': {
u'schema': {u'is_positive': {u'type': u'boolean'},
u'user': {u'type': u'objectid'},
u'weight': {u'type': u'integer'}},
u'type': u'dict'},
u'type': u'list'},
u'status': {u'allowed': [u'published', u'flagged', u'edited'],
u'type': u'string'}},
u'form_schema': {},
u'name': u'comment',
u'parent': [u'asset', u'comment']},
{u'description': u'Container for node_type post.',
u'dyn_schema': {u'categories': {u'schema': {u'type': u'string'},
u'type': u'list'},
u'template': {u'type': u'string'}},
u'form_schema': {},
u'name': u'blog',
u'parent': [u'project']},
{u'description': u'A blog post, for any project',
u'dyn_schema': {
u'attachments': {u'schema': {u'schema': {u'field': {u'type': u'string'},
u'files': {u'schema': {
u'schema': {u'file': {
u'data_relation': {
u'embeddable': True,
u'field': u'_id',
u'resource': u'files'},
u'type': u'objectid'},
u'size': {
u'type': u'string'},
u'slug': {
u'minlength': 1,
u'type': u'string'}},
u'type': u'dict'},
u'type': u'list'}},
u'type': u'dict'},
u'type': u'list'},
u'category': {u'type': u'string'},
u'content': {u'maxlength': 90000,
u'minlength': 5,
u'required': True,
u'type': u'string'},
u'status': {u'allowed': [u'published', u'pending'],
u'default': u'pending',
u'type': u'string'},
u'url': {u'type': u'string'}},
u'form_schema': {u'attachments': {u'visible': False}},
u'name': u'post',
u'parent': [u'blog']},
{u'description': u'Image Texture',
u'dyn_schema': {u'aspect_ratio': {u'type': u'float'},
u'categories': {u'type': u'string'},
u'files': {u'schema': {u'schema': {
u'file': {u'data_relation': {u'embeddable': True,
u'field': u'_id',
u'resource': u'files'},
u'type': u'objectid'},
u'is_tileable': {u'type': u'boolean'},
u'map_type': {u'allowed': [u'color',
u'specular',
u'bump',
u'normal',
u'translucency',
u'emission',
u'alpha'],
u'type': u'string'}},
u'type': u'dict'},
u'type': u'list'},
u'is_landscape': {u'type': u'boolean'},
u'is_tileable': {u'type': u'boolean'},
u'order': {u'type': u'integer'},
u'resolution': {u'type': u'string'},
u'status': {u'allowed': [u'published',
u'pending',
u'processing'],
u'type': u'string'},
u'tags': {u'schema': {u'type': u'string'}, u'type': u'list'}},
u'form_schema': {u'content_type': {u'visible': False},
u'files': {u'visible': False}},
u'name': u'texture',
u'parent': [u'group']}],
u'nodes_blog': [],
u'nodes_featured': [],
u'nodes_latest': [],
u'permissions': {u'groups': [{u'group': ctd.EXAMPLE_ADMIN_GROUP_ID,
u'methods': [u'GET', u'POST', u'PUT', u'DELETE']}],
u'users': [],
u'world': [u'GET']},
u'status': u'published',
u'summary': u'Texture collection from all Blender Institute open projects.',
u'url': u'attachment-schema-update',
u'picture_header': ObjectId('5673f260c379cf0007b31bc4'),
u'picture_square': ObjectId('5673f256c379cf0007b31bc3'),
u'user': ctd.EXAMPLE_PROJECT_OWNER_ID}
'_created': datetime.datetime(2015, 12, 17, 13, 22, 56, tzinfo=tz_util.utc),
'_etag': 'cc4643e98d3606f87bbfaaa200bfbae941b642f3',
'_id': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
'_updated': datetime.datetime(2016, 1, 7, 18, 59, 4, tzinfo=tz_util.utc),
'category': 'assets',
'description': 'Welcome to this curated collection of Blender Institute textures and image '
'resources. This collection is an on-going project, as with each project we '
'create a number of textures based on our own resources (photographs, scans, '
'etc.) or made completely from scratch. At the moment you can find all the '
'textures from the past Open Projects that were deemed re-usable. \r\n\r\n'
'People who have contributed to these textures:\r\n\r\nAndrea Weikert, Andy '
'Goralczyk, Basse Salmela, Ben Dansie, Campbell Barton, Enrico Valenza, Ian '
'Hubert, Kjartan Tysdal, Manu J\xe4rvinen, Massimiliana Pulieso, Matt Ebb, '
'Pablo Vazquez, Rob Tuytel, Roland Hess, Sarah Feldlaufer, S\xf6nke M\xe4ter',
'is_private': False,
'name': 'Unittest project',
'node_types': [
{'description': 'Group for texture node type',
'dyn_schema': {'order': {'type': 'integer'},
'status': {'allowed': ['published', 'pending'],
'type': 'string'},
'url': {'type': 'string'}},
'form_schema': {},
'name': 'group_texture',
'parent': ['group_texture', 'project']},
{'description': 'Folder node',
'dyn_schema': {'notes': {'maxlength': 256, 'type': 'string'},
'order': {'type': 'integer'},
'status': {'allowed': ['published', 'pending'],
'type': 'string'},
'url': {'type': 'string'}},
'form_schema': {},
'name': 'group',
'parent': ['group', 'project']},
{'description': 'Basic Asset Type',
'dyn_schema': {
'attachments': {'schema': {'schema': {'field': {'type': 'string'},
'files': {'schema': {
'schema': {'file': {
'data_relation': {
'embeddable': True,
'field': '_id',
'resource': 'files'},
'type': 'objectid'},
'size': {
'type': 'string'},
'slug': {
'minlength': 1,
'type': 'string'}},
'type': 'dict'},
'type': 'list'}},
'type': 'dict'},
'type': 'list'},
'categories': {'type': 'string'},
'content_type': {'type': 'string'},
'file': {'data_relation': {'embeddable': True,
'field': '_id',
'resource': 'files'},
'type': 'objectid'},
'order': {'type': 'integer'},
'status': {'allowed': ['published',
'pending',
'processing'],
'type': 'string'},
'tags': {'schema': {'type': 'string'}, 'type': 'list'}},
'form_schema': {'attachments': {'visible': False},
'content_type': {'visible': False},
'file': {'visible': False}},
'name': 'asset',
'parent': ['group']},
{'description': 'Entrypoint to a remote or local storage solution',
'dyn_schema': {'backend': {'type': 'string'},
'subdir': {'type': 'string'}},
'form_schema': {'backend': {}, 'subdir': {}},
'name': 'storage',
'parent': ['group', 'project'],
'permissions': {'groups': [{'group': ctd.EXAMPLE_ADMIN_GROUP_ID,
'methods': ['GET', 'PUT', 'POST']},
{'group': ctd.EXAMPLE_PROJECT_READONLY_GROUP_ID,
'methods': ['GET']},
{'group': ctd.EXAMPLE_PROJECT_READONLY_GROUP2_ID,
'methods': ['GET']}],
'users': [],
'world': []}},
{'description': 'Comments for asset nodes, pages, etc.',
'dyn_schema': {'confidence': {'type': 'float'},
'content': {'minlength': 5, 'type': 'string'},
'is_reply': {'type': 'boolean'},
'rating_negative': {'type': 'integer'},
'rating_positive': {'type': 'integer'},
'ratings': {'schema': {
'schema': {'is_positive': {'type': 'boolean'},
'user': {'type': 'objectid'},
'weight': {'type': 'integer'}},
'type': 'dict'},
'type': 'list'},
'status': {'allowed': ['published', 'flagged', 'edited'],
'type': 'string'}},
'form_schema': {},
'name': 'comment',
'parent': ['asset', 'comment']},
{'description': 'Container for node_type post.',
'dyn_schema': {'categories': {'schema': {'type': 'string'},
'type': 'list'},
'template': {'type': 'string'}},
'form_schema': {},
'name': 'blog',
'parent': ['project']},
{'description': 'A blog post, for any project',
'dyn_schema': {
'attachments': {'schema': {'schema': {'field': {'type': 'string'},
'files': {'schema': {
'schema': {'file': {
'data_relation': {
'embeddable': True,
'field': '_id',
'resource': 'files'},
'type': 'objectid'},
'size': {
'type': 'string'},
'slug': {
'minlength': 1,
'type': 'string'}},
'type': 'dict'},
'type': 'list'}},
'type': 'dict'},
'type': 'list'},
'category': {'type': 'string'},
'content': {'maxlength': 90000,
'minlength': 5,
'required': True,
'type': 'string'},
'status': {'allowed': ['published', 'pending'],
'default': 'pending',
'type': 'string'},
'url': {'type': 'string'}},
'form_schema': {'attachments': {'visible': False}},
'name': 'post',
'parent': ['blog']},
{'description': 'Image Texture',
'dyn_schema': {'aspect_ratio': {'type': 'float'},
'categories': {'type': 'string'},
'files': {'schema': {'schema': {
'file': {'data_relation': {'embeddable': True,
'field': '_id',
'resource': 'files'},
'type': 'objectid'},
'is_tileable': {'type': 'boolean'},
'map_type': {'allowed': ['color',
'specular',
'bump',
'normal',
'translucency',
'emission',
'alpha'],
'type': 'string'}},
'type': 'dict'},
'type': 'list'},
'is_landscape': {'type': 'boolean'},
'is_tileable': {'type': 'boolean'},
'order': {'type': 'integer'},
'resolution': {'type': 'string'},
'status': {'allowed': ['published',
'pending',
'processing'],
'type': 'string'},
'tags': {'schema': {'type': 'string'}, 'type': 'list'}},
'form_schema': {'content_type': {'visible': False},
'files': {'visible': False}},
'name': 'texture',
'parent': ['group']}],
'nodes_blog': [],
'nodes_featured': [],
'nodes_latest': [],
'permissions': {'groups': [{'group': ctd.EXAMPLE_ADMIN_GROUP_ID,
'methods': ['GET', 'POST', 'PUT', 'DELETE']}],
'users': [],
'world': ['GET']},
'status': 'published',
'summary': 'Texture collection from all Blender Institute open projects.',
'url': 'attachment-schema-update',
'picture_header': ObjectId('5673f260c379cf0007b31bc4'),
'picture_square': ObjectId('5673f256c379cf0007b31bc3'),
'user': ctd.EXAMPLE_PROJECT_OWNER_ID}
EXAMPLE_ASSET_NODE_OLD_ATTACHMENT_SCHEMA = {
u'_id': ObjectId('572761099837730efe8e120d'),
u'picture': ObjectId('5673f260c379cf0007b31bc4'),
u'description': u'',
u'node_type': u'asset',
u'user': ctd.EXAMPLE_PROJECT_OWNER_ID,
u'properties': {
u'status': u'published',
u'content_type': u'image',
u'file': ObjectId('5673f260c379cf0007b31bed'),
u'attachments': [{
'_id': ObjectId('572761099837730efe8e120d'),
'picture': ObjectId('5673f260c379cf0007b31bc4'),
'description': '',
'node_type': 'asset',
'user': ctd.EXAMPLE_PROJECT_OWNER_ID,
'properties': {
'status': 'published',
'content_type': 'image',
'file': ObjectId('5673f260c379cf0007b31bed'),
'attachments': [{
'files': [
{'slug': '01', 'file': ObjectId('5679b25ec379cf25636688f6')},
{'slug': '02b', 'file': ObjectId('5679b308c379cf25636688f7')},
@@ -215,24 +215,24 @@ EXAMPLE_ASSET_NODE_OLD_ATTACHMENT_SCHEMA = {
'field': 'properties.content'
}],
},
u'_updated': datetime.datetime(2016, 5, 2, 14, 19, 58, 0, tzinfo=tz_util.utc),
u'name': u'Image test',
u'project': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
u'_created': datetime.datetime(2016, 5, 2, 14, 19, 37, 0, tzinfo=tz_util.utc),
u'_etag': u'6b8589b42c880e3626f43f3e82a5c5b946742687'
'_updated': datetime.datetime(2016, 5, 2, 14, 19, 58, 0, tzinfo=tz_util.utc),
'name': 'Image test',
'project': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
'_created': datetime.datetime(2016, 5, 2, 14, 19, 37, 0, tzinfo=tz_util.utc),
'_etag': '6b8589b42c880e3626f43f3e82a5c5b946742687'
}
EXAMPLE_PAGE_NODE_OLD_ATTACHMENT_SCHEMA = {
u'_id': ObjectId('572761099837730efe8e120a'),
u'picture': ObjectId('5673f260c379cf0007b31bc4'),
u'description': u'',
u'node_type': u'page',
u'user': ctd.EXAMPLE_PROJECT_OWNER_ID,
u'properties': {
u'status': u'published',
u'content': u'Überinteressant Verhaaltje™ voor het slapengaan.',
u'url': u'jemoeder',
u'attachments': [{
'_id': ObjectId('572761099837730efe8e120a'),
'picture': ObjectId('5673f260c379cf0007b31bc4'),
'description': '',
'node_type': 'page',
'user': ctd.EXAMPLE_PROJECT_OWNER_ID,
'properties': {
'status': 'published',
'content': 'Überinteressant Verhaaltje™ voor het slapengaan.',
'url': 'jemoeder',
'attachments': [{
'files': [
{'slug': '03', 'file': ObjectId('5679b33bc379cf256366ddd8')},
{'slug': '04', 'file': ObjectId('5679b35bc379cf256366ddd9')},
@@ -240,11 +240,11 @@ EXAMPLE_PAGE_NODE_OLD_ATTACHMENT_SCHEMA = {
'field': 'properties.content'
}],
},
u'_updated': datetime.datetime(2016, 5, 2, 14, 19, 58, 0, tzinfo=tz_util.utc),
u'name': u'Page test',
u'project': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
u'_created': datetime.datetime(2016, 5, 2, 14, 19, 37, 0, tzinfo=tz_util.utc),
u'_etag': u'6b8589b42c880e3626f43f3e82a5c5b946742687'
'_updated': datetime.datetime(2016, 5, 2, 14, 19, 58, 0, tzinfo=tz_util.utc),
'name': 'Page test',
'project': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
'_created': datetime.datetime(2016, 5, 2, 14, 19, 37, 0, tzinfo=tz_util.utc),
'_etag': '6b8589b42c880e3626f43f3e82a5c5b946742687'
}
@@ -258,11 +258,11 @@ class AbstractNodeReplacementTest(AbstractPillarTest):
project_overrides=self.project_overrides)
self.ensure_file_exists({
'_id': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA[u'picture_header'],
'_id': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA['picture_header'],
'project': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
})
self.ensure_file_exists({
'_id': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA[u'picture_square'],
'_id': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA['picture_square'],
'project': EXAMPLE_PROJECT_OLD_ATTACHMENT_SCHEMA_ID,
})
@@ -270,8 +270,8 @@ class AbstractNodeReplacementTest(AbstractPillarTest):
return super(AbstractNodeReplacementTest, self).fetch_project_from_db(self.project_id)
def add_group_permission_to_asset_node_type(self):
group_perms = {u'group': ctd.EXAMPLE_PROJECT_READONLY_GROUP_ID,
u'methods': [u'POST', u'PUT']}
group_perms = {'group': ctd.EXAMPLE_PROJECT_READONLY_GROUP_ID,
'methods': ['POST', 'PUT']}
# Assign some permissions to the node types, so we're sure they don't get overwritten.
with self.app.app_context():
proj_coll = self.app.db()['projects']
@@ -314,13 +314,13 @@ class UpgradeAttachmentSchemaTest(AbstractNodeReplacementTest):
super(UpgradeAttachmentSchemaTest, self).setUp(**kwargs)
self.ensure_file_exists(
{'_id': EXAMPLE_ASSET_NODE_OLD_ATTACHMENT_SCHEMA[u'properties'][u'file']})
{'_id': EXAMPLE_ASSET_NODE_OLD_ATTACHMENT_SCHEMA['properties']['file']})
for node in (EXAMPLE_ASSET_NODE_OLD_ATTACHMENT_SCHEMA,
EXAMPLE_PAGE_NODE_OLD_ATTACHMENT_SCHEMA):
for att in node[u'properties'][u'attachments']:
for filedict in att[u'files']:
self.ensure_file_exists({'_id': filedict[u'file']})
for att in node['properties']['attachments']:
for filedict in att['files']:
self.ensure_file_exists({'_id': filedict['file']})
def test_schema_upgrade(self):
from pillar.cli import upgrade_attachment_schema
@@ -348,8 +348,8 @@ class CreateBlogTest(AbstractPillarTest):
AbstractPillarTest.setUp(self, **kwargs)
self.project_id, self.proj = self.ensure_project_exists()
self.ensure_file_exists({'_id': self.proj[u'picture_header']})
self.ensure_file_exists({'_id': self.proj[u'picture_square']})
self.ensure_file_exists({'_id': self.proj['picture_header']})
self.ensure_file_exists({'_id': self.proj['picture_square']})
def test_create_blog(self):
"""Very simple test to check the create_blog CLI command."""