def test_from_string(self):
     stack = config.MemoryStack("ssl.cert_reqs = none\n")
     self.assertEqual(ssl.CERT_NONE, stack.get("ssl.cert_reqs"))
     stack = config.MemoryStack("ssl.cert_reqs = required\n")
     self.assertEqual(ssl.CERT_REQUIRED, stack.get("ssl.cert_reqs"))
     stack = config.MemoryStack("ssl.cert_reqs = invalid\n")
     self.assertRaises(ConfigOptionValueError, stack.get, "ssl.cert_reqs")
Пример #2
0
    def test_commit_failed_signature(self):
        import bzrlib.gpg
        import bzrlib.commit as commit
        oldstrategy = bzrlib.gpg.GPGStrategy
        wt = self.make_branch_and_tree('.')
        branch = wt.branch
        wt.commit("base", allow_pointless=True, rev_id='A')
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
        try:
            # monkey patch gpg signing mechanism
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
            conf = config.MemoryStack('''
gpg_signing_command=cat -
create_signatures=always
''')
            self.assertRaises(SigningFailed,
                              commit.Commit(config_stack=conf).commit,
                              message="base",
                              allow_pointless=True,
                              rev_id='B',
                              working_tree=wt)
            branch = Branch.open(self.get_url('.'))
            self.assertEqual(branch.last_revision(), 'A')
            self.assertFalse(branch.repository.has_revision('B'))
        finally:
            bzrlib.gpg.GPGStrategy = oldstrategy
Пример #3
0
    def test_signed_commit(self):
        import bzrlib.gpg
        import bzrlib.commit as commit
        oldstrategy = bzrlib.gpg.GPGStrategy
        wt = self.make_branch_and_tree('.')
        branch = wt.branch
        wt.commit("base", allow_pointless=True, rev_id='A')
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
        try:
            from bzrlib.testament import Testament
            # monkey patch gpg signing mechanism
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
            conf = config.MemoryStack('''
gpg_signing_command=cat -
create_signatures=always
''')
            commit.Commit(config_stack=conf).commit(message="base",
                                                    allow_pointless=True,
                                                    rev_id='B',
                                                    working_tree=wt)

            def sign(text):
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)

            self.assertEqual(
                sign(
                    Testament.from_revision(branch.repository,
                                            'B').as_short_text()),
                branch.repository.get_signature_text('B'))
        finally:
            bzrlib.gpg.GPGStrategy = oldstrategy
    def test_destination_address_required(self):
        msg = Message()
        msg['From'] = '"J. Random Developer" <*****@*****.**>'
        self.assertRaises(
            errors.NoDestinationAddress,
            smtp_connection.SMTPConnection(config.MemoryStack("")).send_email,
            msg)

        msg = email_message.EmailMessage('*****@*****.**', '', 'subject')
        self.assertRaises(
            errors.NoDestinationAddress,
            smtp_connection.SMTPConnection(config.MemoryStack("")).send_email,
            msg)

        msg = email_message.EmailMessage('*****@*****.**', [], 'subject')
        self.assertRaises(
            errors.NoDestinationAddress,
            smtp_connection.SMTPConnection(config.MemoryStack("")).send_email,
            msg)
Пример #5
0
    def test_commit_invokes_hooks(self):
        import bzrlib.commit as commit
        wt = self.make_branch_and_tree('.')
        branch = wt.branch
        calls = []

        def called(branch, rev_id):
            calls.append('called')

        bzrlib.ahook = called
        try:
            conf = config.MemoryStack('post_commit=bzrlib.ahook bzrlib.ahook')
            commit.Commit(config_stack=conf).commit(message="base",
                                                    allow_pointless=True,
                                                    rev_id='A',
                                                    working_tree=wt)
            self.assertEqual(['called', 'called'], calls)
        finally:
            del bzrlib.ahook
 def get_connection(self, text, smtp_factory=None):
     my_config = config.MemoryStack(text)
     return smtp_connection.SMTPConnection(my_config,
                                           _smtp_factory=smtp_factory)
 def test_default(self):
     stack = config.MemoryStack("")
     self.assertEqual(ssl.CERT_REQUIRED, stack.get("ssl.cert_reqs"))
 def get_stack(self, content):
     return config.MemoryStack(content.encode('utf-8'))
Пример #9
0
 def test_set_lp_login(self):
     # Test that set_lp_login() updates the config file.
     my_config = config.MemoryStack('')
     self.assertEqual(None, my_config.get('launchpad_username'))
     account.set_lp_login('test-user', my_config)
     self.assertEqual('test-user', my_config.get('launchpad_username'))
Пример #10
0
 def test_get_lp_login(self):
     # Test that get_lp_login() returns the configured username
     my_config = config.MemoryStack(
         '[DEFAULT]\nlaunchpad_username=test-user\n')
     self.assertEqual('test-user', account.get_lp_login(my_config))
Пример #11
0
 def test_get_lp_login_unconfigured(self):
     # Test that get_lp_login() returns None if no username has
     # been configured.
     my_config = config.MemoryStack('')
     self.assertEqual(None, account.get_lp_login(my_config))