Пример #1
0
    def test_order_events(self):
        # Prepare the setup::
        from zope.container.contained import ContainerModifiedEvent

        # Prepare some objects::

        from zope.container.ordered import OrderedContainer
        oc = OrderedContainer()
        oc['foo'] = 'bar'
        oc['baz'] = 'quux'
        oc['zork'] = 'grue'
        self.assertEqual(oc.keys(),
                         ['foo', 'baz', 'zork'])

        # Now change the order::

        clearEvents()
        oc.updateOrder(['baz', 'foo', 'zork'])
        self.assertEqual(oc.keys(),
                         ['baz', 'foo', 'zork'])

        # Check what events have been sent::

        events = getEvents()
        self.assertEqual(1, len(events))
        self.assertIsInstance(events[0], ContainerModifiedEvent)

        # This is in fact a specialized modification event::

        from zope.lifecycleevent.interfaces import IObjectModifiedEvent
        self.assertTrue(IObjectModifiedEvent.providedBy(events[0]))
    def test_round_trip(self):
        """Make a trip:
        1. Create items.
        2. Export them.
        3. Import them.
        4. Export them.
        5. Check that export created at 2. and 4. are identical.
        """
        # 1. create content
        # 2. export
        exporter1 = getAdapter(self.root.publication,
                               interfaces.IContentExporter,
                               name='zip')
        self.assertTrue(verifyObject(interfaces.IContentExporter, exporter1))

        export1 = exporter1.export(TestRequest())

        # 3. import
        factory = self.root.manage_addProduct['Silva']
        factory.manage_addFolder('folder', 'Import Folder')
        importer = getAdapter(self.root.folder, interfaces.IZipFileImporter)
        self.assertTrue(verifyObject(interfaces.IZipFileImporter, importer))

        clearEvents()
        importer.importFromZip(StringIO(export1), TestRequest())

        self.assertEventsAre([
            'ContentImported for /root/folder/publication',
            'ContentImported for /root/folder/publication/assets',
            'ContentImported for /root/folder/publication/infrae',
            'ContentImported for /root/folder/publication/nice',
            'ContentImported for /root/folder/publication/pictures',
            'ContentImported for /root/folder/publication/pictures/tobesorted',
            'ContentImported for /root/folder/publication/pictures/torvald',
            'ContentImported for /root/folder/publication/pictures/unknown',
            'ContentImported for /root/folder/publication/trash'
        ], IContentImported)

        imported_ghost = self.root.folder.publication.nice
        imported_link = self.root.folder.publication.infrae
        self.assertEqual(imported_ghost.get_editable().get_haunted(),
                         imported_link)

        # 4. export
        exporter2 = getAdapter(self.root.folder.publication,
                               interfaces.IContentExporter,
                               name='zip')

        export2 = exporter2.export(TestRequest())

        # 5. compare the two exports
        zip_export1 = ZipFile(StringIO(export1))
        zip_export2 = ZipFile(StringIO(export2))

        self.failUnless('silva.xml' in zip_export1.namelist())
        self.assertItemsEqual(zip_export1.namelist(), zip_export2.namelist())
        silva_export1 = zip_export1.read('silva.xml')
        silva_export2 = zip_export2.read('silva.xml')

        self.assertXMLEqual(silva_export1, silva_export2)
Пример #3
0
def test_setitem():

    item = Item()
    container = {}

    setitem(container, container.__setitem__, u'c', item)
    assert container[u'c'] is item
    assert item.__parent__ is container
    assert item.__name__ == u'c'

    # We should get events
    assert len(getEvents(IObjectAddedEvent)) == 1

    event = getEvents(IObjectAddedEvent)[-1]
    assert event.object is item
    assert event.newParent is container
    assert event.newName == u'c'
    assert event.oldParent is None
    assert event.oldName is None

    # As well as a modification event for the container
    assert len(getEvents(IObjectModifiedEvent)) == 1
    assert getEvents(IObjectModifiedEvent)[-1].object is container

    # The item's hooks have been called:
    assert item.added is event
    assert item.moved is event

    # we clean our test.
    clearEvents()
