Ejemplo n.º 1
0
 def test_with_object(self):
     obj_base.NovaObjectRegistry.register(test_objects.MyObj)
     obj = test_objects.MyObj(foo=1, bar="baz")
     tester = mock.Mock()
     tester.foo(1, obj)
     self.assertTrue(test_utils.obj_called_with(tester.foo, 1, test_objects.MyObj(foo=1, bar="baz")))
     self.assertFalse(test_utils.obj_called_with(tester.foo, 1, test_objects.MyObj(foo=2, bar="baz")))
Ejemplo n.º 2
0
    def test_with_object_multiple(self):
        obj_base.NovaObjectRegistry.register(test_objects.MyObj)
        obj1 = test_objects.MyObj(foo=1, bar='baz')
        obj2 = test_objects.MyObj(foo=3, bar='baz')
        tester = mock.Mock()
        tester.foo(1, obj1)
        tester.foo(1, obj1)
        tester.foo(3, obj2)

        # Called at all
        self.assertTrue(
            test_utils.obj_called_with(tester.foo, 1,
                                       test_objects.MyObj(foo=1, bar='baz')))

        # Called once (not true)
        self.assertFalse(
            test_utils.obj_called_once_with(
                tester.foo, 1, test_objects.MyObj(foo=1, bar='baz')))

        # Not called with obj.foo=2
        self.assertFalse(
            test_utils.obj_called_with(tester.foo, 1,
                                       test_objects.MyObj(foo=2, bar='baz')))

        # Called with obj.foo.3
        self.assertTrue(
            test_utils.obj_called_with(tester.foo, 3,
                                       test_objects.MyObj(foo=3, bar='baz')))

        # Called once with obj.foo.3
        self.assertTrue(
            test_utils.obj_called_once_with(
                tester.foo, 3, test_objects.MyObj(foo=3, bar='baz')))
Ejemplo n.º 3
0
 def test_with_primitives(self):
     tester = mock.Mock()
     tester.foo(1, 'two', three='four')
     self.assertTrue(
         test_utils.obj_called_with(tester.foo, 1, 'two', three='four'))
     self.assertFalse(
         test_utils.obj_called_with(tester.foo, 42, 'two', three='four'))
Ejemplo n.º 4
0
 def test_with_object(self):
     obj_base.NovaObjectRegistry.register(test_objects.MyObj)
     obj = test_objects.MyObj(foo=1, bar='baz')
     tester = mock.Mock()
     tester.foo(1, obj)
     self.assertTrue(
         test_utils.obj_called_with(tester.foo, 1,
                                    test_objects.MyObj(foo=1, bar='baz')))
     self.assertFalse(
         test_utils.obj_called_with(tester.foo, 1,
                                    test_objects.MyObj(foo=2, bar='baz')))
Ejemplo n.º 5
0
    def test_with_object_multiple(self):
        obj_base.NovaObjectRegistry.register(test_objects.MyObj)
        obj1 = test_objects.MyObj(foo=1, bar="baz")
        obj2 = test_objects.MyObj(foo=3, bar="baz")
        tester = mock.Mock()
        tester.foo(1, obj1)
        tester.foo(1, obj1)
        tester.foo(3, obj2)

        # Called at all
        self.assertTrue(test_utils.obj_called_with(tester.foo, 1, test_objects.MyObj(foo=1, bar="baz")))

        # Called once (not true)
        self.assertFalse(test_utils.obj_called_once_with(tester.foo, 1, test_objects.MyObj(foo=1, bar="baz")))

        # Not called with obj.foo=2
        self.assertFalse(test_utils.obj_called_with(tester.foo, 1, test_objects.MyObj(foo=2, bar="baz")))

        # Called with obj.foo.3
        self.assertTrue(test_utils.obj_called_with(tester.foo, 3, test_objects.MyObj(foo=3, bar="baz")))

        # Called once with obj.foo.3
        self.assertTrue(test_utils.obj_called_once_with(tester.foo, 3, test_objects.MyObj(foo=3, bar="baz")))
Ejemplo n.º 6
0
 def test_with_primitives(self):
     tester = mock.Mock()
     tester.foo(1, "two", three="four")
     self.assertTrue(test_utils.obj_called_with(tester.foo, 1, "two", three="four"))
     self.assertFalse(test_utils.obj_called_with(tester.foo, 42, "two", three="four"))