def test_check_certificate_error_loading(self, mock_load):
        mock_load.side_effect = Exception('some error')

        self.user.auth.cert = 'some cert'

        before = datetime.datetime.now()

        after = datetime.datetime.now()

        mock_load.return_value.get_notBefore.return_value = before.strftime(
            tasks.CERT_DATE_FMT)

        mock_load.return_value.get_notAfter.return_value = after.strftime(
            tasks.CERT_DATE_FMT)

        with self.assertRaises(tasks.CertificateError):
            tasks.check_certificate(self.user)
    def test_check_certificate(self, mock_load):
        self.user.auth.cert = 'some cert'

        before = datetime.datetime.now() - datetime.timedelta(days=10)

        after = datetime.datetime.now() + datetime.timedelta(days=10)

        mock_load.return_value.get_notBefore.return_value = before.strftime(
            tasks.CERT_DATE_FMT)

        mock_load.return_value.get_notAfter.return_value = after.strftime(
            tasks.CERT_DATE_FMT)

        self.assertTrue(tasks.check_certificate(self.user))
 def test_check_certificate_missing_certificate(self):
     with self.assertRaises(tasks.CertificateError):
         tasks.check_certificate(self.user)