mockito.ANY

Here are the examples of the python api mockito.ANY taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

20 Examples 7

Example 1

View license
    @defer.inlineCallbacks
    def test_get_mail_not_exist(self):
        with patch('mockito.invocation.AnswerSelector', AnswerSelector):
            when(self.soledad).get_doc(ANY()).thenAnswer(lambda: defer.succeed(None))
        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(_format_mdoc_id(uuid4(), 1))

        self.assertIsNone(mail)

Example 2

View license
    @defer.inlineCallbacks
    def test_add_mailbox(self):
        when(self.soledad).list_indexes().thenReturn(defer.succeed(MAIL_INDEXES)).thenReturn(defer.succeed(MAIL_INDEXES))
        when(self.soledad).get_from_index('by-type-and-mbox', 'mbox', 'TEST').thenReturn(defer.succeed([]))
        self._mock_create_soledad_doc(self.mbox_uuid, MailboxWrapper(mbox='TEST'))
        with patch('mockito.invocation.AnswerSelector', AnswerSelector):
            when(self.soledad).get_doc(self.mbox_uuid).thenAnswer(lambda: defer.succeed(self.doc_by_id[self.mbox_uuid]))
            when(self.soledad).put_doc(ANY()).thenAnswer(lambda: defer.succeed(None))
        store = LeapMailStore(self.soledad)

        mbox = yield store.add_mailbox('TEST')

        self.assertIsNotNone(mbox)
        self.assertEqual(self.mbox_uuid, mbox.doc_id)
        self.assertEqual('TEST', mbox.mbox)
        self.assertIsNotNone(mbox.uuid)

Example 3

View license
    @defer.inlineCallbacks
    def test_catches_exceptions_to_not_break_other_listeners(self):
        when(logger).error(ANY()).thenReturn(None)
        listener = MailboxIndexerListener('INBOX', self.mail_store, mock())

        yield listener.notify_new()

        verify(logger).error(ANY())

Example 4

View license
    def test_send_mail(self):
        when(InputMail).from_dict(ANY(), ANY()).thenReturn(self.mail)
        when(self.mail_sender).sendmail(ANY()).thenReturn(defer.Deferred())

        sent_deferred = self.mail_service.send_mail(mail_dict())

        verify(self.mail_sender).sendmail(self.mail)

        sent_deferred.callback('Assume sending mail succeeded')

        return sent_deferred

Example 5

View license
    @defer.inlineCallbacks
    def test_send_mail_removes_draft(self):
        mail = LeapMail('id', 'INBOX')
        when(mail).raw = 'raw mail'
        mail._headers['To'] = []
        mail._headers['Cc'] = []
        mail._headers['Bcc'] = []
        when(InputMail).from_dict(ANY(), ANY()).thenReturn(mail)
        when(self.mail_store).delete_mail('12').thenReturn(defer.succeed(None))
        when(self.mail_store).add_mail('SENT', ANY()).thenReturn(mail)

        deferred_success = defer.succeed(None)
        when(self.mail_sender).sendmail(ANY()).thenReturn(deferred_success)

        yield self.mail_service.send_mail({'ident': '12'})

        verify(self.mail_sender).sendmail(mail)
        verify(self.mail_store).add_mail('SENT', mail.raw)
        verify(self.mail_store).delete_mail('12')

Example 6

View license
    @defer.inlineCallbacks
    def test_send_mail_marks_as_read(self):
        when(self.mail).raw = 'raw mail'
        when(InputMail).from_dict(ANY(), ANY()).thenReturn(self.mail)
        when(self.mail_store).delete_mail('12').thenReturn(defer.succeed(None))
        when(self.mail_sender).sendmail(self.mail).thenReturn(defer.succeed(None))

        sent_mail = LeapMail('id', 'INBOX')
        add_mail_deferral = defer.succeed(sent_mail)
        when(self.mail_store).add_mail('SENT', ANY()).thenReturn(add_mail_deferral)

        yield self.mail_service.send_mail({'ident': '12'})

        self.assertIn(Status.SEEN, sent_mail.flags)
        verify(self.mail_store).update_mail(sent_mail)

Example 7

View license
    @defer.inlineCallbacks
    def test_send_mail_does_not_delete_draft_on_error(self):
        when(InputMail).from_dict(ANY(), ANY()).thenReturn(self.mail)

        deferred_failure = defer.fail(Exception("Assume sending mail failed"))
        when(self.mail_sender).sendmail(ANY()).thenReturn(deferred_failure)

        try:
            yield self.mail_service.send_mail({'ident': '12'})
            self.fail("send_mail is expected to raise if underlying call fails")
        except:
            verify(self.mail_sender).sendmail(self.mail)
            verifyNoMoreInteractions(self.drafts)

Example 8

View license
    @defer.inlineCallbacks
    def test_delete_mail_does_not_fail_for_invalid_mail(self):
        no_mail = None
        mail_id = 1
        when(self.mail_store).get_mail(mail_id, include_body=True).thenReturn(defer.succeed(no_mail))

        yield self.mail_service.delete_mail(mail_id)

        verify(self.mail_store, never).delete_mail(mail_id)
        verify(self.mail_store, never).move_mail_to_mailbox(mail_id, ANY())

Example 9

View license
    def test_download_certificate(self):
        cert = SmtpClientCertificate(self.provider, self.auth, self.tmp_dir.name)
        when(cert).download_to(ANY()).thenReturn(None)
        result = cert.cert_path()

        self.assertEqual(self.pem_path, result)

Example 10

