def testSubObjectMismatch(self):
        mock = simple_mock.MockObject()
        mock.bar = simple_mock.MockObject(mock)

        mock.ExpectCall('foo').WithArgs(_, 4)
        mock.bar.ExpectCall('baz')

        self.assertRaises(Exception, lambda: mock.bar.baz())  # pylint: disable=W0108
    def testSubObject(self):
        mock = simple_mock.MockObject()
        mock.bar = simple_mock.MockObject(mock)

        mock.ExpectCall('foo').WithArgs(_, 4)
        mock.bar.ExpectCall('baz')

        mock.foo(0, 4)
        mock.bar.baz()
Пример #3
0
    def _LoginUsingMock(self, backend, login_page_url, email_element_id,
                        password_element_id):  # pylint: disable=R0201
        tab = simple_mock.MockObject()

        config = {'username': '******', 'password': '******'}

        tab.ExpectCall('Navigate', login_page_url)
        tab.ExpectCall('EvaluateJavaScript', _).WillReturn(False)
        tab.ExpectCall('EvaluateJavaScript', _).WillReturn(True)
        tab.ExpectCall('EvaluateJavaScript', _).WillReturn(False)
        tab.ExpectCall('WaitForDocumentReadyStateToBeInteractiveOrBetter')

        def VerifyEmail(js):
            assert email_element_id in js
            assert 'blah' in js

        tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyEmail)

        def VerifyPw(js):
            assert password_element_id in js
            assert 'largh' in js

        tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyPw)

        def VerifySubmit(js):
            assert '.submit' in js

        tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifySubmit)

        # Checking for form still up.
        tab.ExpectCall('EvaluateJavaScript', _).WillReturn(False)

        backend.LoginNeeded(tab, config)
    def testOnCall(self):
        mock = simple_mock.MockObject()

        handler_called = []

        def Handler(arg0):
            assert arg0 == 7
            handler_called.append(True)

        mock.ExpectCall('baz', 7).WhenCalled(Handler)

        mock.baz(7)
        self.assertTrue(len(handler_called) > 0)
    def testArgsDontCare(self):
        mock = simple_mock.MockObject()
        mock.ExpectCall('foo').WithArgs(_, 4)

        mock.foo(4, 4)
    def testArgsMismatch(self):
        mock = simple_mock.MockObject()
        mock.ExpectCall('foo').WithArgs(3, 4)

        self.assertRaises(Exception, lambda: mock.foo(4, 4))
    def testArgs2(self):
        mock = simple_mock.MockObject()
        mock.ExpectCall('foo', 3, 4)

        mock.foo(3, 4)
    def testArgs(self):
        mock = simple_mock.MockObject()
        mock.ExpectCall('foo').WithArgs(3, 4)

        mock.foo(3, 4)
    def testReturn(self):
        mock = simple_mock.MockObject()
        mock.ExpectCall('foo').WillReturn(7)

        ret = mock.foo()
        self.assertEquals(ret, 7)
Пример #10
0
    def testBasic(self):
        mock = simple_mock.MockObject()
        mock.ExpectCall('foo')

        mock.foo()