Exemplo n.º 1
0
    def test_folder_removed_when_modules_added(self):
        " EmptyDir's shouldn't exist if there are modules inside the 'dir' "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        folder = EmptyDir(name=self.path, author=self.author, root_dir='l')
        folder.save()
        revision.folder_add(folder)
        self.assertEqual(1, revision.folders.count())

        mod = Module(
            filename='/'.join([self.path, 'helpers']),
            author=self.author,
            code='//test code'
        )
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())

        mod = Module(
            filename='model',
            author=self.author,
            code='//test code'
        )
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())
Exemplo n.º 2
0
    def test_save(self):
        # system should create new revision on save
        addon = Package(author=self.author, type='a')
        addon.save()
        revisions = PackageRevision.objects.filter(package__name=addon.name)
        first = revisions[0]
        first.save()
        revisions = PackageRevision.objects.filter(package__name=addon.name)
        eq_(2, revisions.count())

        # first is not the same package anymore and it does not have
        # the version_name parameter
        eq_(None, first.version_name)

        # "old" addon doesn't know about the changes
        self.assertNotEqual(addon.latest.revision_number,
                            first.revision_number)

        # reloading addon to update changes
        addon = first.package

        # first is the latest
        eq_(addon.latest.revision_number,
                         first.revision_number)
        self.assertNotEqual(addon.version.revision_number,
                            addon.latest.revision_number)
Exemplo n.º 3
0
    def test_adding_extra_package_properties(self):
        addon = Package(type='a', author=self.author)
        addon.save()
        pk = addon.pk
        rev = addon.latest

        rev.set_extra_json('''
        {
            "preferences": [{
                "name": "example",
                "type": "string",
                "title": "foo",
                "value": "bar"
            }],
            "id": "baz"
        }
        ''')

        addon = Package.objects.get(pk=pk) # breaking cache
        manifest = addon.latest.get_manifest()
        assert 'preferences' in manifest
        eq_(manifest['preferences'][0]['name'], 'example')

        # user-provide values don't override our generated ones
        self.assertNotEqual(manifest['id'], 'baz')

        assert 'Extra JSON' in addon.latest.commit_message
Exemplo n.º 4
0
def package_create(r, type_id):
    """
    Create new Package (Add-on or Library)
    Usually no full_name used
    """

    full_name = r.POST.get("full_name", False)
    description = r.POST.get("description", "")

    if full_name:
        packages = Package.objects.filter(
            author__username=r.user.username, full_name=full_name,
            type=type_id)
        if len(packages.all()) > 0:
            return HttpResponseForbidden(
                "You already have a %s with that name" % escape(
                    settings.PACKAGE_SINGULAR_NAMES[type_id]))
    else:
        description = ""

    item = Package(
        author=r.user,
        full_name=full_name,
        description=description,
        type=type_id
        )
    item.save()

    return HttpResponseRedirect(reverse(
        'jp_%s_edit_latest' % item.get_type_name(), args=[item.id_number]))
Exemplo n.º 5
0
	def test_filtering(self):
		addon2 = Package(full_name=TEST_ADDON2_FULLNAME, author=self.user, type='a')
		addon2.save()
		self.to_delete.append(addon2)

		self.assertEqual(len(list((Package.objects.addons()))), 2)
		self.assertEqual(len(list((Package.objects.libraries()))), 1)
Exemplo n.º 6
0
 def test_addon_creation(self):
     package = Package(
         author=self.author,
         type='a'
     )
     package.save()
     # all packages have assigned an incremental id_number
     assert package.id_number
     eq_(int(package.id_number),
             settings.MINIMUM_PACKAGE_ID + 1)
     # all add-ons have PackageRevision created
     assert package.version
     assert package.latest
     eq_(package.version.id, package.latest.id)
     # name is created automtically if no given
     assert package.full_name
     assert package.name
     eq_(package.full_name, self.author.username)
     # test preventing inserting duplicates
     assert Package.objects.get(
             author=self.author,
             type='a',
             full_name=package.name)
     self.assertRaises(Exception, Package.objects.create,
                       author=self.author, type='a', full_name=package.name)