Пример #4
0
    def test_order_events(self):
        # Prepare the setup::
        from zope.container.contained import ContainerModifiedEvent

        # Prepare some objects::

        from zope.container.ordered import OrderedContainer
        oc = OrderedContainer()
        oc['foo'] = 'bar'
        oc['baz'] = 'quux'
        oc['zork'] = 'grue'
        self.assertEqual(oc.keys(), ['foo', 'baz', 'zork'])

        # Now change the order::

        clearEvents()
        oc.updateOrder(['baz', 'foo', 'zork'])
        self.assertEqual(oc.keys(), ['baz', 'foo', 'zork'])

        # Check what events have been sent::

        events = getEvents()
        self.assertEqual(1, len(events))
        self.assertIsInstance(events[0], ContainerModifiedEvent)

        # This is in fact a specialized modification event::

        from zope.lifecycleevent.interfaces import IObjectModifiedEvent
        self.assertTrue(IObjectModifiedEvent.providedBy(events[0]))
Пример #5
0
 def _doTearDown(obj, clear_configuration_context=True, super_tear_down=None):
     # always safe to clear events
     eventtesting.clearEvents() # redundant with zope.testing.cleanup
     # we never actually want to do this, it's not needed and can mess up other fixtures
     # resetHooks()
     transaction.abort() # see comments above
     if clear_configuration_context:
         obj.configuration_context = None
     if super_tear_down is not None:
         super_tear_down()
     else:
         obj._doTearDownSuper() # pylint:disable=protected-access
Пример #6
0
 def test_send_mail_journalized(self, browser):
     eventtesting.clearEvents()
     browser.login().visit(self.file_, view='send-mail-form')
     browser.fill({'Recipients': '*****@*****.**',
                   'Comment': 'Test'})
     browser.find('Send').click()
     events = [e for e in eventtesting.getEvents()
               if IJournalEntryEvent.providedBy(e)]
     self.assertEqual(1, len(events))
     self.assertIn(
         '*****@*****.**',
         self.file_.translate(events[0].action))
     self.assertEqual(u'Test', events[0].comment)
Пример #7
0
    def test_register_styles_record(self):
        registry = getUtility(IRegistry)
        record = 'collective.cover.controlpanel.ICoverSettings.styles'

        eventtesting.setUp()

        # just delete the existing record and rerun the handler to verify it
        # was added again
        del registry.records[record]
        eventtesting.clearEvents()
        register_styles_record(self.portal)
        events = eventtesting.getEvents(IRecordAddedEvent)
        self.assertNotEqual(len(events), 0)
        self.assertIn(record, registry.records)
        eventtesting.clearEvents()
Пример #8
0
def module_teardown():
    """
    Tears down the module-level fixture for configuring packages
    established by :func:`module_setup`.

    Either import this as ``tearDownModule`` at the module level, or
    call it to perform module level tear down froum your own function
    with that name.

    This is an alternative to using :class:`ConfiguringTestBase`; the
    two should generally not be mixed in a module.
    """
    eventtesting.clearEvents() # redundant with zope.testing.cleanup
    # we never actually want to do this, it's not needed and can mess up other fixtures
    # resetHooks()
    zope.testing.cleanup.tearDown()
Пример #9
0
 def assertImportZip(self, filename, imported, replace=False, update=False,
                     ignore_top_level=False):
     """Import a ZIP file.
     """
     clearEvents()
     request = TestRequest()
     importer = ZipImporter(self.root, request, {
             'replace_content': replace,
             'update_content': update,
             'ignore_top_level_content': ignore_top_level})
     with self.layer.open_fixture(filename) as source:
         importer.importStream(source)
     self.assertItemsEqual(
         map(lambda event:  '/'.join(event.object.getPhysicalPath()),
             getEvents(IContentImported)),
         imported)
     return importer
Пример #10
0
    def test_download_file_by_token_journal(self, browser):
        eventtesting.clearEvents()
        folder = create(Builder('folder').in_state('private'))
        file_ = create(Builder('file')
                       .with_dummy_content()
                       .within(folder))

        with self.assertRaises(Unauthorized):
            browser.visit(file_)

        downloadtoken = self.storage.add(file_, '*****@*****.**')
        url = self.storage.url(downloadtoken)
        transaction.commit()
        browser.open(url)
        events = [e for e in eventtesting.getEvents()
                  if IJournalEntryEvent.providedBy(e)]
        self.assertEqual(1, len(events))
        self.assertEqual(u'*****@*****.**', events[0].actor)
