本文整理汇总了Python中jetpack.models.Package类的典型用法代码示例。如果您正苦于以下问题:Python Package类的具体用法?Python Package怎么用?Python Package使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Package类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filtering
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)
示例2: test_addon_creation
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)
示例3: test_adding_invalid_extra_json
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"
}
""",
)
示例4: package_create
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]))
"""
示例5: test_adding_extra_package_properties
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
示例6: package_create
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]))
示例7: test_save
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)
示例8: test_folder_removed_when_modules_added
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())
示例9: test_folder_removed_when_attachments_added
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())
示例10: test_adding_extra_package_properties
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
示例11: test_prepare_zip_file
def test_prepare_zip_file(self):
author = User.objects.get(username='john')
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}')
示例12: test_ordering
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)
示例13: test_revision_list_contains_added_modules
def test_revision_list_contains_added_modules(self):
author = User.objects.get(username="john")
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
示例14: test_download_zip_file
def test_download_zip_file(self):
author = User.objects.get(username='john')
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"')
示例15: test_first_revision_creation
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)