Esempio n. 1
0
 def test_multiple_notifiers(self):
     p = self.project
     self.assertFalse(p.has_notifier)
     
     # create mail notifier
     mn = MailNotifier(project=p, name="notify by email")
     mn.save()
     self.assertEqual(1, p.notifier_set.count())
     self.assertEqual(unicode(mn), "notify by email")
     self.assertTrue(p.has_notifier)
     
     # create web notifier
     wn = WebNotifier(project=p, name="waterfall page")
     wn.save()
     self.assertEqual(2, p.notifier_set.count())
     self.assertEqual(unicode(wn), "waterfall page")
     
     # check that models can downcast properly
     expect = [_("mail notifier"), _("web notifier")]
     for i,n in enumerate(p.notifier_set.all()):
         # calling method on parent class should raise exception
         self.assertRaises(NotImplementedError, n.get_config_type)
         self.assertRaises(NotImplementedError, n.get_config_class)
         self.assertRaises(NotImplementedError, n.get_config_args)
         # should work with .cast()
         self.assertEqual(expect[i], n.cast().get_config_type())
Esempio n. 2
0
 def test_name_uniqueness(self):
     """
     Ensure that a project cannot have multiple notifiers with the same name
     """
     p = self.project
     n = MailNotifier(project=p, name="notifier1")
     n.save()
     
     n2 = WebNotifier(project=p, name="notifier1")
     self.assertRaises(IntegrityError, n2.save)
     self.assertEqual(n2.id, None)
     
     # the same name can be used in a different project
     p2 = Project(name="another p", owner=self.user)
     p2.save()
     n2.project = p2
     n2.save()
     self.assertNotEqual(n2.id, None)
     
         
     
     
     
 def test_simple_creation(self):
     """
     Basic Mail Notifier creation
     """
     mn = MailNotifier(project=self.project, name="mail me")
     mn.save()
     self.assertNotEqual(mn.id, None)
     self.assertEqual(unicode(mn), "mail me")
     self.assertEqual(mn.cast().get_config_type(), _("mail notifier"))
     self.assertNotEqual(len(mn.cast().get_mode_str()), 0)
     
     admin = BuildAdmin(
         project = self.project,
         name = "admin",
         email = "*****@*****.**",
         receive_build_events = True,
     )
     admin.save()
     
     args = mn.cast().get_config_args() 
     # check default arguments
     self.assertEqual(args.get("fromaddr", None), settings.DEFAULT_MAIL_FROM_ADDR)
     self.assertEqual(args.get("relayhost", None), settings.DEFAULT_MAIL_SMTP_HOST)
     self.assertEqual(args.get("smtpPort", None), settings.DEFAULT_MAIL_SMTP_PORT)
     self.assertEqual(args.get("lookup", None), settings.DEFAULT_MAIL_RCPT_DOMAIN)
     self.assertEqual(args.get("mode", None), "problem")
     self.assertEqual(args.get("useTls", None), False) 
     self.assertEqual(args.get("sendToInterestedUsers", None), True) 
     er = args.get("extraRecipients", None)
     self.assertEqual(type(er), list)
     self.assertEqual(len(er), 1)
     self.assertEqual(er[0], "*****@*****.**")
     
     # check that the config object can be instantiated
     self.assert_valid_buildbot_config(mn.cast().get_config_class(), args)
     
     # Check that the resulting config string is sensible
     self.assert_config_string_executable(mn.cast())
 def test_with_more_options(self):
     """
     Filling in optional args during object creation
     """
     mn = MailNotifier(project=self.project, name="mail me 2",
         mode = "all",
         from_address = "*****@*****.**",
         rcpt_domain = "svndomain.com",
         smtp_host = "smtp.mydomain.com",
         smtp_port = 52,
         smtp_use_tls = True,
         smtp_username = "******",
         smtp_password = "******",
     )
     mn.save()
     
     # check additional args
     args = mn.cast().get_config_args()
     self.assertEqual(args.get("fromaddr", None), "*****@*****.**")
     self.assertEqual(args.get("relayhost", None), "smtp.mydomain.com")
     self.assertEqual(args.get("smtpPort", None), 52)
     self.assertEqual(args.get("lookup", None), "svndomain.com")
     self.assertEqual(args.get("mode", None), "all")
     self.assertEqual(args.get("smtpUser", None), "smtpuser")
     self.assertEqual(args.get("smtpPassword", None), "sekrit")
     self.assertEqual(args.get("sendToInterestedUsers", None), True) 
     self.assertEqual(mn.cast().get_mode_str(), unicode(_("(all) build completes, pass or fail.")))
     
     # check that the config object can be instantiated
     self.assert_valid_buildbot_config(mn.cast().get_config_class(), args)
     
     # Check that the resulting config string is sensible
     self.assert_config_string_executable(mn.cast())