I wrote a function that copies the /etc/skel directory on a linux machine during a "create new user" RPC call. Now, there is quite a few things about this I want to test, for example the files in /etc/skel and the targets of symlinks should not have changed permissions afterwards, whereas the copied files including the actual symlinks should have a changed owner. Now, i can create my test directory and files using mkdtemp and stuff, but I can't chown those to another user without root privileges. How would you write a test for this?
views:
24answers:
1
+2
A:
You could make an object which does the chmod, and inject a mock when testing. This mock would not really do the chmod, but make it possible to test if it was called with the right parameters.
Sjoerd
2010-07-01 07:33:45
+1, a classical use case for a mock, IMO.
Philipp
2010-07-01 07:46:31
Of course... You're right, thats probably the best I can do here. Also, in Python, I don't even need to create a separate class for the chmod as you suggested - I probably can just pass in the function (functions being normal objects and such) and mock that....
Chris089
2010-07-09 06:52:02