Beispiel #1
0
    def test_archive(self):
        note = Notice("FAILURE", "Duck!")
        archfile = os.path.join(self.tmpdir, "operators.txt")
        self.assertTrue(not os.path.exists(archfile))

        self.archiver.archive("operators", note)
        self.assertTrue(os.path.exists(archfile))
        with open(archfile) as fd:
            lines = fd.readlines()

        self.assertEqual(lines[0], '{\n')
        self.assertEqual(lines[-2], '}\n')
        self.assertEqual(lines[-1], ',\n')
        self.assertGreater(len(lines), 5)
        js = ''.join(lines[0:-1])
        data = json.loads(js)
        self.assertIn('issued', data)
        self.assertEqual(data['type'], "FAILURE")
        self.assertEqual(data['title'], "Duck!")

        self.archiver.archive("operators", note)
        self.assertTrue(os.path.exists(archfile))
        with open(archfile) as fd:
            lines = fd.readlines()
        self.assertEqual(lines[0], '{\n')
        self.assertEqual(lines[-2], '}\n')
        self.assertEqual(lines[-1], ',\n')
        self.assertGreater(len(lines), 10)
Beispiel #2
0
    def test_archive(self):
        note = Notice("info", "Whoa!")

        archfile = os.path.join(self.arcdir, "goob.txt")
        self.assertTrue(not os.path.exists(archfile))
        self.svc.archive(note, "goob")
        self.assertTrue(os.path.exists(archfile))
Beispiel #3
0
    def test_send_notice(self):
        note = Notice.from_json(notice_data)
        self.target.send_notice(note)

        with open(os.path.join(self.mailer.cache, "notice.txt")) as fd:
            msg = fd.read().split("\n")

        self.assertEqual(
            msg[0],
            "To [email protected] [email protected] [email protected] [email protected]"
        )
        self.assertEqual(msg[1], "From [email protected]")
        # self.assertTrue(msg[2].startswith("From [email protected] "))
        self.assertIn('From: "PDR Notification System" <*****@*****.**>',
                      msg)
        self.assertIn(
            'To: "OAR PDR Operators: Raymond Plante" <*****@*****.**>,',
            msg)
        self.assertIn(' "Gretchen Greene" <*****@*****.**>', msg)
        self.assertIn('Cc: "Sys admin" <*****@*****.**>', msg)
        self.assertIn(
            'Subject: PDR Notice: FAILURE: data is devoid of science', msg)
        self.assertIn(
            'The data is dull and uninteresting.  Pure noise is less tedious than this data.',
            msg)
Beispiel #4
0
    def test_send_notice(self):
        note = Notice("FAILURE", "Duck!")
        archfile = os.path.join(self.tmpdir, "operators.txt")
        self.assertTrue(not os.path.exists(archfile))
        archfile = os.path.join(self.tmpdir, "goober.txt")
        self.assertTrue(not os.path.exists(archfile))

        self.target.send_notice(note)
        self.assertTrue(os.path.exists(archfile))
        with open(archfile) as fd:
            lines = fd.readlines()

        self.assertEqual(lines[0], '{\n')
        self.assertEqual(lines[-2], '}\n')
        self.assertEqual(lines[-1], ',\n')
        self.assertGreater(len(lines), 5)

        archfile = os.path.join(self.tmpdir, "operators.txt")
        self.target.send_notice(note, "operators")
        self.assertTrue(os.path.exists(archfile))
        with open(archfile) as fd:
            lines = fd.readlines()

        self.assertEqual(lines[0], '{\n')
        self.assertEqual(lines[-2], '}\n')
        self.assertEqual(lines[-1], ',\n')
        self.assertGreater(len(lines), 5)
Beispiel #5
0
    def test_StdoutMailer(self):

        note = Notice("INFO", "hello!")
        out = MyStringIO()
        chan = cli.StdoutMailer({"name": "archiver", "pretty": False}, out)
        chan.send_email("*****@*****.**", ["*****@*****.**", "*****@*****.**"])

        self.assertGreater(len(out.getvalue()), 10)
Beispiel #6
0
    def test_StdoutArchiver(self):

        note = Notice("INFO", "hello!")
        out = MyStringIO()
        chan = cli.StdoutArchiver({"name": "archiver", "pretty": False}, out)
        chan.archive("hank", note)

        self.assertGreater(len(out.getvalue()), 10)
Beispiel #7
0
    def test_format_body_no_format(self):
        d = notice_data
        note = Notice(d['type'], d['title'], d['description'], d['origin'],
                      d['issued'], formatted=True, platform="unittest")
        body = self.target.format_body(note).split("\n")
        self.assertEqual(body[0], "Attention: OAR PDR Operators")
        self.assertEqual(body[1], "Notification Type: FAILURE")
        self.assertEqual(body[2], "Origin: Preservation")
        self.assertEqual(body[4], "data is devoid of science")
        self.assertEqual(body[6], "The data is dull and uninteresting.  Pure noise is less tedious than this data.  It reads like 'Smoke on the Water' but without the changing notes.")
        self.assertEqual(body[8], "This data should not be saved")

        self.assertTrue(body[10].startswith("Issued: "))
        self.assertEqual(body[11], "platform: unittest")
Beispiel #8
0
    def test_format_body(self):
        note = Notice.from_json(notice_data)
        body = self.target.format_body(note).split("\n")
        self.assertEqual(body[0], "Attention: OAR PDR Operators")
        self.assertEqual(body[1], "Notification Type: FAILURE")
        self.assertEqual(body[2], "Origin: Preservation")
        self.assertEqual(body[4], "data is devoid of science")
        self.assertEqual(body[6], "The data is dull and uninteresting.  Pure noise is less tedious than this data.")
        self.assertEqual(body[7], "It reads like 'Smoke on the Water' but without the changing notes.")
        self.assertEqual(body[9], "This data should not be saved")

        self.assertTrue(body[11].startswith("Issued: "))
        self.assertEqual(body[12], "color: grey")
        self.assertEqual(body[13], "platform: unittest")
        self.assertEqual(body[14], "excitation: False")
Beispiel #9
0
 def test_format_subject(self):
     note = Notice("FAILURE", "Duck!")
     self.assertEqual(self.target.format_subject(note),
                      "PDR Notice: FAILURE: Duck!")