~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/factory.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-08-03 22:06:56 UTC
  • mfrom: (11280.1.1 shout-more-effectively)
  • Revision ID: launchpad@pqm.canonical.com-20100803220656-h0c1fowy3vwg8ra0
[r=sinzui][ui=none][no-qa]
        remove_security_proxy_and_shout_at_engineer now gives clearer
        directions

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import os.path
32
32
from random import randint
33
33
from StringIO import StringIO
34
 
import sys
35
34
from textwrap import dedent
36
35
from threading import local
37
36
from types import InstanceType
2797
2796
            "unproxied object." % (method_name,))
2798
2797
 
2799
2798
 
2800
 
class UnreasonableRemoveSecurityProxyWarning(UserWarning):
2801
 
    """Raised when there is an unreasonable call to removeSecurityProxy."""
2802
 
 
2803
 
    # XXX: JonathanLange 2010-07-25: I have no idea what "unreasonable" means
2804
 
    # in this context.
 
2799
class ShouldThisBeUsingRemoveSecurityProxy(UserWarning):
 
2800
    """Raised when there is a potentially bad call to removeSecurityProxy."""
2805
2801
 
2806
2802
    def __init__(self, obj):
2807
2803
        message = (
2808
 
            "Called removeSecurityProxy(%r) without a check if this is "
2809
 
            "reasonable." % obj)
2810
 
        super(UnreasonableRemoveSecurityProxyWarning, self).__init__(message)
 
2804
            "removeSecurityProxy(%r) called. Is this correct? "
 
2805
            "Either call it directly or fix the test." % obj)
 
2806
        super(ShouldThisBeUsingRemoveSecurityProxy, self).__init__(message)
2811
2807
 
2812
2808
 
2813
2809
class LaunchpadObjectFactory:
2850
2846
    This function should only be used in legacy tests which fail because
2851
2847
    they expect unproxied objects.
2852
2848
    """
2853
 
    warnings.warn(UnreasonableRemoveSecurityProxyWarning(obj), stacklevel=2)
 
2849
    warnings.warn(ShouldThisBeUsingRemoveSecurityProxy(obj), stacklevel=2)
2854
2850
    return removeSecurityProxy(obj)