Example #1
0
class WarnExpireTestCase(MyBaseTest):

    def setUp(self):
        MyBaseTest.setUp(self)
        self.cmd = WarnExpireCommand()

    @patch("fwadmin.management.commands.warnexpire.send_renew_mail")
    def test_no_send_renew_mail_when_still_active(self, mock_f):
        """Ensure we do not send mails if there is enough delta"""
        today = datetime.date.today()
        delta = self.host.active_until - today
        self.assertEqual(delta, datetime.timedelta(days=360))
        self.cmd.handle()
        self.assertEqual(mock_f.mock_calls, [])

    @patch("fwadmin.management.commands.warnexpire.send_renew_mail")
    def test_send_renew_mail_from_cmd(self, mock_f):
        """Ensure we do send mails"""
        tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        self.host.active_until = tomorrow
        self.host.save()
        self.cmd.handle()
        mock_f.assert_called_with(self.host)

    @patch("fwadmin.management.commands.warnexpire.send_mail")
    def test_send_renew_mail(self, mock_f):
        """Ensure we do send mails"""
        tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        self.host.active_until = tomorrow
        self.host.save()
        send_renew_mail(self.host)
        subject = u"Firewall config for 'test'"
        body = u"""Dear user1,

The firewall config for machine: 'test' (192.168.1.1) will expire at
'%s'.

Please click on https://fwadmin.uni-trier.de%s to renew.
""" % (self.host.active_until,
           reverse("fwadmin:edit_host", args=(self.host.id,)))
        mock_f.assert_called_with(
            subject, body, FWADMIN_EMAIL_FROM,
            [self.host.owner.email])
Example #2
0
class WarnExpireTestCase(MyBaseTest):
    def setUp(self):
        MyBaseTest.setUp(self)
        self.cmd = WarnExpireCommand()

    @patch("fwadmin.management.commands.warnexpire.send_renew_mail")
    def test_no_send_renew_mail_when_still_active(self, mock_f):
        """Ensure we do not send mails if there is enough delta"""
        today = datetime.date.today()
        delta = self.host.active_until - today
        self.assertEqual(delta, datetime.timedelta(days=360))
        self.cmd.handle()
        self.assertEqual(mock_f.mock_calls, [])

    @patch("fwadmin.management.commands.warnexpire.send_renew_mail")
    def test_send_renew_mail_from_cmd(self, mock_f):
        """Ensure we do send mails"""
        tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        self.host.active_until = tomorrow
        self.host.save()
        self.cmd.handle()
        mock_f.assert_called_with(self.host)

    @patch("fwadmin.management.commands.warnexpire.send_mail")
    def test_send_renew_mail(self, mock_f):
        """Ensure we do send mails"""
        tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        self.host.active_until = tomorrow
        self.host.save()
        send_renew_mail(self.host)
        subject = u"Firewall config for 'test'"
        body = u"""Dear user1,

The firewall config for machine: 'test' (192.168.1.1) will expire at
'%s'.

Please click on https://fwadmin.uni-trier.de%s to renew.
""" % (self.host.active_until,
        reverse("fwadmin:edit_host", args=(self.host.id, )))
        mock_f.assert_called_with(subject, body, FWADMIN_EMAIL_FROM,
                                  [self.host.owner.email])
Example #3
0
 def setUp(self):
     MyBaseTest.setUp(self)
     self.cmd = WarnExpireCommand()
Example #4
0
 def setUp(self):
     MyBaseTest.setUp(self)
     self.cmd = WarnExpireCommand()