Skip to content

Commit 84038a9

Browse files
author
Greg Turnquist
committed
SESPRINGPYTHONPY-134: Backported AopProxy fix and test cases to 1.1.x
2 parents 4488b1f + 256c91e commit 84038a9

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
target/
3+
.DS_Store

src/springpython/aop/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ class AopProxy(object):
167167
lookups are not intercepted, but instead fetched from the actual target object."""
168168

169169
def __init__(self, target, interceptors):
170-
if type(target).__name__ != "instance":
171-
raise Exception("Target attribute must be an instance.")
172170
self.target = target
173171
if type(interceptors) == list:
174172
self.interceptors = interceptors

test/springpythontest/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
springpython.db

test/springpythontest/aopTestCases.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from springpython.context import ApplicationContext
2626
from springpython.remoting.pyro import PyroDaemonHolder
2727
from springpythontest.support.testSupportClasses import BeforeAndAfterInterceptor
28-
from springpythontest.support.testSupportClasses import SampleService
28+
from springpythontest.support.testSupportClasses import SampleService, NewStyleSampleService
2929
from springpythontest.support.testSupportClasses import WrappingInterceptor
3030

3131
class AopInterfaceTestCase(unittest.TestCase):
@@ -56,6 +56,15 @@ def testCreatingAProxyFactoryAndAddingAnInterceptorProgrammatically(self):
5656
self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method("test"))
5757
self.assertEquals("sample", service.attribute)
5858

59+
def testCreatingAopProxyFactoryAndAddingInterceptorToNewStyleClassProgammatically(self):
60+
factory = ProxyFactory()
61+
factory.target = NewStyleSampleService()
62+
factory.interceptors.append(WrappingInterceptor())
63+
service = factory.getProxy()
64+
self.assertEquals("<Wrapped>Even better!</Wrapped>", service.doSomething())
65+
self.assertEquals("<Wrapped>You made it to a new style class! => test</Wrapped>", service.method("test"))
66+
self.assertEquals("new_sample", service.attribute)
67+
5968
def testCreatingAProxyFactoryAndAddingAnInterceptorIoC(self):
6069
factory = self.appContext.get_object("factory")
6170
service = factory.getProxy()

test/springpythontest/support/testSupportClasses.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ def doSomething(self):
149149
def __str__(self):
150150
return "This is a sample service."
151151

152+
class NewStyleSampleService(object):
153+
def __init__(self):
154+
self.attribute = "new_sample"
155+
def method(self, data):
156+
return "You made it to a new style class! => %s" % data
157+
def doSomething(self):
158+
return "Even better!"
159+
def __str__(self):
160+
return "This is a new style sample service."
161+
152162
class RemoteService1(object):
153163
def getData(self, param):
154164
return "You got remote data => %s" % param

0 commit comments

Comments
 (0)