Пример #11
0
def test_order_events():
    oc = OrderedBTreeContainer()

    oc['foo'] = 'bar'
    oc['baz'] = 'quux'
    oc['zork'] = 'grue'

    assert oc.keys() == ['foo', 'baz', 'zork']

    clearEvents()
    oc.updateOrder(['baz', 'foo', 'zork'])
    assert oc.keys() == ['baz', 'foo', 'zork']

    events = getEvents()
    assert [event.__class__.__name__ for event in events] == (
        ['ContainerModifiedEvent'])

    assert IObjectModifiedEvent.providedBy(events[0])
Пример #12
0
    def test_delete_tile_persistent_data(self):
        eventtesting.clearEvents()
        # First, let's store some data on the tile
        data_mgr = ITileDataManager(self.tile)
        data_mgr.set({'test': 'data'})

        # We see that the data persists
        self.assertIn('test', data_mgr.get())
        self.assertEqual(data_mgr.get()['test'], 'data')

        # Call the delete method
        self.tile.delete()

        # Now we should not see the stored data anymore
        self.assertNotIn('test', data_mgr.get())

        events = eventtesting.getEvents()

        # Finally, test that ObjectModifiedEvent was fired for the cover
        self.assertEqual(events[0].object, self.cover)
    def test_delete_tile_persistent_data(self):
        eventtesting.clearEvents()
        # First, let's assign an id to the tile and store some data
        self.tile.id = 'test-tile'
        data_mgr = ITileDataManager(self.tile)
        data_mgr.set({'test': 'data'})

        # We see that the data persists
        self.assertEqual(data_mgr.get(), {'test': 'data'})

        # Call the delete method
        self.tile.delete()

        # Now we should not see the stored data anymore
        self.assertEqual(data_mgr.get(), {})

        events = eventtesting.getEvents()

        # Finally, test that ObjectModifiedEvent was fired for the cover
        self.assertEqual(events[0].object, self.portal)
Пример #14
0
    def test_delete_tile_persistent_data(self):
        eventtesting.clearEvents()
        # First, let's store some data on the tile
        data_mgr = ITileDataManager(self.tile)
        data_mgr.set({'test': 'data'})

        # We see that the data persists
        self.assertIn('test', data_mgr.get())
        self.assertEqual(data_mgr.get()['test'], 'data')

        # Call the delete method
        self.tile.delete()

        # Now we should not see the stored data anymore
        self.assertNotIn('test', data_mgr.get())

        events = eventtesting.getEvents()

        # Finally, test that ObjectModifiedEvent was fired for the cover
        self.assertEqual(events[0].object, self.cover)
Пример #15
0
    def test_delete_tile_persistent_data(self):
        eventtesting.clearEvents()
        # First, let's assign an id to the tile and store some data
        self.tile.id = 'test-tile'
        data_mgr = ITileDataManager(self.tile)
        data_mgr.set({'test': 'data'})

        # We see that the data persists
        self.assertEqual(data_mgr.get(), {'test': 'data'})

        # Call the delete method
        self.tile.delete()

        # Now we should not see the stored data anymore
        self.assertEqual(data_mgr.get(), {})

        events = eventtesting.getEvents()

        # Finally, test that ObjectModifiedEvent was fired for the cover
        self.assertEqual(events[0].object, self.portal)
Пример #16
0
    def _test_question_answered(self):
        context = self.portal.questions
        manager_name = 'plone.belowcontent'
        viewlet_name = 'question-add'
        layer = ISiyavulaWhatLayer
        viewlet = self._find_viewlet(context, manager_name, viewlet_name,
                                     layer)

        question = self._createQuestion()
        eventtesting.clearEvents()
        request = self.portal.REQUEST
        request.form[
            'siyavula.what.questionslist.form.submitted'] = 'submitted'
        request.form['questionid'] = question.getId()
        request.form['answer'] = 'first answer'
        request.form['action'] = 'add-answer'
        viewlet[0].update()

        events = eventtesting.getEvents(
            IObjectModifiedEvent, filter=lambda obj: IQuestion.providedBy(obj))
        self.assertTrue(len(events) > 0, 'Missing event.')
