How to spy on Mock-wrapped method calls in Python

You have a class whose API you want to verify:

[python] class Class_A(object):
def method_X(self):
self.method_Y()

def method_Y(self):
pass
[/python]

You write the following test fully expecting it to pass. Alas, the method_Y assertion fails.

[python] def test_class_a(self):
obj = Class_A()
mock = MagicMock(spec_set=obj, wraps=obj)

mock.method_X()
mock.method_Y.assert_called_once_with()
[/python]

This is because the Python Unittest Mock, while wrapping mock.method_X(), Mock uses obj in the __self__ of the method_Y binding. As a result the self value passed to method_X is that of the obj and not mock and the call to method_Y is therefore invisible to the Mock.

Continue reading “How to spy on Mock-wrapped method calls in Python”

PicketLink and EARs on WildFly

PicketLink provides a wealth of security functionality, including identity management, federation and authorization in various forms. Unfortunately, WildFly 8.2 with PicketLink 2.7.0.Final suffers from integration issues and documentation gap that makes it very hard to deploy PicketLink in a multi-module enterprise application. The issues discussed below are described ad nauseam in PLINK-666.

This guide assumes you have PicketLink installed as a WildFly-scoped module rather than shipping PicketLink libraries in your EAR or WAR lib directory. Since I’m using PicketLink Subsystem for WildFly 8, this is the scenario described here. I have not found any evidence of anyone successfully using PicketLink when JARs were shipped in an EAR lib directory propagating PicketLink to subdeployments.

Continue reading “PicketLink and EARs on WildFly”