2017-09-14 12:09:54 +02:00
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from bson import ObjectId
|
|
|
|
from dateutil.parser import parse
|
|
|
|
from flask import Markup
|
|
|
|
|
|
|
|
from pillarsdk import Node
|
|
|
|
from pillar.tests import AbstractPillarTest
|
|
|
|
|
|
|
|
|
|
|
|
class JSTreeTest(AbstractPillarTest):
|
2018-01-31 14:33:41 +01:00
|
|
|
def setUp(self, **kwargs):
|
|
|
|
super().setUp(**kwargs)
|
|
|
|
self.project_id, self.project = self.ensure_project_exists()
|
|
|
|
|
2017-09-14 12:09:54 +02:00
|
|
|
def test_jstree_parse_node(self):
|
|
|
|
from pillar.web.utils.jstree import jstree_parse_node
|
|
|
|
|
|
|
|
node_doc = {'_id': ObjectId('55f338f92beb3300c4ff99fe'),
|
|
|
|
'_created': parse('2015-09-11T22:26:33.000+0200'),
|
|
|
|
'_updated': parse('2015-10-30T22:44:27.000+0100'),
|
|
|
|
'_etag': '5248485b4ea7e55e858ff84b1bd4aae88917a37c',
|
|
|
|
'picture': ObjectId('55f338f92beb3300c4ff99de'),
|
|
|
|
'description': 'Play the full movie and see how it was cobbled together.',
|
|
|
|
'parent': ObjectId('55f338f92beb3300c4ff99f9'),
|
2018-01-31 14:33:41 +01:00
|
|
|
'project': self.project_id,
|
2017-09-14 12:09:54 +02:00
|
|
|
'node_type': 'asset',
|
|
|
|
'user': ObjectId('552b066b41acdf5dec4436f2'),
|
|
|
|
'properties': {'status': 'published',
|
|
|
|
'file': ObjectId('55f338f92beb3300c4ff99c2'),
|
|
|
|
'content_type': 'file'},
|
|
|
|
'name': 'Live <strong>Edit</strong>'}
|
|
|
|
|
2018-01-31 14:33:41 +01:00
|
|
|
with self.app.test_request_context():
|
2017-09-14 12:09:54 +02:00
|
|
|
parsed = jstree_parse_node(Node(node_doc))
|
|
|
|
|
|
|
|
self.assertEqual(parsed, {
|
|
|
|
'id': 'n_55f338f92beb3300c4ff99fe',
|
2018-01-31 14:33:41 +01:00
|
|
|
'a_attr': {'href': f"/p/{self.project['url']}/55f338f92beb3300c4ff99fe"},
|
2017-09-14 12:09:54 +02:00
|
|
|
'li_attr': {'data-node-type': 'asset'},
|
|
|
|
'text': Markup('Live <strong>Edit</strong>'),
|
|
|
|
'type': 'file',
|
|
|
|
'children': False,
|
2017-09-28 17:50:31 +02:00
|
|
|
'custom_view': False,
|
2017-09-14 12:09:54 +02:00
|
|
|
})
|
2017-09-28 17:50:31 +02:00
|
|
|
|
|
|
|
def test_jstree_parse_blog_node(self):
|
|
|
|
from pillar.web.utils.jstree import jstree_parse_node
|
|
|
|
|
|
|
|
node_doc = {'_id': ObjectId('55f338f92beb3300c4ff99fe'),
|
|
|
|
'_created': parse('2015-09-11T22:26:33.000+0200'),
|
|
|
|
'_updated': parse('2015-10-30T22:44:27.000+0100'),
|
|
|
|
'_etag': '5248485b4ea7e55e858ff84b1bd4aae88917a37c',
|
|
|
|
'picture': ObjectId('55f338f92beb3300c4ff99de'),
|
|
|
|
'description': 'Play the full movie and see how it was cobbled together.',
|
|
|
|
'parent': ObjectId('55f338f92beb3300c4ff99f9'),
|
2018-01-31 14:33:41 +01:00
|
|
|
'project': self.project_id,
|
2017-09-28 17:50:31 +02:00
|
|
|
'node_type': 'blog',
|
|
|
|
'user': ObjectId('552b066b41acdf5dec4436f2'),
|
|
|
|
'properties': {'status': 'published',
|
|
|
|
'file': ObjectId('55f338f92beb3300c4ff99c2'),
|
|
|
|
'content_type': 'file'},
|
|
|
|
'name': 'Live <strong>Edit</strong>'}
|
|
|
|
|
2018-01-31 14:33:41 +01:00
|
|
|
with self.app.test_request_context():
|
2017-09-28 17:50:31 +02:00
|
|
|
parsed = jstree_parse_node(Node(node_doc))
|
|
|
|
|
|
|
|
self.assertEqual(parsed, {
|
|
|
|
'id': 'n_55f338f92beb3300c4ff99fe',
|
2018-01-31 14:33:41 +01:00
|
|
|
'a_attr': {'href': '/blog/'},
|
2017-09-28 17:50:31 +02:00
|
|
|
'li_attr': {'data-node-type': 'blog'},
|
|
|
|
'text': Markup('Live <strong>Edit</strong>'),
|
|
|
|
'type': 'blog',
|
|
|
|
'children': False,
|
|
|
|
'custom_view': True,
|
|
|
|
})
|
|
|
|
|
2017-09-14 12:09:54 +02:00
|
|
|
def test_jstree_parse_just_created_node(self):
|
|
|
|
from pillar.web.utils.jstree import jstree_parse_node
|
|
|
|
|
|
|
|
node_doc = {'_id': ObjectId('55f338f92beb3300c4ff99fe'),
|
|
|
|
'_created': parse('2015-09-11T22:26:33.000+0200'),
|
|
|
|
'_updated': parse('2015-10-30T22:44:27.000+0100'),
|
|
|
|
'_etag': '5248485b4ea7e55e858ff84b1bd4aae88917a37c',
|
2018-01-31 14:33:41 +01:00
|
|
|
'project': self.project_id,
|
2017-09-14 12:09:54 +02:00
|
|
|
'node_type': 'asset',
|
|
|
|
'user': ObjectId('552b066b41acdf5dec4436f2'),
|
|
|
|
'name': 'Live <strong>Edit</strong>'}
|
|
|
|
|
2018-01-31 14:33:41 +01:00
|
|
|
with self.app.test_request_context():
|
2017-09-14 12:09:54 +02:00
|
|
|
parsed = jstree_parse_node(Node(node_doc))
|
|
|
|
|
|
|
|
self.assertEqual(parsed, {
|
|
|
|
'id': 'n_55f338f92beb3300c4ff99fe',
|
2018-01-31 14:33:41 +01:00
|
|
|
'a_attr': {'href': f"/p/{self.project['url']}/55f338f92beb3300c4ff99fe"},
|
2017-09-14 12:09:54 +02:00
|
|
|
'li_attr': {'data-node-type': 'asset'},
|
|
|
|
'text': Markup('Live <strong>Edit</strong>'),
|
|
|
|
'type': 'asset',
|
|
|
|
'children': False,
|
2017-09-28 17:50:31 +02:00
|
|
|
'custom_view': False,
|
2017-09-14 12:09:54 +02:00
|
|
|
})
|