예제 #1
0
    def test_serialize_brains(self):
        catalog = getToolByName(self.portal, 'portal_catalog')
        results = catalog(path='/'.join(self.folder.getPhysicalPath()),
                          sort_on='path')

        self.assertEqual(2, len(results))
        folder, page = results
        self.assertEquals('Folder', folder.portal_type)
        self.assertEquals('Document', page.portal_type)

        serializer = BrainSerializer()
        data = serializer.serialize_brains(results)
        self.assertEqual(list, type(data))
        self.assertEqual(2, len(data))

        folder_data, page_data = data

        self.assertEqual(u'***portal_url***feed-folder',
                         folder_data['_url'])
        self.assertEqual(u'Feed folder', folder_data['Title'])
        self.assertEqual(u'feed-folder', folder_data['id'])

        self.assertEqual(
            u'***portal_url***feed-folder/the-page-with-umlauts',
            page_data['_url'])
        self.assertEqual(u'The page with uml\xe4uts',
                         page_data['Title'])
        self.assertEqual(u'the-page-with-umlauts', page_data['id'])
예제 #2
0
    def test_deserializing(self):
        catalog = getToolByName(self.folder, 'portal_catalog')
        brains = catalog(path='/'.join(self.folder.getPhysicalPath()),
                          sort_on='path')

        self.assertEqual(2, len(brains))

        serializer = BrainSerializer()
        data = json.dumps(serializer.serialize_brains(brains))

        results = serializer.deserialize_brains(
            json.loads(data), total_length=13)

        self.assertEqual(BrainResultSet, type(results))
        self.assertEqual(2, len(results))
        self.assertEqual(13, results.get_total_length())
        folder, page = results

        self.assertTrue(IBrainRepresentation.providedBy(folder))
        self.assertTrue(IBrainRepresentation.providedBy(page))

        self.assertEqual('Feed folder', folder.Title)
        self.assertEqual('The page with uml\xc3\xa4uts', page.Title)

        # The url would be replaced by the bridge proxy, but here we
        # deserialize it directly.
        self.assertEqual('***portal_url***feed-folder',
                         folder.getURL())
        self.assertEqual(
            '***portal_url***feed-folder/the-page-with-umlauts',
            page.getURL())

        self.assertEqual('Folder', folder.portal_type)
        self.assertEqual('Document', page.portal_type)
예제 #3
0
    def test_serialize_brains(self):
        catalog = getToolByName(self.folder, 'portal_catalog')
        results = catalog(path='/'.join(self.folder.getPhysicalPath()),
                          sort_on='path')

        self.assertEqual(len(results), 2)
        folder, page = results
        self.assertEquals(folder.portal_type, 'Folder')
        self.assertEquals(page.portal_type, 'Document')

        serializer = BrainSerializer()
        data = serializer.serialize_brains(results)
        self.assertEqual(type(data), list)
        self.assertEqual(len(data), 2)

        folder_data, page_data = data

        self.assertEqual(folder_data['_url'], u'***portal_url***feed-folder')
        self.assertEqual(folder_data['Title'], u'Feed folder')
        self.assertEqual(folder_data['id'], u'feed-folder')

        self.assertEqual(page_data['_url'],
                         u'***portal_url***feed-folder/page')
        self.assertEqual(page_data['Title'], u'The page with uml\xe4uts')
        self.assertEqual(page_data['id'], u'page')
예제 #4
0
    def test_deserializing(self):
        catalog = getToolByName(self.folder, 'portal_catalog')
        brains = catalog(path='/'.join(self.folder.getPhysicalPath()),
                         sort_on='path')

        self.assertEqual(len(brains), 2)

        serializer = BrainSerializer()
        data = json.dumps(serializer.serialize_brains(brains))

        results = serializer.deserialize_brains(json.loads(data),
                                                total_length=13)

        self.assertEqual(type(results), BrainResultSet)
        self.assertEqual(len(results), 2)
        self.assertEqual(results.get_total_length(), 13)
        folder, page = results

        self.assertTrue(IBrainRepresentation.providedBy(folder))
        self.assertTrue(IBrainRepresentation.providedBy(page))

        self.assertEqual(folder.Title, 'Feed folder')
        self.assertEqual(page.Title, 'The page with uml\xc3\xa4uts')

        # The url would be replaced by the bridge proxy, but here we
        # deserialize it directly.
        self.assertEqual(folder.getURL(), '***portal_url***feed-folder')
        self.assertEqual(page.getURL(), '***portal_url***feed-folder/page')

        self.assertEqual(folder.portal_type, 'Folder')
        self.assertEqual(page.portal_type, 'Document')
예제 #5
0
    def test_serialize_brains(self):
        catalog = getToolByName(self.folder, 'portal_catalog')
        results = catalog(path='/'.join(self.folder.getPhysicalPath()),
                          sort_on='path')

        self.assertEqual(len(results), 2)
        folder, page = results
        self.assertEquals(folder.portal_type, 'Folder')
        self.assertEquals(page.portal_type, 'Document')

        serializer = BrainSerializer()
        data = serializer.serialize_brains(results)
        self.assertEqual(type(data), list)
        self.assertEqual(len(data), 2)

        folder_data, page_data = data

        self.assertEqual(folder_data['_url'], u'***portal_url***feed-folder')
        self.assertEqual(folder_data['Title'], u'Feed folder')
        self.assertEqual(folder_data['id'], u'feed-folder')

        self.assertEqual(page_data['_url'],
                         u'***portal_url***feed-folder/page')
        self.assertEqual(page_data['Title'], u'The page with uml\xe4uts')
        self.assertEqual(page_data['id'], u'page')
예제 #6
0
    def test_serialized_data_is_jsonizable(self):
        catalog = getToolByName(self.portal, 'portal_catalog')
        results = catalog(path='/'.join(self.folder.getPhysicalPath()),
                          sort_on='path')

        self.assertEqual(2, len(results))

        serializer = BrainSerializer()
        data = serializer.serialize_brains(results)

        self.assertEqual(data, json.loads(json.dumps(data)))
예제 #7
0
    def test_serialized_data_is_jsonizable(self):
        catalog = getToolByName(self.folder, 'portal_catalog')
        results = catalog(path='/'.join(self.folder.getPhysicalPath()),
                          sort_on='path')

        self.assertEqual(len(results), 2)

        serializer = BrainSerializer()
        data = serializer.serialize_brains(results)

        self.assertEqual(json.loads(json.dumps(data)), data)