Пример #17
0
def test_no_event():
    """We can suppress events and hooks by setting the `__parent__` and
    `__name__` first
    """
    item = Item()
    container = {}

    # By setting the __parent__ and __name, we act as if we were
    # already contained.
    item.__parent__, item.__name__ = container, 'c'
    setitem(container, container.__setitem__, u'c', item)

    assert len(container) == 1
    assert len(getEvents(IObjectAddedEvent)) == 0
    assert len(getEvents(IObjectModifiedEvent)) == 0

    assert getattr(item, 'added', None) is None
    assert getattr(item, 'moved', None) is None

    # we clean our test.
    clearEvents()
    def _test_question_answered(self):
        context = self.portal.questions
        manager_name = 'plone.belowcontent'
        viewlet_name = 'question-add'
        layer = ICollectiveAnswersLayer
        viewlet = self._find_viewlet(context, manager_name, viewlet_name, layer)

        question = self._createQuestion()
        eventtesting.clearEvents()
        request = self.portal.REQUEST
        request.form['collective.answers.questionslist.form.submitted'] = 'submitted'
        request.form['questionid'] = question.getId()
        request.form['answer'] = 'first answer'
        request.form['action'] = 'add-answer'
        viewlet[0].update()

        events = eventtesting.getEvents(
            IObjectModifiedEvent,
            filter=lambda obj: IQuestion.providedBy(obj)
        )
        self.assertTrue(len(events) > 0, 'Missing event.')
Пример #19
0
def test_move_event():
    """If the item had a parent or name (as in a move or rename),
    we generate a move event, rather than an add event.
    """
    container = {}

    # We create a first item
    item = Item()
    setitem(container, container.__setitem__, u'c1', item)

    # Add operation are "moved" events.
    assert len(getEvents(IObjectMovedEvent)) == 1

    # We created an item already contained.
    item = Item()
    item.__parent__, item.__name__ = container, 'c2'
    setitem(container, container.__setitem__, u'c2', item)

    assert len(container) == 2
    assert len(getEvents(IObjectAddedEvent)) == 1
    assert len(getEvents(IObjectModifiedEvent)) == 1
    assert len(getEvents(IObjectMovedEvent)) == 1

    # We now rewrite 'c2' under another name
    # Thus, we created a move event : +1 modification +1 move.
    setitem(container, container.__setitem__, u'c3', item)

    assert len(container) == 3
    assert len(getEvents(IObjectAddedEvent)) == 1
    assert len(getEvents(IObjectModifiedEvent)) == 2
    assert len(getEvents(IObjectMovedEvent)) == 2

    # We also get the move hook called, but not the add hook:
    event = getEvents(IObjectMovedEvent)[-1]
    assert getattr(item, 'added', None) is None
    assert item.moved is event

    # we clean our test.
    clearEvents()
Пример #20
0
 def assertImportZip(self,
                     filename,
                     imported,
                     replace=False,
                     update=False,
                     ignore_top_level=False):
     """Import a ZIP file.
     """
     clearEvents()
     request = TestRequest()
     importer = ZipImporter(
         self.root, request, {
             'replace_content': replace,
             'update_content': update,
             'ignore_top_level_content': ignore_top_level
         })
     with self.layer.open_fixture(filename) as source:
         importer.importStream(source)
     self.assertItemsEqual(
         map(lambda event: '/'.join(event.object.getPhysicalPath()),
             getEvents(IContentImported)), imported)
     return importer
