def test_save_bundles_to_db(self):
        """
        Test the method to save a Bundle Manager of an App to the database, using
        the revamped DB.
        :return:
        """

        testBundle = Bundle("all", "ALL", "ALL")
        testBundle._msgs["key.one"] = "One"
        testBundle._msgs["key.two"] = "Two"

        bm = BundleManager()
        bm._bundles = {}
        bm._bundles["all_ALL_ALL"] = testBundle

        save_bundles_to_db(self.tapp, bm)

        # Retrieve the bundles from the DB.
        bundle = db.session.query(appcomposer.models.Bundle).filter_by(app=self.tapp, lang="all_ALL", target="ALL").first()
        assert bundle is not None

        self.assertIsNotNone(bundle)
        self.assertEquals("all_ALL", bundle.lang)
        self.assertEquals("ALL", bundle.target)

        messages = db.session.query(appcomposer.models.Message).filter_by(bundle=bundle).all()
        messages = {m.key: m.value for m in messages}

        self.assertEquals(2, len(messages))
        self.assertEquals("One", messages["key.one"])
        self.assertEquals("Two", messages["key.two"])
    def test_load_appdata_from_db(self):
        """
        Test the method to load the appdata as if it was the old legacy JSON object from the database.
        :return:
        """
        data = {
            "spec": "http://justatest.com",
            "random_setting": 1,
            "bundles": {
                "all_ALL_ALL": {
                    "lang": "all",
                    "country": "ALL",
                    "target": "ALL",
                    "messages" : {
                        "key.one": "One"
                    }
                }
            }
        }
        self.tapp.data = json.dumps(data)
        db.session.add(self.tapp)
        db.session.commit()

        appdata = load_appdata_from_db(self.tapp)

        # The bundles should now be empty, because load_appdata_from_db should not rely on the data's bundles, but
        # on the db information (and for now there is none). The settings should be respected.
        self.assertIsNotNone(appdata)
        self.assertIn("random_setting", appdata)
        self.assertIn("bundles", appdata)
        self.assertTrue(len(appdata["bundles"]) == 0)


        # To further test info retrieval, we need to add info to the db.
        testBundle = Bundle("all", "ALL", "ALL")
        testBundle._msgs["key.three"] = "Three"
        testBundle._msgs["key.four"] = "Four"
        bm = BundleManager()
        bm._bundles = {}
        bm._bundles["all_ALL_ALL"] = testBundle
        save_bundles_to_db(self.tapp, bm)


        appdata = load_appdata_from_db(self.tapp)
        self.assertTrue(appdata["bundles"]["all_ALL_ALL"]["messages"]["key.three"] == "Three")
        self.assertTrue(appdata["bundles"]["all_ALL_ALL"]["messages"]["key.four"] == "Four")