tests/pymox/stubout_test.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 30 Sep 2009 21:26:50 +0200
changeset 2995 5931e6d6056f
parent 1000 9af147fc1f1c
permissions -rw-r--r--
Changed the working of the iterative_task decorator. The decorator now needs the logic for the model which it fetches. This is much nicer then "fetching" it using import. Also order has been removed since it has no use when iterating over all entities when key is involved. Fields to filter can now dynamically be set by the function that is wrapped. Note that it will merge the filter with the task_default kwarg and it will only use the start_key if their is no key present in the context. Also note that task_default gathers all kwargs. I tried to do it otherwise (with default kwargs) but I couldn't get it to work. Feel free to improve :).

#!/usr/bin/python2.4
#
# Unit tests for stubout.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import mox
import stubout
import stubout_testee


class StubOutForTestingTest(unittest.TestCase):
  def setUp(self):
    self.mox = mox.Mox()
    self.sample_function_backup = stubout_testee.SampleFunction

  def tearDown(self):
    stubout_testee.SampleFunction = self.sample_function_backup

  def testSmartSetOnModule(self):
    mock_function = self.mox.CreateMockAnything()
    mock_function()

    stubber = stubout.StubOutForTesting()
    stubber.SmartSet(stubout_testee, 'SampleFunction', mock_function)

    self.mox.ReplayAll()

    stubout_testee.SampleFunction()

    self.mox.VerifyAll()


if __name__ == '__main__':
  unittest.main()