Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:37:07+00:00 2026-06-09T18:37:07+00:00

For a project, I have a complex master object that contains a number of

  • 0

For a project, I have a complex master object that contains a number of subcomponents. Set up of these objects is controlled by a Constructor interface, which I bind to various lifecycle & workflow events, like so:

@grok.subscribe(schema.ICustomFolder, lifecycleevent.IObjectAddedEvent)
def setup_custom_folder(folder, event):
    interfaces.IConstructor(folder).setup()

@grok.subscribe(schema.ICustomFolder, lifecycleevent.IObjectModifiedEvent)
def setup_custom_folder(folder, event):
    interfaces.IConstructor(folder).update()

What I’d like to be able to do is test the Constructor methods without relying on the event handlers. I’ve tried doing this by creating objects directly to avoid the lifecycle events:

def test_custom_item_constructor(self):
    master = createContent('model.master_object', 
        needed_attribute = 2
    )
    folder = createContent('model.custom_folder',
        __parent__ = master
    )
    self.assertEqual(0, len(folder))
    constructor = interfaces.IConstructor(folder)
    constructor.setup()
    self.assertEqual(2, len(folder))

The setup method creates a number of items inside the Custom_Folder instance, dependent on the provided attribute on the master object. However, this is hanging, which I think is due to neither object actually belonging to the site, so there’s no acquisition of permissions. I can get this by changing the createContent on the master object to createContentInContainer and adding it to the appropriate part of the test site, but that triggers all of the lifecycle events, which end up doing the Constructor calls, which doesn’t let me test them in isolation.

I’ve tried using mock objects for this, but that got messy dealing with the content creation that is meant to occur during the Constructor .setup.

What’s the best way to approach this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:37:08+00:00Added an answer on June 9, 2026 at 6:37 pm

    I’m not sure if this is the best way, but I managed to get the result I wanted by disabling the relevant event handlers first, and then creating the content properly within the site:

    def test_custom_item_constructor(self):
        zope.component.getGlobalSiteManager().unregisterHandler(
            adapters.master.constructor.setup_masterobject,
            required=[schema.IMasterObject, lifecycleevent.IObjectAddedEvent]
        )
        zope.component.getGlobalSiteManager().unregisterHandler(
            adapters.custom.constructor.setup_customfolder,
            required=[schema.ICustomFolder, lifecycleevent.IObjectAddedEvent]
        )
        master = createContentInContainer(self.portal, 'model.master_object', 
            needed_attribute = 2
        )
        folder = createContentInContainer(master, 'model.custom_folder',
            __parent__ = master
        )
        self.assertEqual(0, len(folder))
        constructor = interfaces.IConstructor(folder)
        constructor.setup()
        self.assertEqual(2, len(folder))
    

    This was enough to disengage the chain of events triggered by the addition of a new master object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex hierarchy of objects that we can represent, for illustration purpose,
I have a complex C# project that I ported over from C++ and now
I currently have a project there are a number of forms that are processed
In my symfony project, I have a complex query that looks like: $d =
I have a complex project that uses a Ruby::Rake system to generate java (and
I have a complex project where there are many directories that have POM files,
in my Java project I have a lot of JasperReports reports with complex SQL
I have a very complex web app project I want to re-structure. Naturally, it
I have a C++ project that have like 15+ external libraries installed with a
I have project Emle in Launchpad . I set it to import from emle.svn.sourceforge.net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.