Beispiel #1
0
    def _save_attachments(self, db):
        self.log_info("Saving attachments")

        with os.scandir(self.dir_attach_incoming) as iterator:
            for entry in iterator:
                self.log_info("Processing attachment “%s”" % entry.name)

                try:
                    with open(entry.path, "r") as fil:
                        attachment = json.load(fil)
                except (OSError, ValueError) as ex:
                    self.log_warn("Failed to load attachment: {0}".format(
                        str(ex)))
                    self._move_attachment_to_deferred(entry.name)
                    continue

                try:
                    validate_attachment(attachment)
                except FafError as ex:
                    self.log_warn("Attachment is invalid: {0}".format(str(ex)))
                    self._move_attachment_to_deferred(entry.name)
                    continue

                try:
                    save_attachment(db, attachment)
                except FafError as ex:
                    self.log_warn("Failed to save attachment: {0}".format(
                        str(ex)))
                    self._move_attachment_to_deferred(entry.name)
                    continue

                self._move_attachment_to_saved(entry.name)
Beispiel #2
0
    def test_comment_saving(self):
        """
        Check if comment attachment is added to report.
        """

        save(self.db, self.sample_reports['ureport2'])
        report = self.db.session.query(Report).first()

        # update hash locally
        reporthash = report.hashes[0].hash
        com_attachment = self.comment_attachment
        com_attachment["bthash"] = reporthash

        save_attachment(self.db, com_attachment)
        self.assertEqual(len(report.comments), 1)
Beispiel #3
0
    def test_url_saving(self):
        """
        Check if URL attachment is added to report.
        """

        save(self.db, self.sample_reports['ureport2'])
        report = self.db.session.query(Report).first()

        # update hash locally
        reporthash = report.hashes[0].hash
        url_attachment = self.url_attachment
        url_attachment["bthash"] = reporthash

        save_attachment(self.db, url_attachment)
        self.assertEqual(len(report.urls), 1)
        self.assertEqual(report.urls[0].url, 'http://example.org')
        self.assertIsNotNone(report.urls[0].saved)
Beispiel #4
0
    def test_contact_email_saving(self):
        """
        Check if comment attachment is added to report.
        """

        save(self.db, self.sample_reports['ureport2'])
        report = self.db.session.query(Report).first()

        # update hash locally
        reporthash = report.hashes[0].hash
        contact_email_attachment = self.contact_email_attachment
        contact_email_attachment["bthash"] = reporthash

        save_attachment(self.db, contact_email_attachment)
        self.assertEqual(len(report.report_contact_emails), 1)
        self.assertEqual(len(self.db.session.query(ContactEmail).all()), 1)
        self.assertEqual(report.report_contact_emails[0].contact_email.email_address,
                         contact_email_attachment["data"])

        # saving it twice should have no effect
        save_attachment(self.db, contact_email_attachment)
        self.assertEqual(len(report.report_contact_emails), 1)
        self.assertEqual(len(self.db.session.query(ContactEmail).all()), 1)
Beispiel #5
0
    def _save_attachments(self, db):
        self.log_info("Saving attachments")

        attachment_filenames = os.listdir(self.dir_attach_incoming)

        i = 0
        for fname in sorted(attachment_filenames):
            i += 1

            filename = os.path.join(self.dir_attach_incoming, fname)
            self.log_info("[{0} / {1}] Processing file '{2}'"
                          .format(i, len(attachment_filenames), filename))

            try:
                with open(filename, "r") as fil:
                    attachment = json.load(fil)
            except (OSError, ValueError) as ex:
                self.log_warn("Failed to load attachment: {0}".format(str(ex)))
                self._move_attachment_to_deferred(fname)
                continue

            try:
                validate_attachment(attachment)
            except FafError as ex:
                self.log_warn("Attachment is invalid: {0}".format(str(ex)))
                self._move_attachment_to_deferred(fname)
                continue

            try:
                save_attachment(db, attachment)
            except FafError as ex:
                self.log_warn("Failed to save attachment: {0}".format(str(ex)))
                self._move_attachment_to_deferred(fname)
                continue

            self._move_attachment_to_saved(fname)
Beispiel #6
0
    def _save_attachments(self, db):
        self.log_info("Saving attachments")

        attachment_filenames = os.listdir(self.dir_attach_incoming)

        i = 0
        for fname in sorted(attachment_filenames):
            i += 1

            filename = os.path.join(self.dir_attach_incoming, fname)
            self.log_info("[{0} / {1}] Processing file '{2}'"
                          .format(i, len(attachment_filenames), filename))

            try:
                with open(filename, "r") as fil:
                    attachment = json.load(fil)
            except (OSError, ValueError) as ex:
                self.log_warn("Failed to load attachment: {0}".format(str(ex)))
                self._move_attachment_to_deferred(fname)
                continue

            try:
                validate_attachment(attachment)
            except FafError as ex:
                self.log_warn("Attachment is invalid: {0}".format(str(ex)))
                self._move_attachment_to_deferred(fname)
                continue

            try:
                save_attachment(db, attachment)
            except FafError as ex:
                self.log_warn("Failed to save attachment: {0}".format(str(ex)))
                self._move_attachment_to_deferred(fname)
                continue

            self._move_attachment_to_saved(fname)
Beispiel #7
0
    def test_attachment_saving(self):
        """
        Check if bugzilla attachment is added to report.
        """

        save(self.db, self.sample_reports['ureport2'])
        report = self.db.session.query(Report).first()

        # update hash locally
        reporthash = report.hashes[0].hash
        bz_attachment = self.bugzilla_attachment
        bz_attachment["bthash"] = reporthash

        class MockBugtracker(object):
            def download_bug_to_storage(db, bug_id):
                return self.bug

        old_fedora_bt = bugtrackers["fedora-bugzilla"]
        bugtrackers["fedora-bugzilla"] = MockBugtracker()

        save_attachment(self.db, bz_attachment)
        self.assertEqual(len(report.bz_bugs), 1)

        bugtrackers["fedora-bugzilla"] = old_fedora_bt