def test_translate_highlevel_save_bundle_modifs_only(self):
        """
        Ensures that a Bundle is saved successfully to the DB when all the messages are there already.
        :return:
        """
        # Create some bundles to attach.
        b = models.Bundle("all_ALL", "ALL")
        b.app = self.tapp
        m1 = models.Message("message1", "First Message")
        m2 = models.Message("message2", "Second Message")
        b.messages.append(m1)
        b.messages.append(m2)
        db.session.add(b)
        db.session.commit()

        bundle = ops_highlevel.load_bundle(self.tapp, "all_ALL", "ALL")
        bundle.add_msg("message1", "First Message Modified")
        bundle.add_msg("message2", "Second Message Modified")

        ops_highlevel.save_bundle(self.tapp, bundle)

        # Check that it was saved properly.
        m1 = db.session.query(models.Message).filter_by(bundle=b, key="message1").first()
        self.assertEquals("First Message Modified", m1.value)
        m2 = db.session.query(models.Message).filter_by(bundle=b, key="message2").first()
        self.assertEquals("Second Message Modified", m2.value)

        msgs = db.session.query(models.Message).filter_by(bundle=b).all()
        self.assertEquals(2, len(msgs))
    def test_translate_highlevel_load_bundle(self):
        """
        Ensures that if the bundle does exist it is retrieved successfully.
        :return:
        """

        # Create some bundles to attach.
        b = models.Bundle("all_ALL", "ALL")
        b.app = self.tapp
        m1 = models.Message("message1", "First Message")
        m2 = models.Message("message2", "Second Message")
        b.messages.append(m1)
        b.messages.append(m2)
        db.session.add(b)
        db.session.commit()

        bundle = ops_highlevel.load_bundle(self.tapp, "all_ALL", "ALL")

        self.assertIs(type(bundle), bundles.Bundle)
        self.assertEquals(2, len(bundle.get_msgs()))
        self.assertEquals(bundle.get_msg("message1"), "First Message")
        self.assertEquals(bundle.get_msg("message2"), "Second Message")