Exemplo n.º 7
0
def package_create(r, type):
	"""
	Create new Package (Add-on or Library)
	Target of the Popup window with basic metadata
	"""

	full_name = r.POST.get("full_name", False)

	if full_name:
		description = r.POST.get("description")
		packages = Package.objects.filter(author__username=r.user.username, full_name=full_name, type=type)
		if len(packages.all()) > 0:
			return HttpResponseForbidden("You already have a %s with that name" % settings.PACKAGE_SINGULAR_NAMES[type])
	else:
		description = ""
		full_name = 'My Add-on' if type == 'a' else 'My Library'
		full_name = _get_full_name(full_name, r.user.username, type)


	item = Package(
		author=r.user,
		full_name=full_name,
		description=description,
		type=type
		)
	item.save()

	return HttpResponseRedirect(reverse('jp_%s_edit_latest' % item.get_type_name(), args=[item.id_number]))
	"""
Exemplo n.º 8
0
    def test_adding_invalid_extra_json(self):
        addon = Package(type="a", author=self.author)
        addon.save()
        pk = addon.pk
        rev = addon.latest

        from simplejson import JSONDecodeError

        self.assertRaises(
            JSONDecodeError,
            rev.set_extra_json,
            """
        {
            foo: baz
        }
        """,
        )

        from jetpack.errors import IllegalFilenameException

        self.assertRaises(
            IllegalFilenameException,
            rev.set_extra_json,
            """
        {
            "icon": "/user/sean/.ssh/config"
        }
        """,
        )
Exemplo n.º 9
0
    def test_save(self):
        # system should create new revision on save
        addon = Package(author=self.author, type='a')
        addon.save()
        revisions = PackageRevision.objects.filter(package__name=addon.name)
        first = revisions[0]
        first.save()
        revisions = PackageRevision.objects.filter(package__name=addon.name)
        eq_(2, revisions.count())

        # first is not the same package anymore and it does not have
        # the version_name parameter
        eq_(None, first.version_name)

        # "old" addon doesn't know about the changes
        self.assertNotEqual(addon.latest.revision_number,
                            first.revision_number)

        # reloading addon to update changes
        addon = first.package

        # first is the latest
        eq_(addon.latest.revision_number,
                         first.revision_number)
        self.assertNotEqual(addon.version.revision_number,
                            addon.latest.revision_number)
Exemplo n.º 10
0
    def test_adding_extra_package_properties(self):
        addon = Package(type="a", author=self.author)
        addon.save()
        pk = addon.pk
        rev = addon.latest

        rev.set_extra_json(
            """
        {
            "preferences": [{
                "name": "example",
                "type": "string",
                "title": "foo",
                "value": "bar"
            }],
            "id": "baz"
        }
        """
        )

        addon = Package.objects.get(pk=pk)  # breaking cache
        manifest = addon.latest.get_manifest()
        assert "preferences" in manifest
        eq_(manifest["preferences"][0]["name"], "example")

        # user-provide values don't override our generated ones
        self.assertNotEqual(manifest["id"], "baz")

        assert "Extra JSON" in addon.latest.commit_message
Exemplo n.º 11
0
    def test_addon_creation(self):
        package = Package(author=self.author, type='a')
        package.save()
        # all packages have assigned an incremental id_number
        assert package.id_number
        eq_(int(package.id_number), settings.MINIMUM_PACKAGE_ID + 1)
        # all add-ons have PackageRevision created
        assert package.version
        assert package.latest
        eq_(package.version.id, package.latest.id)
        # name is created automtically if no given
        assert package.full_name
        assert package.name
        eq_(package.full_name, self.author.username)
        # test preventing inserting duplicates
        assert Package.objects.get(author=self.author,
                                   type='a',
                                   full_name=package.name)
        p = Package.objects.create(author=self.author,
                                   type='a',
                                   full_name=package.name)

        #test package name iteration
        eq_('john-1', p.name)
        eq_('john', package.name)
Exemplo n.º 12
0
    def test_folder_removed_when_attachments_added(self):
        " EmptyDir's shouldn't exist if there are attachments inside the 'dir' "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        folder = EmptyDir(name=self.path, author=self.author, root_dir='d')
        folder.save()
        revision.folder_add(folder)
        self.assertEqual(1, revision.folders.count())

        att = Attachment(
            filename='/'.join([self.path, 'helpers']),
            author=self.author,
            ext='js'
        )
        att.save()
        revision.attachment_add(att)
        self.assertEqual(0, revision.folders.count())

        att = Attachment(
            filename='model',
            author=self.author,
            ext='html'
        )
        att.save()
        revision.attachment_add(att)
        self.assertEqual(0, revision.folders.count())
Exemplo n.º 13
0
 def test_prepare_zip_file(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     prepare_url = addon.latest.get_prepare_zip_url()
     response = self.client.post(prepare_url, {'hashtag': self.hashtag})
     eq_(response.status_code, 200)
     eq_(response.content, '{"delayed": true}')
Exemplo n.º 14
0
	def test_ordering(self):
		"""
		Newest is first
		"""
		addon2 = Package(full_name=TEST_ADDON2_FULLNAME, author=self.user, type='a')
		addon2.save()
		self.to_delete.append(addon2)
		self.assertEqual(Package.objects.all()[0].full_name, TEST_ADDON2_FULLNAME)
Exemplo n.º 15
0
 def test_prepare_zip_file(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     prepare_url = addon.latest.get_prepare_zip_url()
     response = self.client.post(prepare_url, {'hashtag': self.hashtag})
     eq_(response.status_code, 200)
     eq_(response.content, '{"delayed": true}')
Exemplo n.º 16
0
    def test_library_creation_with_nickname(self):
        profile = self.author.get_profile()
        profile.nickname = 'Samuel'
        profile.save()

        package = Package(author=self.author, type='l')
        package.save()

        eq_(package.full_name, 'Samuel-lib')
Exemplo n.º 17
0
 def test_download_zip_file(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     addon.latest.zip_source(hashtag=self.hashtag)
     download_url = reverse('jp_revision_download_zip', args=[self.hashtag, 'x'])
     response = self.client.get(download_url)
     eq_(response.status_code, 200)
     eq_(response['Content-Disposition'], 'attachment; filename="x.zip"')
Exemplo n.º 18
0
 def test_revision_list_contains_added_modules(self):
     author = User.objects.get(username="******")
     addon = Package(author=author, type="a")
     addon.save()
     mod = Module.objects.create(filename="test_filename", author=author, code="// test")
     rev = addon.latest
     rev.module_add(mod)
     r = self.client.get(reverse("jp_revisions_list_html", args=[addon.id_number]))
     assert "test_filename" in r.content
Exemplo n.º 19
0
 def test_download_zip_file(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     addon.latest.zip_source(hashtag=self.hashtag)
     download_url = reverse('jp_revision_download_zip',
                            args=[self.hashtag, 'x'])
     response = self.client.get(download_url)
     eq_(response.status_code, 200)
     eq_(response['Content-Disposition'], 'attachment; filename="x.zip"')
Exemplo n.º 20
0
 def test_first_revision_creation(self):
     addon = Package(author=self.author, type='a')
     addon.save()
     revisions = PackageRevision.objects.filter(package__pk=addon.pk)
     self.assertEqual(1, revisions.count())
     revision = revisions[0]
     self.assertEqual(revision.author.username, addon.author.username)
     self.assertEqual(revision.revision_number, 0)
     self.assertEqual(revision.pk, addon.latest.pk)
     self.assertEqual(revision.pk, addon.version.pk)
Exemplo n.º 21
0
 def test_duplicate_packages_integrity_error(self):
     # duplicate packages are denied on MySQL level
     author = User.objects.get(username='******')
     addon = Package(full_name='Integrity Error', author=author, type='a')
     addon.save()
     backup = Package.full_clean
     Package.full_clean = Mock()
     addon2 = Package(full_name='Integrity Error', author=author, type='a')
     self.assertRaises(IntegrityError, addon2.save)
     Package.full_clean = backup
Exemplo n.º 22
0
    def test_package_invalid_extra_json(self):
        author = self._login()
        addon = Package(author=author, type='a')
        addon.save()

        extra_json = '{ foo: bar }'
        response = self.client.post(addon.latest.get_save_url(), {
            'package_extra_json': extra_json})

        eq_(response.status_code, 400)
        assert 'invalid JSON' in response.content
Exemplo n.º 23
0
    def test_first_addon_template(self):
        author = User.objects.create(username='******')
        addon = Package(full_name='First Addon', author=author, type='a')
        addon.save()
        mod = addon.latest.modules.all()[0]
        assert 'id: "first-addon-widget' in mod.code

        addon2 = Package(full_name='Second Addon', author=author, type='a')
        addon2.save()
        mod2 = addon2.latest.modules.all()[0]
        assert 'id: "second-addon-widget' not in mod2.code
Exemplo n.º 24
0
 def test_check_zip_file(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     check_url = reverse('jp_revision_check_zip', args=[self.hashtag,])
     response = self.client.get(check_url)
     eq_(response.content, '{"ready": false}')
     addon.latest.zip_source(hashtag=self.hashtag)
     response = self.client.get(check_url)
     eq_(response.status_code, 200)
     eq_(response.content, '{"ready": true}')
Exemplo n.º 25
0
    def test_package_invalid_extra_json(self):
        author = self._login()
        addon = Package(author=author, type='a')
        addon.save()

        extra_json = '{ foo: bar }'
        response = self.client.post(addon.latest.get_save_url(),
                                    {'package_extra_json': extra_json})

        eq_(response.status_code, 400)
        assert 'invalid JSON' in response.content
Exemplo n.º 26
0
    def test_first_addon_template(self):
        author = User.objects.create(username='******')
        addon = Package(full_name='First Addon', author=author, type='a')
        addon.save()
        mod = addon.latest.modules.all()[0]
        assert 'id: "first-addon-widget' in mod.code

        addon2 = Package(full_name='Second Addon', author=author, type='a')
        addon2.save()
        mod2 = addon2.latest.modules.all()[0]
        assert 'id: "second-addon-widget' not in mod2.code
Exemplo n.º 27
0
 def test_revision_list_contains_added_modules(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     mod = Module.objects.create(filename='test_filename',
                                 author=author,
                                 code='// test')
     rev = addon.latest
     rev.module_add(mod)
     r = self.client.get(
         reverse('jp_revisions_list_html', args=[addon.latest.pk]))
     assert 'test_filename' in r.content
Exemplo n.º 28
0
    def test_addon_creation_with_nickname(self):
        """In production if you log in with an AMO user, the username
        is set to a number and the nickname on the profile is set to the
        real username."""
        profile = self.author.get_profile()
        profile.nickname = 'Gordon'
        profile.save()

        package = Package(author=self.author, type='a')
        package.save()

        eq_(package.full_name, 'Gordon')
Exemplo n.º 29
0
 def test_automatic_numbering(self):
     Package(
         author=self.author,
         type='a'
     ).save()
     # Second Library with the same name should get a " (1)" as suffix
     package = Package(
         author=self.author,
         type='a'
     )
     package.save()
     self.assertEqual(package.full_name, '%s (1)' % self.author.username)
Exemplo n.º 30
0
    def test_library_creation_with_nickname(self):
        profile = self.author.get_profile()
        profile.nickname = 'Samuel'
        profile.save()

        package = Package(
            author=self.author,
            type='l'
        )
        package.save()

        eq_(package.full_name, 'Samuel-lib')
Exemplo n.º 31
0
 def test_package_name_change(self):
     author = self._login()
     addon1 = Package(author=author, type='a')
     addon1.save()
     rev1 = addon1.latest
     log.debug(addon1.latest.get_save_url())
     response = self.client.post(addon1.latest.get_save_url(), {
         'full_name': 'FULL NAME'})
     eq_(response.status_code, 200)
     addon2 = Package.objects.get(pk=addon1.pk)
     eq_(len(addon2.revisions.all()), 2)
     eq_(addon2.full_name, addon2.latest.full_name)
     assert rev1.name != addon2.latest.name
Exemplo n.º 32
0
 def test_ordering(self):
     " Newest is first "
     addon1 = Package(author=self.author, type='a')
     addon1.save()
     addon2 = Package(author=self.author, type='a')
     addon2.save()
     # My Addon should be second
     # but because in the test these are so close and we're testing in
     # mutithreaded MySQL it could be different. It would be fair to assume
     # one of these will be (1) and the other not
     names = (addon1.full_name, addon2.full_name)
     self.failUnless('%s (1)' % self.author.username in names)
     self.failUnless('%s' % self.author.username in names)
Exemplo n.º 33
0
 def test_first_revision_creation(self):
     addon = Package(author=self.author, type="a")
     addon.save()
     revisions = PackageRevision.objects.filter(package__pk=addon.pk)
     eq_(1, revisions.count())
     revision = revisions[0]
     eq_(revision.full_name, addon.full_name)
     eq_(revision.name, addon.name)
     eq_(revision.author.username, addon.author.username)
     eq_(revision.revision_number, 0)
     eq_(revision.pk, addon.latest.pk)
     eq_(revision.pk, addon.version.pk)
     eq_(revision.name, addon.name)
Exemplo n.º 34
0
 def test_package_name_change(self):
     author = self._login()
     addon1 = Package(author=author, type='a')
     addon1.save()
     rev1 = addon1.latest
     log.debug(addon1.latest.get_save_url())
     response = self.client.post(addon1.latest.get_save_url(),
                                 {'full_name': 'FULL NAME'})
     eq_(response.status_code, 200)
     addon2 = Package.objects.get(pk=addon1.pk)
     eq_(len(addon2.revisions.all()), 2)
     eq_(addon2.full_name, addon2.latest.full_name)
     assert rev1.name != addon2.latest.name
Exemplo n.º 35
0
 def test_check_zip_file(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     check_url = reverse('jp_revision_check_zip', args=[
         self.hashtag,
     ])
     response = self.client.get(check_url)
     eq_(response.content, '{"ready": false}')
     addon.latest.zip_source(hashtag=self.hashtag)
     response = self.client.get(check_url)
     eq_(response.status_code, 200)
     eq_(response.content, '{"ready": true}')
Exemplo n.º 36
0
 def test_first_revision_creation(self):
     addon = Package(author=self.author, type='a')
     addon.save()
     revisions = PackageRevision.objects.filter(package__pk=addon.pk)
     eq_(1, revisions.count())
     revision = revisions[0]
     eq_(revision.full_name, addon.full_name)
     eq_(revision.name, addon.name)
     eq_(revision.author.username, addon.author.username)
     eq_(revision.revision_number, 0)
     eq_(revision.pk, addon.latest.pk)
     eq_(revision.pk, addon.version.pk)
     eq_(revision.name, addon.name)
Exemplo n.º 37
0
 def test_ordering(self):
     " Newest is first "
     addon1 = Package(author=self.author, type='a')
     addon1.save()
     addon2 = Package(author=self.author, type='a')
     addon2.save()
     # My Addon should be second
     # but because in the test these are so close and we're testing in
     # mutithreaded MySQL it could be different. It would be fair to assume
     # one of these will be (1) and the other not
     names = (addon1.full_name, addon2.full_name)
     self.failUnless('%s (1)' % self.author.username in names)
     self.failUnless('%s' % self.author.username in names)
Exemplo n.º 38
0
 def test_revision_list_contains_added_modules(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     mod = Module.objects.create(
             filename='test_filename',
             author=author,
             code='// test')
     rev = addon.latest
     rev.module_add(mod)
     r = self.client.get(
             reverse('jp_revisions_list_html', args=[addon.id_number]))
     assert 'test_filename' in r.content
Exemplo n.º 39
0
 def test_package_name_change(self):
     author = User.objects.get(username="******")
     author.set_password("secure")
     author.save()
     addon1 = Package(author=author, type="a")
     addon1.save()
     rev1 = addon1.latest
     self.client.login(username=author.username, password="******")
     response = self.client.post(addon1.latest.get_save_url(), {"full_name": "FULL NAME"})
     eq_(response.status_code, 200)
     addon2 = Package.objects.get(pk=addon1.pk)
     eq_(len(addon2.revisions.all()), 2)
     eq_(addon2.full_name, addon2.latest.full_name)
     assert rev1.name != addon2.latest.name
Exemplo n.º 40
0
 def test_name_change(self):
     addon = Package(author=self.author, type='a')
     addon.save()
     revisionA = PackageRevision.objects.filter(package__pk=addon.pk)[0]
     addon.latest.set_full_name("TEST NAME CHANGE")
     addon.save()
     addon.latest.save()
     revisionB = PackageRevision.objects.filter(package__pk=addon.pk)[0]
     log.debug(revisionB.name)
     log.debug(addon.name)
     eq_(revisionB.name, addon.name)
     assert revisionA.pk != revisionB.pk
     assert revisionA.name != revisionB.name
     eq_(len(addon.revisions.all()), 2)
Exemplo n.º 41
0
    def test_package_extra_json_change(self):
        author = self._login()
        addon = Package(author=author, type='a')
        addon.save()
        pk = addon.pk

        homepage = 'https://builder.addons.mozilla.org'
        extra_json = '{"homepage": "%s"}' % homepage
        response = self.client.post(addon.latest.get_save_url(),
                                    {'package_extra_json': extra_json})

        addon = Package.objects.get(pk=pk)  # old one is cached

        eq_(addon.latest.extra_json, extra_json)
Exemplo n.º 42
0
    def test_adding_attachment(self):
        " Test if attachment is added properly "
        addon = Package(author=self.author, type="a")
        addon.save()
        first = addon.latest
        first.attachment_create(filename="test.txt", author=self.author)

        " module should be added to the latter revision only "
        revisions = addon.revisions.all()
        first = revisions[1]
        second = revisions[0]

        eq_(0, first.attachments.count())
        eq_(1, second.attachments.count())
Exemplo n.º 43
0
 def test_read_write_attachment(self):
     """Test that we can read and write to an attachment."""
     addon = Package(author=self.author, type="a")
     addon.save()
     first = addon.latest
     filename = tempfile.mkstemp()[1]
     try:
         attachment = first.attachment_create(filename="test", ext="txt", author=self.author)
         attachment.data = "This is a test."
         attachment.write()
         assert attachment.read() == attachment.data
         assert not attachment.changed()
     finally:
         os.remove(filename)
Exemplo n.º 44
0
 def test_name_change(self):
     addon = Package(author=self.author, type='a')
     addon.save()
     revisionA = PackageRevision.objects.filter(package__pk=addon.pk)[0]
     addon.latest.set_full_name("TEST NAME CHANGE")
     addon.save()
     addon.latest.save()
     revisionB = PackageRevision.objects.filter(package__pk=addon.pk)[0]
     log.debug(revisionB.name)
     log.debug(addon.name)
     eq_(revisionB.name, addon.name)
     assert revisionA.pk != revisionB.pk
     assert revisionA.name != revisionB.name
     eq_(len(addon.revisions.all()), 2)
Exemplo n.º 45
0
def create(request, type_id):
    """
    Create new Package (Add-on or Library)
    Usually no full_name used
    """

    full_name = request.POST.get("full_name", None)
    description = request.POST.get("description", "")

    item = Package(author=request.user, full_name=full_name, description=description, type=type_id)

    item.save()

    return HttpResponseRedirect(reverse("jp_latest", args=[item.pk]))
Exemplo n.º 46
0
 def test_duplicate_packages_integrity_error(self):
     # duplicate packages are denied on MySQL level
     author = User.objects.get(username='******')
     addon = Package(
             full_name='Integrity Error',
             author=author, type='a')
     addon.save()
     backup = Package.full_clean
     Package.full_clean = Mock()
     addon2 = Package(
             full_name='Integrity Error',
             author=author, type='a')
     self.assertRaises(IntegrityError, addon2.save)
     Package.full_clean = backup
Exemplo n.º 47
0
    def test_set_version(self):
        addon = Package(author=self.author, type='a')
        addon.save()
        first = addon.latest
        old_id = first.id
        first.set_version('test')

        # setting version does not make new revision
        eq_(first.id, old_id)

        # setting version sets it for revision, package
        # and assigns revision to package
        eq_(first.version_name, 'test')
        eq_(first.package.version_name, 'test')
        eq_(first.package.version.pk, first.pk)
Exemplo n.º 48
0
    def test_package_sanitization(self):
        bad_text = u'Te$tąć"><script src="google.com"></script>!#'
        good_text = 'Te$tscript srcgoogle.com/script!#'
        good_text_utf8 = u'Te$tąćscript srcgoogle.com/script!#'

        package = Package(author=self.author,
                          type='a',
                          full_name=bad_text,
                          description=bad_text,
                          version_name=bad_text)
        package.save()

        eq_(package.full_name, good_text)
        eq_(package.description, good_text_utf8)
        eq_(package.version_name, good_text)
Exemplo n.º 49
0
    def test_add_commit_message(self):
        author = User.objects.all()[0]
        addon = Package(type='a', author=author)
        addon.save()
        rev = addon.latest
        rev.add_commit_message('one')
        rev.add_commit_message('two')
        rev.save()

        eq_(rev.commit_message, 'one, two')

        # revision has been saved, so we should be building up a new commit message
        rev.add_commit_message('three')
        rev.save()
        eq_(rev.commit_message, 'three')
Exemplo n.º 50
0
 def test_copy_revision(self):
     author = User.objects.get(username='******')
     addon = Package(author=author, type='a')
     addon.save()
     # unauthenticated
     response = self.client.get(addon.latest.get_copy_url())
     eq_(response.status_code, 302)
     # authenticated
     author.set_password('secure')
     author.save()
     self.client.login(username=author.username, password='******')
     log.debug(addon.latest.get_copy_url())
     response = self.client.get(addon.latest.get_copy_url())
     eq_(response.status_code, 200)
     assert 'Add-on' in response.content
     assert 'copied' in response.content
Exemplo n.º 51
0
    def test_folder_added_when_attachments_removed(self):
        " EmptyDir's should be added if all attachments in a 'dir' are removed "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        att = Attachment(filename='/'.join([self.path, 'helpers']),
                         author=self.author,
                         ext='js')
        att.save()
        revision.attachment_add(att)
        self.assertEqual(0, revision.folders.count())

        revision.attachment_remove(att)
        self.assertEqual(1, revision.folders.count())
        self.assertEqual(self.path, revision.folders.all()[0].name)
Exemplo n.º 52
0
    def test_folder_added_when_modules_removed(self):
        " EmptyDir's should be added if all modules in a 'dir' are removed "
        addon = Package(author=self.author, type='a')
        addon.save()
        revision = PackageRevision.objects.filter(package__name=addon.name)[0]

        mod = Module(filename='/'.join([self.path, 'helpers']),
                     author=self.author,
                     code='//test code')
        mod.save()
        revision.module_add(mod)
        self.assertEqual(0, revision.folders.count())

        revision.module_remove(mod)
        self.assertEqual(1, revision.folders.count())
        self.assertEqual(self.path, revision.folders.all()[0].name)
Exemplo n.º 53
0
 def test_package_jid_change(self):
     jid = 'somejid'
     author = self._login()
     addon1 = Package(author=author, type='a')
     addon1.save()
     response = self.client.post(addon1.latest.get_save_url(), {'jid': jid})
     eq_(response.status_code, 200)
     addon2 = Package.objects.get(pk=addon1.pk)
     # no change in revision
     eq_(len(addon2.revisions.all()), 1)
     eq_(addon2.jid, jid)
     # check adding an existing JID
     addon3 = Package(author=author, type='a')
     addon3.save()
     response = self.client.post(addon1.latest.get_save_url(), {'jid': jid})
     eq_(response.status_code, 403)
Exemplo n.º 54
0
    def _save_package(packed, name, harness_options, package_type, author):
        " create Package or add PackageRevision "
        manifest = harness_options['metadata'][name]
        if 'version' not in manifest:
            manifest['version'] = 'uploaded'
        if package_type == 'a':
            manifest['main'] = harness_options['main']
        if 'contributors' in manifest:
            manifest['contributors'] = ','.join(manifest['contributors'])
        if 'license' not in manifest:
            manifest['license'] = ''
        # validation
        if 'name' not in manifest:
            raise ManifestNotValid("Manifest is not valid.\n"
                                   "name is obsolete")

        if 'fullName' not in manifest:
            manifest['fullName'] = manifest['name']

        # * optional - check for jid - might be a problem with private key
        # create Package
        try:
            obj = Package.objects.get(author=author,
                                      name=name,
                                      type=package_type)
            new_revision = True
        except:
            obj = Package(
                author=author,
                full_name=manifest['fullName'],
                name=manifest['name'],
                type=package_type,
                license=manifest['license'],
                description=manifest['description'] \
                        if 'description' in manifest else ''
            )
            obj.save()
            obj.latest.set_version('empty.uploaded')
            new_revision = False

        obj.create_revision_from_xpi(packed,
                                     manifest,
                                     author,
                                     harness_options['jetpackID'],
                                     new_revision=new_revision)

        return obj
Exemplo n.º 55
0
    def test_outdated_dependencies_with_conflicts(self):
        addon = Package.objects.create(author=self.author, type='a')
        lib = Package.objects.create(author=self.author, type='l')
        addon.latest.dependency_add(lib.latest)

        jan = User.objects.get(username='******')
        jan_lib = Package(author=jan, type='l', full_name='janjanjan')
        jan_lib.save()
        dupe_lib = Package(author=jan, type='l', full_name=lib.full_name)
        dupe_lib.save()

        addon.latest.dependency_add(jan_lib.latest)

        jan_lib.latest.dependency_add(dupe_lib.latest)
        out_of_date = addon.latest.get_outdated_dependency_versions()

        eq_(len(out_of_date), 0)
Exemplo n.º 56
0
def create(request, type_id):
    """
    Create new Package (Add-on or Library)
    Usually no full_name used
    """

    full_name = request.POST.get("full_name", None)
    description = request.POST.get("description", "")

    item = Package(author=request.user,
                   full_name=full_name,
                   description=description,
                   type=type_id)

    item.save()

    return HttpResponseRedirect(reverse('jp_latest', args=[item.pk]))
Exemplo n.º 57
0
    def test_adding_attachment(self):
        " Test if attachment is added properly "
        addon = Package(author=self.author, type='a')
        addon.save()
        first = addon.latest
        first.attachment_create(
            filename='test.txt',
            author=self.author
        )

        " module should be added to the latter revision only "
        revisions = addon.revisions.all()
        first = revisions[1]
        second = revisions[0]

        eq_(0, first.attachments.count())
        eq_(1, second.attachments.count())
Exemplo n.º 58
0
 def test_read_write_attachment(self):
     """Test that we can read and write to an attachment."""
     addon = Package(author=self.author, type='a')
     addon.save()
     first = addon.latest
     filename = tempfile.mkstemp()[1]
     try:
         attachment = first.attachment_create(
             filename='test',
             ext='txt',
             author=self.author
         )
         attachment.data = 'This is a test.'
         attachment.write()
         assert attachment.read() == attachment.data
         assert not attachment.changed()
     finally:
         os.remove(filename)
Exemplo n.º 59
0
def _create_lib(author, manifest, full_name, name, id_number, version):
    check_SDK_version(version)

    # create Jetpack Core Library
    contributors = [manifest['author']]
    contributors.extend(manifest['contributors'])
    core = Package(author=author,
                   full_name=full_name,
                   name=name,
                   type='l',
                   public_permission=2,
                   description=manifest['description'],
                   id_number=id_number)
    core.save()
    revision = core.latest
    revision.set_version(manifest.get('version'), version)
    revision.contributors = ', '.join(contributors)
    super(PackageRevision, revision).save()
    return revision