Пример #21
0
    def test_delete_tile_removes_persistent_data(self):
        # https://github.com/collective/collective.cover/issues/765
        from collective.cover.config import CONFIGURATION_PREFIX
        from collective.cover.config import PERMISSIONS_PREFIX
        from zope.annotation import IAnnotations
        from zope.component import eventtesting
        from zope.lifecycleevent import IObjectModifiedEvent
        eventtesting.setUp()
        annotations = IAnnotations(self.tile.context)

        data_mgr = ITileDataManager(self.tile)
        data_mgr.set({'test': 'data'})
        self.assertIn('test', data_mgr.get())
        self.assertEqual(data_mgr.get()['test'], 'data')

        permissions = getMultiAdapter(
            (self.cover, self.request, self.tile), ITilesPermissions)
        permissions.set_allowed_edit('masters_of_the_universe')
        self.assertIn(PERMISSIONS_PREFIX + '.test', annotations)

        configuration = getMultiAdapter(
            (self.cover, self.request, self.tile), ITilesConfigurationScreen)
        configuration.set_configuration({'uuid': 'c1d2e3f4g5jrw'})
        self.assertIn(CONFIGURATION_PREFIX + '.test', annotations)

        # Call the delete method
        eventtesting.clearEvents()
        self.tile.delete()

        # Now we should not see the persistent data anymore
        self.assertNotIn('test', data_mgr.get())
        self.assertNotIn(PERMISSIONS_PREFIX + '.test', annotations)
        self.assertNotIn(CONFIGURATION_PREFIX + '.test', annotations)

        # Finally, test that ObjectModifiedEvent was fired for the cover
        events = eventtesting.getEvents()
        self.assertEqual(len(events), 1)
        self.assertTrue(IObjectModifiedEvent.providedBy(events[0]))
Пример #22
0
    def test_delete_tile_removes_persistent_data(self):
        # https://github.com/scmos.scmos.cover/issues/765
        from scmos.cover.config import CONFIGURATION_PREFIX
        from scmos.cover.config import PERMISSIONS_PREFIX
        from zope.annotation import IAnnotations
        from zope.component import eventtesting
        from zope.lifecycleevent import IObjectModifiedEvent
        eventtesting.setUp()
        annotations = IAnnotations(self.tile.context)

        data_mgr = ITileDataManager(self.tile)
        data_mgr.set({'test': 'data'})
        self.assertIn('test', data_mgr.get())
        self.assertEqual(data_mgr.get()['test'], 'data')

        permissions = getMultiAdapter((self.cover, self.request, self.tile),
                                      ITilesPermissions)
        permissions.set_allowed_edit('masters_of_the_universe')
        self.assertIn(PERMISSIONS_PREFIX + '.test', annotations)

        configuration = getMultiAdapter((self.cover, self.request, self.tile),
                                        ITilesConfigurationScreen)
        configuration.set_configuration({'uuid': 'c1d2e3f4g5jrw'})
        self.assertIn(CONFIGURATION_PREFIX + '.test', annotations)

        # Call the delete method
        eventtesting.clearEvents()
        self.tile.delete()

        # Now we should not see the persistent data anymore
        self.assertNotIn('test', data_mgr.get())
        self.assertNotIn(PERMISSIONS_PREFIX + '.test', annotations)
        self.assertNotIn(CONFIGURATION_PREFIX + '.test', annotations)

        # Finally, test that ObjectModifiedEvent was fired for the cover
        events = eventtesting.getEvents()
        self.assertEqual(len(events), 1)
        self.assertTrue(IObjectModifiedEvent.providedBy(events[0]))
Пример #23
0
def test_replace():
    """If we try to replace an item without deleting it first, we'll get
    an error.
    """
    container = {}

    # We create a first item
    item = Item()
    setitem(container, container.__setitem__, u'c', item)

    # We try to override
    with pytest.raises(KeyError):
        setitem(container, container.__setitem__, u'c', [])

    # We have to delete to replace a key
    del container[u'c']
    setitem(container, container.__setitem__, u'c', [])

    assert len(getEvents(IObjectAddedEvent)) == 2
    assert len(getEvents(IObjectModifiedEvent)) == 2

    # we clean our test.
    clearEvents()
Пример #24
0
def test_interface_providing():
    """If the object implements `ILocation`, but not `IContained`, set it's
    `__parent__` and `__name__` attributes *and* declare that it
    implements `IContained`.
    """
    container = {}

    item = Location()
    assert not IContained.providedBy(item)

    setitem(container, container.__setitem__, u'l', item)
    assert container[u'l'] is item
    assert item.__parent__ is container
    assert item.__name__ == u'l'
    assert IContained.providedBy(item)

    # We get added and modification events:
    assert len(getEvents(IObjectAddedEvent)) == 1
    assert len(getEvents(IObjectModifiedEvent)) == 1

    # If the object doesn't even implement `ILocation`, put a
    # `ContainedProxy` around it:
    item = []
    setitem(container, container.__setitem__, u'i', item)
    assert container[u'i'] == []
    assert not container[u'i'] is item

    item = container[u'i']
    assert item.__parent__ is container
    assert item.__name__ == u'i'

    assert IContained.providedBy(item)
    assert len(getEvents(IObjectAddedEvent)) == 2
    assert len(getEvents(IObjectModifiedEvent)) == 2

    # we clean our test.
    clearEvents()
