зеркало из https://github.com/mozilla/FlightDeck.git
tests for previous two fixes
This commit is contained in:
Родитель
b56bc5d793
Коммит
9914643a1b
|
@ -307,6 +307,14 @@ class TestViews(TestCase):
|
|||
revision = PackageRevision.objects.get(package=self.package,
|
||||
revision_number=2)
|
||||
assert not revision.attachments.all().count()
|
||||
|
||||
def test_fake_attachment_remove(self):
|
||||
revision = self.add_one()
|
||||
|
||||
data = {'uid': '1337'}
|
||||
resp = self.client.post(self.get_delete_url(1), data)
|
||||
|
||||
eq_(resp.status_code, 404)
|
||||
|
||||
def test_attachment_rename(self):
|
||||
revision = self.add_one()
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
from test_utils import TestCase
|
||||
import os
|
||||
import json
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from test_utils import TestCase
|
||||
from nose import SkipTest
|
||||
from nose.tools import eq_
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from jetpack.models import Package, PackageRevision, Module, EmptyDir, \
|
||||
Attachment
|
||||
|
||||
def newest(revision):
|
||||
number = revision.revision_number
|
||||
return (PackageRevision.objects.filter(revision_number__gt=number,
|
||||
package=revision.package)
|
||||
.order_by('-revision_number')[:1])[0]
|
||||
|
||||
class FolderTest(TestCase):
|
||||
fixtures = ['mozilla_user', 'users', 'packages']
|
||||
|
@ -109,3 +120,73 @@ class FolderTest(TestCase):
|
|||
revision.attachment_remove(att)
|
||||
self.assertEqual(1, revision.folders.count())
|
||||
self.assertEqual(self.path, revision.folders.all()[0].name)
|
||||
|
||||
class TestViews(TestCase):
|
||||
fixtures = ['mozilla_user', 'users', 'core_sdk', 'packages']
|
||||
|
||||
def setUp(self):
|
||||
if not os.path.exists(settings.UPLOAD_DIR):
|
||||
os.makedirs(settings.UPLOAD_DIR)
|
||||
|
||||
self.author = User.objects.get(username='john')
|
||||
self.author.set_password('password')
|
||||
self.author.save()
|
||||
|
||||
self.package = self.author.packages_originated.addons()[0:1].get()
|
||||
self.revision = self.package.revisions.all()[0]
|
||||
|
||||
self.client.login(username=self.author.username, password='password')
|
||||
|
||||
def post(self, url, data):
|
||||
return self.client.post(url, data);
|
||||
|
||||
def add_one(self, name='tester', root_dir='l'):
|
||||
self.post(self.get_add_url(self.revision.revision_number),
|
||||
{ 'name': name, 'root_dir': root_dir })
|
||||
self.revision = newest(self.revision)
|
||||
return self.revision
|
||||
|
||||
def get_add_url(self, revision):
|
||||
args = [self.package.id_number, revision]
|
||||
return reverse('jp_addon_revision_add_folder', args=args)
|
||||
|
||||
def get_delete_url(self, revision):
|
||||
args = [self.package.id_number, revision]
|
||||
return reverse('jp_addon_revision_remove_folder', args=args)
|
||||
|
||||
def test_add_folder(self):
|
||||
res = self.post(self.get_add_url(self.revision.revision_number),
|
||||
{ 'name': 'tester', 'root_dir': 'l' })
|
||||
eq_(res.status_code, 200)
|
||||
json.loads(res.content)
|
||||
|
||||
revision = newest(self.revision)
|
||||
folder = revision.folders.all()[0]
|
||||
eq_(folder.name, 'tester')
|
||||
|
||||
def test_remove_folder(self):
|
||||
self.add_one()
|
||||
res = self.post(self.get_delete_url(self.revision.revision_number),
|
||||
{ 'name': 'tester', 'root_dir': 'l' })
|
||||
eq_(res.status_code, 200)
|
||||
json.loads(res.content)
|
||||
|
||||
revision = newest(self.revision)
|
||||
eq_(revision.folders.count(), 0)
|
||||
|
||||
def test_remove_fake_folder(self):
|
||||
self.add_one()
|
||||
res = self.post(self.get_delete_url(self.revision.revision_number), {
|
||||
'name': 'im_not_a_folder',
|
||||
'root_dir': 'l'
|
||||
})
|
||||
|
||||
eq_(res.status_code, 403)
|
||||
|
||||
def test_folder_sanitization(self):
|
||||
revision = self.add_one(name='A"> <script src="google.com">/m@l!c!ous')
|
||||
eq_(revision.folders.all()[0].name, 'A-script-src-googlecom-/m-l-c-ous')
|
||||
revision.folder_remove(revision.folders.all()[0])
|
||||
|
||||
revision = self.add_one(name='/absolute///and/triple/')
|
||||
eq_(revision.folders.all()[0].name, 'absolute/and/triple')
|
|
@ -125,65 +125,3 @@ class TestPackage(TestCase):
|
|||
# addon depends on lib should be visable
|
||||
response = self.client.get(lib.get_absolute_url())
|
||||
eq_(response.status_code, 200)
|
||||
|
||||
class TestEmptyDirs(TestCase):
|
||||
fixtures = ['mozilla_user', 'users', 'core_sdk', 'packages']
|
||||
|
||||
def setUp(self):
|
||||
if not os.path.exists(settings.UPLOAD_DIR):
|
||||
os.makedirs(settings.UPLOAD_DIR)
|
||||
|
||||
self.author = User.objects.get(username='john')
|
||||
self.author.set_password('password')
|
||||
self.author.save()
|
||||
|
||||
self.package = self.author.packages_originated.addons()[0:1].get()
|
||||
self.revision = self.package.revisions.all()[0]
|
||||
|
||||
self.client.login(username=self.author.username, password='password')
|
||||
|
||||
def post(self, url, data):
|
||||
return self.client.post(url, data);
|
||||
|
||||
def add_one(self, name='tester', root_dir='l'):
|
||||
self.post(self.get_add_url(self.revision.revision_number),
|
||||
{ 'name': name, 'root_dir': root_dir })
|
||||
self.revision = next(self.revision)
|
||||
return self.revision
|
||||
|
||||
def get_add_url(self, revision):
|
||||
args = [self.package.id_number, revision]
|
||||
return reverse('jp_addon_revision_add_folder', args=args)
|
||||
|
||||
def get_delete_url(self, revision):
|
||||
args = [self.package.id_number, revision]
|
||||
return reverse('jp_addon_revision_remove_folder', args=args)
|
||||
|
||||
def test_add_folder(self):
|
||||
res = self.post(self.get_add_url(self.revision.revision_number),
|
||||
{ 'name': 'tester', 'root_dir': 'l' })
|
||||
eq_(res.status_code, 200)
|
||||
json.loads(res.content)
|
||||
|
||||
revision = next(self.revision)
|
||||
folder = revision.folders.all()[0]
|
||||
eq_(folder.name, 'tester')
|
||||
|
||||
def test_remove_folder(self):
|
||||
self.add_one()
|
||||
res = self.post(self.get_delete_url(self.revision.revision_number),
|
||||
{ 'name': 'tester', 'root_dir': 'l' })
|
||||
eq_(res.status_code, 200)
|
||||
json.loads(res.content)
|
||||
|
||||
revision = next(self.revision)
|
||||
eq_(revision.folders.count(), 0)
|
||||
|
||||
def test_folder_sanitization(self):
|
||||
revision = self.add_one(name='A"> <script src="google.com">/m@l!c!ous')
|
||||
eq_(revision.folders.all()[0].name, 'A-script-src-googlecom-/m-l-c-ous')
|
||||
revision.folder_remove(revision.folders.all()[0])
|
||||
|
||||
revision = self.add_one(name='/absolute///and/triple/')
|
||||
eq_(revision.folders.all()[0].name, 'absolute/and/triple')
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче