Esempio n. 1
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')
Esempio n. 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)
Esempio n. 3
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'])
Esempio n. 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')
Esempio n. 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')
Esempio n. 6
0
 def test_converts_dates(self):
     serializer = BrainSerializer()
     data = {'python_datetime': datetime(2014, 12, 22, 15, 30),
             'zope_DateTime': DateTime('2001/11/14 13:22')}
     self.assertEquals(
         data,
         serializer._decode_data(json.loads(
                 json.dumps(serializer._encode(data)))))
Esempio n. 7
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)))
Esempio n. 8
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)
Esempio n. 9
0
    def test_converts_persistent_mutables_to_default_types(self):
        # On the remote side the data is not stored, therfore we can
        # convert persistent mutables to default types in order to be
        # able to dump it to json.

        serializer = BrainSerializer()
        self.assertEquals(dict, type(serializer._encode(PersistentMapping())),
                          'PersistentMapping should be converted to dict')
        self.assertEquals(list, type(serializer._encode(PersistentList())),
                          'PersistentList should be converted to list')

        self.assertEquals(dict, type(serializer._encode({'dict': PersistentMapping()})['dict']),
                          'Dicts should be encoded recursively')
        self.assertEquals(list, type(serializer._encode([PersistentList()])[0]),
                          'Lists should be encoded recursively')