Пример #25
0
    def test_register_styles_record(self):
        registry = getUtility(IRegistry)
        record = 'collective.cover.controlpanel.ICoverSettings.styles'

        eventtesting.setUp()

        # calling the handler here should have no effect as we are running the
        # latest profile version
        eventtesting.clearEvents()
        register_styles_record(self.portal)
        events = eventtesting.getEvents(IRecordAddedEvent)
        self.assertEqual(len(events), 0)

        # now we delete the record and rerun the handler to verify the record
        # was added
        del registry.records[record]
        eventtesting.clearEvents()
        register_styles_record(self.portal)
        events = eventtesting.getEvents(IRecordAddedEvent)
        self.assertNotEqual(len(events), 0)
        self.assertIn(record, registry.records)
        eventtesting.clearEvents()
Пример #26
0
    def test_register_available_tiles_record(self):
        registry = getUtility(IRegistry)
        record = 'collective.cover.controlpanel.ICoverSettings.available_tiles'

        eventtesting.setUp()

        # calling the handler here should have no effect as we are running the
        # latest profile version
        eventtesting.clearEvents()
        register_available_tiles_record(self.portal)
        events = eventtesting.getEvents(IRecordAddedEvent)
        self.assertEqual(len(events), 0)

        # now we delete the record and rerun the handler to verify the record
        # was added
        del registry.records[record]
        eventtesting.clearEvents()
        register_available_tiles_record(self.portal)
        events = eventtesting.getEvents(IRecordAddedEvent)
        self.assertNotEqual(len(events), 0)
        self.assertIn(record, registry.records)
        eventtesting.clearEvents()
Пример #27
0
 def tearDown(cls):
     # always safe to clear events
     eventtesting.clearEvents() # redundant with zope.testing.cleanup
Пример #28
0
 def tearDown(self):
     """Clean up after yourself."""
     self.log.clear()
     eventtesting.clearEvents()
 def tearDown(self):
     eventtesting.clearEvents()
Пример #30
0
 def setUp(self):
     super(Test, self).setUp()
     ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget)
     ztapi.provideAdapter(IFoo, IBar, FooBarAdapter)
     clearEvents()
Пример #31
0
 def testTearDown(self):
     clearEvents()
Пример #32
0
def teardown_module(module):
    clearEvents()
    cleanUp()
Пример #33
0
 def setUp(self):
     super(Test, self).setUp()
     ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget)
     ztapi.provideAdapter(IFoo, IBar, FooBarAdapter)
     clearEvents()