View license
    def test_download_certificate_if_redownload_necessary_e_g_certificate_expired(self):
        self.pretend_all_paths_exist()
        when(certs).should_redownload(self.pem_path).thenReturn(True)

        cert = SmtpClientCertificate(self.provider, self.auth, self.tmp_dir.name)
        when(cert).download_to(ANY()).thenReturn(None)
        result = cert.cert_path()

        self.assertEqual(self.pem_path, result)

Example 11

View license
    def test_skip_download_if_already_downloaded_and_still_valid(self):
        when(os.path).exists(self.pem_path).thenReturn(True)
        when(certs).should_redownload(ANY()).thenReturn(False)
        cert = SmtpClientCertificate(self.provider, self.auth, self.tmp_dir.name)
        result = cert.cert_path()

        self.assertEqual(self.pem_path, result)

Example 12

View license
    def setUp(self):
        self.mail_service = mock()
        self.services_factory = mock()
        self.services_factory.mode = UserAgentMode(is_single_user=True)
        self.services = mock()
        self.services.mail_service = self.mail_service
        self.services_factory._services_by_user = {'someuserid': self.mail_service}
        when(self.services_factory).services(ANY()).thenReturn(self.services)

        self.mails_resource = AttachmentsResource(self.services_factory)
        self.mails_resource.isLeaf = True
        self.web = DummySite(self.mails_resource)

Example 13

View license
    def setUp(self):
        self.feedback_service = mock()
        self.services_factory = mock()
        self.services_factory.mode = UserAgentMode(is_single_user=True)
        self.services = mock()
        self.services.feedback_service = self.feedback_service
        self.services_factory._services_by_user = {'someuserid': self.feedback_service}
        when(self.services_factory).services(ANY()).thenReturn(self.services)

        self.web = DummySite(FeedbackResource(self.services_factory))

Example 14

View license
    def setUp(self):
        self.keymanager = mock()
        self.services_factory = mock()
        self.services_factory.mode = UserAgentMode(is_single_user=True)
        self.services = mock()
        self.services.keymanager = self.keymanager
        self.services_factory._services_by_user = {'someuserid': self.keymanager}
        when(self.services_factory).services(ANY()).thenReturn(self.services)
        self.web = DummySite(KeysResource(self.services_factory))

Example 15

View license
    @patch('pixelated.resources.session.PixelatedSession.is_logged_in')
    def test_there_are_no_grand_children_resources_when_logged_in(self, mock_is_logged_in):
        request = DummyRequest(['/login/grand_children'])
        mock_is_logged_in.return_value = True
        when(self.services_factory).has_session(ANY()).thenReturn(True)

        d = self.web.get(request)

        def assert_resources_not_found(_):
            self.assertEqual(404, request.responseCode)
            self.assertIn("No Such Resource", request.written[0])

        d.addCallback(assert_resources_not_found)
        return d

Example 16

View license
    @patch('pixelated.authentication.Authenticator.authenticate')
    @patch('twisted.web.util.redirectTo')
    @patch('pixelated.resources.session.PixelatedSession.is_logged_in')
    def test_should_redirect_to_home_if_user_if_already_logged_in(self, mock_logged_in, mock_redirect, mock_authenticate):
        mock_logged_in.return_value = True
        when(self.services_factory).has_session(ANY()).thenReturn(True)
        mock_redirect.return_value = "mocked redirection"

        d = self.web.get(self.request)

        def assert_redirected_to_home(_):
            mock_redirect.assert_called_once_with('/', self.request)
            self.assertFalse(mock_authenticate.called)

        d.addCallback(assert_redirected_to_home)
        return d

Example 17

View license
    def setUp(self):
        self.mail_service = mock()
        self.services_factory = mock()
        self.services_factory.mode = UserAgentMode(is_single_user=True)
        self.services = mock()
        self.services.mail_service = self.mail_service
        self.services.draft_service = mock()
        self.services_factory._services_by_user = {'someuserid': self.mail_service}
        when(self.services_factory).services(ANY()).thenReturn(self.services)

Example 18

View license
    def setUp(self):
        self.mail_service = mock()
        self.services_factory = mock()
        self.services_factory.mode = UserAgentMode(is_single_user=True)
        self.services = mock()
        self.services.mail_service = self.mail_service
        self.services_factory._services_by_user = {'someuserid': self.mail_service}
        when(self.services_factory).services(ANY()).thenReturn(self.services)
        self.mail_service.account_email = self.MAIL_ADDRESS

        root_resource = RootResource(self.services_factory)
        root_resource._html_template = "<html><head><title>$account_email</title></head></html>"
        root_resource._mode = root_resource
        self.web = DummySite(root_resource)
        self.root_resource = root_resource

Example 19

View license
    def login(self, username='username', password='password'):
        session = Authentication(username, 'some_user_token', 'some_user_uuid', 'session_id', {'is_admin': False})
        leap_session = self._test_account.leap_session
        leap_session.user_auth = session
        config = mock()
        config.leap_home = 'some_folder'
        leap_session.config = config
        leap_session.fresh_account = False
        self.leap_session = leap_session
        self.services = self._test_account.services
        self.user_auth = session

        self._mock_bonafide_auth(username, password)

        when(LeapSessionFactory).create(username, password, session).thenReturn(leap_session)
        with patch('mockito.invocation.AnswerSelector', AnswerSelector):
            when(leap_session).initial_sync().thenAnswer(lambda: defer.succeed(None))
        when(pixelated.config.services).Services(ANY()).thenReturn(self.services)

        request = request_mock(path='/login', method="POST", body={'username': username, 'password': password})
        return self._render(request, as_json=False)

Example 20

View license
    def pretend_all_paths_exist(self):
        when(os.path).exists(ANY()).thenReturn(True)