Beispiel #1
0
    def test_replace_metadata(self):
        old_zip_file = get_test_zipfile('LotsOfFiles')

        metadata = models.parse_zipfile_metadata(old_zip_file)
        old_zip_file.seek(0)

        extension = models.Extension.objects.create_from_metadata(
            metadata, creator=self.user)
        version = models.ExtensionVersion(extension=extension,
                                          source=File(old_zip_file))

        version.parse_metadata_json(metadata)

        new_zip = version.get_zipfile('r')

        old_zip = ZipFile(File(old_zip_file), 'r')
        self.assertEqual(len(old_zip.infolist()), len(new_zip.infolist()))
        self.assertEqual(new_zip.read("metadata.json"),
                         version.make_metadata_json_string())

        for old_info in old_zip.infolist():
            if old_info.filename == "metadata.json":
                continue

            new_info = new_zip.getinfo(old_info.filename)
            self.assertEqual(old_zip.read(old_info), new_zip.read(new_info))
            self.assertEqual(old_info.date_time, new_info.date_time)

        old_zip.close()
        new_zip.close()
Beispiel #2
0
    def test_simple_zipdata_data(self):
        with get_test_zipfile('SimpleExtension') as f:
            metadata = models.parse_zipfile_metadata(f)

        extension = models.Extension.objects.create_from_metadata(
            metadata, creator=self.user)
        version = models.ExtensionVersion(extension=extension)
        version.parse_metadata_json(metadata)

        self.assertEqual(extension.uuid, "*****@*****.**")
        self.assertEqual(extension.name, "Test Extension")
        self.assertEqual(extension.description, "Simple test metadata")
        self.assertEqual(extension.url, "http://test-metadata.gnome.org")
Beispiel #3
0
    def test_extra_metadata(self):
        with get_test_zipfile('ExtraMetadata') as f:
            metadata = models.parse_zipfile_metadata(f)

        extension = models.Extension.objects.create_from_metadata(
            metadata, creator=self.user)
        version = models.ExtensionVersion(extension=extension)
        version.parse_metadata_json(metadata)

        extra = json.loads(version.extra_json_fields)
        self.assertEqual(extension.uuid, "*****@*****.**")
        self.assertEqual(extra["extra"], "This is some good data")
        self.assertTrue("description" not in extra)
        self.assertTrue("url" not in extra)
Beispiel #4
0
    def test_simple_metadata(self):
        metadata = {
            "uuid": "*****@*****.**",
            "name": "Test Metadata",
            "description": "Simple test metadata",
            "url": "http://test-metadata.gnome.org"
        }

        extension = models.Extension.objects.create_from_metadata(
            metadata, creator=self.user)
        version = models.ExtensionVersion(extension=extension)
        version.parse_metadata_json(metadata)

        self.assertEqual(extension.name, "Test Metadata")
        self.assertEqual(extension.description, "Simple test metadata")
        self.assertEqual(extension.url, "http://test-metadata.gnome.org")