def test_json_details_document(self):
        # This class is used to get detail from a certain object. Let's create a Document.
        self.assertEqual(repr(self.portal[self.document]),
                         '<ATDocument at /plone/document>')

        # The basic details should return the following.
        obj = IJSONDetails(self.portal[self.document])
        details = json.loads(obj.getDetails())
        should = {
            "url": "http://nohost/plone/document",
            "thumb": "",
            "description": "",
            "anchors": [],
            "title": "document"
        }
        for key, val in should.iteritems():
            self.assertEqual(details[key], val)

        # Let's set some more details like description and body text.
        self.portal[self.document].setDescription('Test')
        self.portal[self.document].setText(
            u'<p><a name="anchor">anchor</a></p>', mimetype='text/html')

        # The details will now contain a bit more info.
        details = json.loads(obj.getDetails())
        should = {
            "url": "http://nohost/plone/document",
            "thumb": "",
            "description": "Test",
            "anchors": ["anchor"],
            "title": "document"
        }
        for key, val in should.iteritems():
            self.assertEqual(details[key], val)
    def jsonDetails(self):
        """Returns the details of an object in JSON"""

        object = IJSONDetails(self.context, None)
        if object is None:
            return ''
        return object.getDetails()
Exemple #3
0
    def jsonDetails(self):
        """Returns the details of an object in JSON"""

        object = IJSONDetails(self.context, None)
        if object is None:
            return ''
        return object.getDetails()
    def test_json_details_image(self):
        # We can also get the details of an image object.
        image = self.portal.invokeFactory('Image', id='image')
        self.assertEqual(repr(self.portal[image]), '<ATImage at /plone/image>')

        imgdata = open(os.path.join(os.path.dirname(__file__), 'sample.png'))
        self.portal[image].setImage(imgdata)

        # The details will now also include the thumbnail url and the imagescales.
        obj = IJSONDetails(self.portal[image])
        self.assertRegexpMatches(obj.getDetails(), r'\{"scales": \[\{"size": \[52, 43], "value": "", "title": "Original"}.+], "thumb": "http://nohost/plone/resolveuid/.*/@@images/image/thumb".+')
    def test_json_details_document(self):
        # This class is used to get detail from a certain object. Let's create a Document.
        self.assertEqual(repr(self.portal[self.document]), '<ATDocument at /plone/document>')

        # The basic details should return the following.
        obj = IJSONDetails(self.portal[self.document])
        self.assertEqual(obj.getDetails(), '{"thumb": "", "description": "", "anchors": [], "title": "document"}')

        # Let's set some more details like description and body text.
        self.portal[self.document].setDescription('Test')
        self.portal[self.document].setText(u'<p><a name="anchor">anchor</a></p>', mimetype='text/html')

        # The details will now contain a bit more info.
        self.assertEqual(obj.getDetails(), '{"thumb": "", "description": "Test", "anchors": ["anchor"], "title": "document"}')
    def test_json_details_document(self):
        # This class is used to get detail from a certain object. Let's create a Document.
        self.assertEqual(repr(self.portal[self.document]), '<Document at /plone/document>')

        # The basic details should return the following.
        obj = IJSONDetails(self.portal[self.document])
        details = json.loads(obj.getDetails())
        should = {"url": "http://nohost/plone/document", "thumb": "", "description": "", "anchors": [], "title": "document"}
        for key, val in should.iteritems():
            self.assertEqual(details[key], val)

        # Let's set some more details like description and body text.
        self.portal[self.document].description = 'Test'
        self.portal[self.document].text = RichTextValue(
            u'<p><a name="anchor">anchor</a></p>',
            'text/plain',
            'text/html'
        )

        # The details will now contain a bit more info.
        details = json.loads(obj.getDetails())
        should = {"url": "http://nohost/plone/document", "thumb": "", "description": "Test", "anchors": ["anchor"], "title": "document"}
        for key, val in should.iteritems():
            self.assertEqual(details[key], val)