Пример #34
0
    def test_validity(self, DT):
        """Integration test of @@validity view."""
        DT.return_value = DateTime('2012/01/01')

        # first, let's create a member and enable it
        api.group.create(groupname='ipn_1')
        group = api.group.get(groupname='ipn_1')
        group.setGroupProperties(mapping={'validity': 31})
        self.ipn.enable_member(
            email='*****@*****.**',
            product_id='1',
            trans_type='SALE',
            fullname='New Member',
            affiliate='*****@*****.**',
        )

        # clear after yourself before you start testing
        self.log.clear()
        eventtesting.clearEvents()

        # all is prepared, let's run @@validity as anonymous user, a
        # month after the initial sale
        logout()
        DT.return_value = DateTime('2012/02/02')
        self.request['secret'] = 'secret'
        view = self.portal.restrictedTraverse('validity')
        html = view.render()

        # test member is in Disabled group
        self.assertIn(
            'disabled',
            [g.id for g in api.group.get_groups(username='******')]
        )

        # test member is in no other group
        # TODO: for some reason api.group.remove_user does not work here
        # if I pass in "user=member" --> it is not removed from group???
        self.assertItemsEqual(
            ['disabled', 'AuthenticatedUsers', ],
            [g.id for g in api.group.get_groups(username='******')]
        )

        # test member does not have the Member role
        self.assertNotIn('Member', api.user.get_roles(username='******'))

        # test event emitted
        events = list(set(eventtesting.getEvents(IMemberDisabledEvent)))
        self.assertEquals(len(events), 1)
        self.assertEquals(events[0].username, '*****@*****.**')

        # test member history
        self.assert_member_history(
            username='******',
            history=['2012/01/01 00:00:00|enable_member|1|SALE|',
                     '2012/02/02 00:00:00|disable_member|1|cronjob|'
                     'removed from groups: ipn_1, ']
        )

        # test HTML output
        self.assertEquals(
            html.split('\n'),
            [
                "START validity check.",
                "Disabling member '*****@*****.**' (2012/02/01).",
            ]
        )

        # test log output
        self.assertEqual(len(self.log.records), 5)
        self.assert_log_record(
            'INFO',
            'Anonymous User',
            "START disable_member:cronjob for '*****@*****.**'.",
        )
        self.assert_log_record(
            'INFO',
            'Anonymous User',
            "Adding member '*****@*****.**' to Disabled group.",
        )
        self.assert_log_record(
            'INFO',
            'Anonymous User',
            "Removing member '*****@*****.**' from group 'ipn_1'.",
        )
        self.assert_log_record(
            'INFO',
            'Anonymous User',
            "Revoking member '*****@*****.**' the Member role.",
        )
        self.assert_log_record(
            'INFO',
            'Anonymous User',
            "END disable_member:cronjob for '*****@*****.**'.",
        )
Пример #35
0
 def testTearDown(self):
     clearEvents()
 def tearDown(self):
     self.ideal._do_request = self.ideal.old_do_request
     eventtesting.clearEvents()
Пример #37
0
 def testTearDown(cls):
     # Some tear down needs to happen always
     eventtesting.clearEvents()
     transaction.abort() # see comments above
Пример #38
0
 def tearDown(self):
     super(TestFileDownload, self).tearDown()
     eventtesting.clearEvents()
Пример #39
0
    def test_round_trip(self):
        """Make a trip:
        1. Create items.
        2. Export them.
        3. Import them.
        4. Export them.
        5. Check that export created at 2. and 4. are identical.
        """
        # 1. create content
        # 2. export
        exporter1 = getAdapter(
            self.root.publication,
            interfaces.IContentExporter, name='zip')
        self.assertTrue(verifyObject(interfaces.IContentExporter, exporter1))

        export1 = exporter1.export(TestRequest())

        # 3. import
        factory = self.root.manage_addProduct['Silva']
        factory.manage_addFolder('folder', 'Import Folder')
        importer = getAdapter(
            self.root.folder, interfaces.IZipFileImporter)
        self.assertTrue(verifyObject(interfaces.IZipFileImporter, importer))

        clearEvents()
        importer.importFromZip(StringIO(export1), TestRequest())

        self.assertEventsAre(
            ['ContentImported for /root/folder/publication',
             'ContentImported for /root/folder/publication/assets',
             'ContentImported for /root/folder/publication/infrae',
             'ContentImported for /root/folder/publication/nice',
             'ContentImported for /root/folder/publication/pictures',
             'ContentImported for /root/folder/publication/pictures/tobesorted',
             'ContentImported for /root/folder/publication/pictures/torvald',
             'ContentImported for /root/folder/publication/pictures/unknown',
             'ContentImported for /root/folder/publication/trash'],
            IContentImported)

        imported_ghost = self.root.folder.publication.nice
        imported_link = self.root.folder.publication.infrae
        self.assertEqual(
            imported_ghost.get_editable().get_haunted(),
            imported_link)

        # 4. export
        exporter2 = getAdapter(
            self.root.folder.publication,
            interfaces.IContentExporter, name='zip')

        export2 = exporter2.export(TestRequest())

        # 5. compare the two exports
        zip_export1 = ZipFile(StringIO(export1))
        zip_export2 = ZipFile(StringIO(export2))

        self.failUnless('silva.xml' in zip_export1.namelist())
        self.assertItemsEqual(zip_export1.namelist(), zip_export2.namelist())
        silva_export1 = zip_export1.read('silva.xml')
        silva_export2 = zip_export2.read('silva.xml')

        self.assertXMLEqual(silva_export1, silva_export2)