Issue #29 resolved

.need() call on ResourceInclusion and testing of applications/libraries that happen to depend on fanstatic

Jan-Wijbrand Kolman
created an issue

The .need() call on ResourceInclusion object fails if there is no current NeededInclusions object initialized.

This however, is very inconvenient in tests. It means that to test something that will trigger a .need() somewhere along the line, the NeededInclusions object needs to be initialized in the test-setup code of the particular application or library.

IOW in tests where you are not really interested in the resources related to your view, you still have to think about them.

In tests where you actually are interested about resources related to your view, you would probably have taken care of the NeededInclusions object in the test setup yourself already.

One solution could be to have the .need() call on the ResourceInclusion object do nothing in case there is no current NeededInclusions object to be found, like so:

{{{

!python

class ResourceInclusion(object):

def need(self):
    try:
        needed = get_current_needed_inclusions()
    except NoNeededInclusions:
        pass
    else:
        needed.need(self)

}}}

Alternatively, the .need() call could actually initialize a NeededInclusions object with default values:

{{{

!python

class ResourceInclusion(object):

def need(self):
    try:
        needed = get_current_needed_inclusions()
    except NoNeededInclusions:
        needed = init_current_needed_inclusions()
    needed.need(self)

}}}

Comments (10)

  1. faassen

    The code under test *does* need a NeededInclusions to be present in order to work. If needing were done explicitly it'd be very clear, as you'd need to do "needed.need(resource)", and "needed" needs to come from somewhere.

    We could provide a "no-operation" needed inclusions that had a .need() method that does nothing, if this is useful. We could even make this an object that gets returned as the needed inclusions by default by Fanstatic (if nothing got initialized).

  2. Jan-Wijbrand Kolman reporter

    What I wanted to address, is the ResourceInclusion.need(). If you happen to test, say, a Grok-view call Foobar, it is possible this particular view calls myniceresource.need(). In the test setup for this Foobar view component, you now need to make sure there is a NeededInclusions object initialized, even if you're not really interested (in this test) in the effect of the myniceresource.need() call.

  3. faassen

    That's why I said we could provide a no-operation needed inclusions that has a need() method that does nothing, that is installed by default. That way if you don't initialize resources that one will be used.

  4. Log in to comment