Rev 61: Add tests for BranchConfigSubmitBundle. in file:///home/jelmer/bzr-submit/trunk/

Jelmer Vernooij jelmer at samba.org
Sat Apr 7 22:30:39 BST 2007


At file:///home/jelmer/bzr-submit/trunk/

------------------------------------------------------------
revno: 61
revision-id: jelmer at samba.org-20070407213035-t8bhc7o6upbvg4jq
parent: jelmer at samba.org-20070407204219-j7xvun90ui91wvnz
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sat 2007-04-07 23:30:35 +0200
message:
  Add tests for BranchConfigSubmitBundle.
modified:
  submit_helpers.py              submit_helpers.py-20060624164558-9aabyghnw7kxeuwg-2
  test_submit_bundle.py          test_submit_bundle.p-20070128205938-j61ty7zc1fxv9dba-1
=== modified file 'submit_helpers.py'
--- a/submit_helpers.py	2007-03-23 20:11:14 +0000
+++ b/submit_helpers.py	2007-04-07 21:30:35 +0000
@@ -119,11 +119,11 @@
         
         multipart = True
         pqm = False
-        if mail_to[:8] == "mailbot:":
+        if mail_to.startswith("mailbot:"):
             pqm = True
             multipart = False
             mail_to = mail_to[8:]
-        elif mail_to[:7] == "mailto:":
+        elif mail_to.startswith("mailto:"):
             mail_to = mail_to[7:]
         return (mail_to, multipart, pqm)
 

=== modified file 'test_submit_bundle.py'
--- a/test_submit_bundle.py	2007-04-07 20:42:19 +0000
+++ b/test_submit_bundle.py	2007-04-07 21:30:35 +0000
@@ -15,19 +15,108 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Test cases for pqm submit."""
 
+from bzrlib.errors import BzrCommandError
 from bzrlib.tests import TestCase
+from bzrlib.tests.test_config import FakeBranch
+
 from bzrlib.plugins.submit import parse_submit_options
+from bzrlib.plugins.submit.submit_helpers import BranchConfigSubmitBundle
 
 class TestParseSubmitOptions(TestCase):
     def test_simple(self):
+        """Make sure a single option can be parsed correctly."""
         self.assertEquals([("bla", "bloe")], 
                 list(parse_submit_options("bla=bloe\n")))
 
     def test_with_comment(self):
+        """Make sure comments are ignored."""
         self.assertEquals([("bla", "bloe")], 
                 list(parse_submit_options("#comment\nbla=bloe\n")))
 
     def test_multiple(self):
+        """Test that multiple options can be parsed."""
         self.assertEquals([("bla", "bloe"), ("var1", "val1"), ("var2", "val2")], 
             list(parse_submit_options("bla=bloe\nvar1=val1\nvar2=val2\n")))
 
+ 
+class TestConfig(TestCase):
+    def setUp(self):
+        self.config = BranchConfigSubmitBundle(FakeBranch())
+
+    def test_get_submit_address(self):
+        """Check whether the default submit address can be obtained."""
+        self.config.set_user_option('submit-address', 'foo at bar.nl')
+        self.assertEquals("foo at bar.nl", self.config.get_submit_address())
+
+    def test_get_submit_address_default(self):
+        """Check whether None is returned if no address is set."""
+        self.assertIs(None, self.config.get_submit_address())
+
+    def test_set_submit_address(self):
+        """Check whether the default submit address can be obtained."""
+        self.config.set_submit_address('some-address at example.com')
+        self.assertEquals("some-address at example.com", self.config.get_user_option("submit-address"))
+
+    def test_get_smtp_server(self):
+        """Check whether the SMTP server can be obtained from the config file."""
+        self.config.set_user_option("smtp_server", "smtp.example.com")
+        self.assertEquals("smtp.example.com", self.config.get_smtp_server())
+
+    def test_get_smtp_server_default(self):
+        """Make sure that get_smtp_server() defaults to localhost."""
+        self.assertEquals("localhost", self.config.get_smtp_server())
+
+    def test_get_smtp_user(self):
+        """Make sure that the SMTP user can be obtain from the config."""
+        self.config.set_user_option("smtp_user", "somebody")
+        self.assertEquals("somebody", self.config.get_smtp_user())
+
+    def test_get_smtp_user_default(self):
+        """Make sure that get_smtp_user() defaults to None."""
+        self.assertIs(None, self.config.get_smtp_user())
+
+    def test_get_smtp_password(self):
+        """Make sure the smtp password can be obtained correctly."""
+        self.config.set_user_option("smtp_password", "geheim")
+        self.assertEquals("geheim", self.config.get_smtp_password())
+
+    def test_get_smtp_password_default(self):
+        """Make sure the default smtp password is None."""
+        self.assertIs(None, self.config.get_smtp_password())
+
+    def test_get_mailto_no_address(self):
+        """Make sure a BzrCommandError is raised if there is no address set."""
+        self.assertRaises(BzrCommandError, 
+                lambda: self.config.get_mailto(None, None, False, False))
+
+    def test_get_mailto_remember(self):
+        """Make sure remember works."""
+        self.assertEquals(("foo at example.com", True, False),
+            self.config.get_mailto("foo at example.com", "default", True, False))
+        self.assertEquals("foo at example.com", self.config.get_submit_address("default"))
+
+    def test_get_mailto_noremember(self):
+        """Make sure remember=False doesn't store anything."""
+        self.assertEquals(("foo at example.com", True, False),
+            self.config.get_mailto("foo at example.com", "default", False, False))
+        self.assertIs(None, self.config.get_submit_address("default"))
+
+    def test_get_mailto_nopredefined(self):
+        """Make sure get_mailto() without predefined address uses 
+        get_submit_address."""
+        self.config.set_user_option("submit-address", "bar at example.com")
+        self.assertEquals(("bar at example.com", True, False),
+            self.config.get_mailto(None, "default", False, False))
+
+    def test_get_mailto_nopredefined(self):
+        """Make sure get_mailto() strips mailto: prefixes."""
+        self.assertEquals(("bar at example.com", True, False),
+            self.config.get_mailto("mailto:bar at example.com", "default", False, 
+                False))
+
+    def test_get_mailto_mailbot(self):
+        """Make sure get_mailto() strips mailbot: prefixes and 
+        returns the pqm setting correctly. """
+        self.assertEquals(("bar at example.com", False, True),
+            self.config.get_mailto("mailbot:bar at example.com", "default", False, 
+                False))




More information about the bazaar-commits mailing list