예제 #1
0
    def test_install_webapps(self):
        """Test installing webapps into a profile that has no prior webapps"""
        webapps = WebappCollection(self.profile, apps=self.manifest_path_1)
        self.assertFalse(os.path.exists(self.webapps_dir))

        # update the webapp manifests for the first time
        webapps.update_manifests()
        self.assertFalse(
            os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))
        self.assertTrue(os.path.isfile(self.webapps_json_path))

        webapps_json = webapps.read_json(self.webapps_json_path,
                                         description="fake description")
        self.assertEqual(len(webapps_json), 7)
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)

        manifest_json_1 = webapps.read_json(self.manifest_path_1)
        manifest_json_2 = webapps.read_json(self.manifest_path_2)
        self.assertEqual(len(webapps_json), len(manifest_json_1))
        for app in webapps_json:
            self.assertTrue(app in manifest_json_1)

        # Remove one of the webapps from WebappCollection after it got installed
        removed_app = manifest_json_1[2]
        webapps.remove(removed_app)
        # Add new webapps to the collection
        webapps.extend(manifest_json_2)

        # update the webapp manifests a second time
        webapps.update_manifests()
        self.assertFalse(
            os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))
        self.assertTrue(os.path.isfile(self.webapps_json_path))

        webapps_json = webapps.read_json(self.webapps_json_path,
                                         description="a description")
        self.assertEqual(len(webapps_json), 11)

        # The new apps should be added
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)
            self.assertTrue(
                os.path.isfile(
                    os.path.join(self.webapps_dir, app['name'],
                                 'manifest.webapp')))
        # The removed app should not exist in the manifest
        self.assertNotIn(removed_app, webapps_json)
        self.assertFalse(
            os.path.exists(os.path.join(self.webapps_dir,
                                        removed_app['name'])))

        # Cleaning should delete the webapps directory entirely
        # since there was nothing there before
        webapps.clean()
        self.assertFalse(os.path.isdir(self.webapps_dir))
예제 #2
0
    def test_install_webapps(self):
        """Test installing webapps into a profile that has no prior webapps"""
        webapps = WebappCollection(self.profile, apps=self.manifest_path_1)
        self.assertFalse(os.path.exists(self.webapps_dir))

        # update the webapp manifests for the first time
        webapps.update_manifests()
        self.assertFalse(os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))
        self.assertTrue(os.path.isfile(self.webapps_json_path))

        webapps_json = webapps.read_json(self.webapps_json_path, description="fake description")
        self.assertEqual(len(webapps_json), 7)
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)

        manifest_json_1 = webapps.read_json(self.manifest_path_1)
        manifest_json_2 = webapps.read_json(self.manifest_path_2)
        self.assertEqual(len(webapps_json), len(manifest_json_1))
        for app in webapps_json:
            self.assertTrue(app in manifest_json_1)

        # Remove one of the webapps from WebappCollection after it got installed
        removed_app = manifest_json_1[2]
        webapps.remove(removed_app)
        # Add new webapps to the collection
        webapps.extend(manifest_json_2)

        # update the webapp manifests a second time
        webapps.update_manifests()
        self.assertFalse(os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))
        self.assertTrue(os.path.isfile(self.webapps_json_path))

        webapps_json = webapps.read_json(self.webapps_json_path, description="a description")
        self.assertEqual(len(webapps_json), 11)

        # The new apps should be added
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)
            self.assertTrue(os.path.isfile(os.path.join(self.webapps_dir, app['name'],
                                                        'manifest.webapp')))
        # The removed app should not exist in the manifest
        self.assertNotIn(removed_app, webapps_json)
        self.assertFalse(os.path.exists(os.path.join(self.webapps_dir, removed_app['name'])))

        # Cleaning should delete the webapps directory entirely
        # since there was nothing there before
        webapps.clean()
        self.assertFalse(os.path.isdir(self.webapps_dir))
예제 #3
0
    def test_install_webapps_preexisting(self):
        """Tests installing webapps when the webapps directory already exists"""
        manifest_json_2 = WebappCollection.read_json(self.manifest_path_2)

        # Synthesize a pre-existing webapps directory
        os.mkdir(self.webapps_dir)
        shutil.copyfile(self.manifest_path_2, self.webapps_json_path)
        for app in manifest_json_2:
            app_path = os.path.join(self.webapps_dir, app['name'])
            os.mkdir(app_path)
            f = open(os.path.join(app_path, 'manifest.webapp'), 'w')
            f.close()

        webapps = WebappCollection(self.profile, apps=self.manifest_path_1)
        self.assertTrue(os.path.exists(self.webapps_dir))

        # update webapp manifests for the first time
        webapps.update_manifests()
        # A backup should be created
        self.assertTrue(
            os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))

        # Both manifests should remain installed
        webapps_json = webapps.read_json(self.webapps_json_path,
                                         description='a fake description')
        self.assertEqual(len(webapps_json), 12)
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)
            self.assertTrue(
                os.path.isfile(
                    os.path.join(self.webapps_dir, app['name'],
                                 'manifest.webapp')))

        # Upon cleaning the backup should be restored
        webapps.clean()
        self.assertFalse(
            os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))

        # The original webapps should still be installed
        webapps_json = webapps.read_json(self.webapps_json_path)
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)
            self.assertTrue(
                os.path.isfile(
                    os.path.join(self.webapps_dir, app['name'],
                                 'manifest.webapp')))
        self.assertEqual(webapps_json, manifest_json_2)
예제 #4
0
    def test_install_webapps_preexisting(self):
        """Tests installing webapps when the webapps directory already exists"""
        manifest_json_2 = WebappCollection.read_json(self.manifest_path_2)

        # Synthesize a pre-existing webapps directory
        os.mkdir(self.webapps_dir)
        shutil.copyfile(self.manifest_path_2, self.webapps_json_path)
        for app in manifest_json_2:
            app_path = os.path.join(self.webapps_dir, app['name'])
            os.mkdir(app_path)
            f = open(os.path.join(app_path, 'manifest.webapp'), 'w')
            f.close()

        webapps = WebappCollection(self.profile, apps=self.manifest_path_1)
        self.assertTrue(os.path.exists(self.webapps_dir))

        # update webapp manifests for the first time
        webapps.update_manifests()
        # A backup should be created
        self.assertTrue(os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))

        # Both manifests should remain installed
        webapps_json = webapps.read_json(self.webapps_json_path, description='a fake description')
        self.assertEqual(len(webapps_json), 12)
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)
            self.assertTrue(os.path.isfile(os.path.join(self.webapps_dir, app['name'],
                                                        'manifest.webapp')))

        # Upon cleaning the backup should be restored
        webapps.clean()
        self.assertFalse(os.path.isdir(os.path.join(self.profile, webapps.backup_dir)))

        # The original webapps should still be installed
        webapps_json = webapps.read_json(self.webapps_json_path)
        for app in webapps_json:
            self.assertIsInstance(app, Webapp)
            self.assertTrue(os.path.isfile(os.path.join(self.webapps_dir, app['name'],
                                                        'manifest.webapp')))
        self.assertEqual(webapps_json, manifest_json_2)