зеркало из https://github.com/mozilla/FlightDeck.git
fake sdk for docs import tests created
This commit is contained in:
Родитель
188813161e
Коммит
46e23b3055
|
@ -0,0 +1,10 @@
|
|||
from django.db import models, IntegrityError
|
||||
|
||||
from jetpack.models import SDK
|
||||
from utils.exceptions import SimpleException
|
||||
|
||||
class DocPage(models.Model):
|
||||
sdk = models.ForeignKey(SDK)
|
||||
path = models.CharField(max_length=255)
|
||||
html = models.TextField()
|
||||
json = models.TextField()
|
|
@ -2,10 +2,38 @@
|
|||
Testing the cuddlefish engine to export API
|
||||
"""
|
||||
import os
|
||||
from cuddlefish import apiparser
|
||||
import commonware.log
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from utils.test import TestCase, get_latest_sdk_dir
|
||||
from jetpack.management import create_SDK
|
||||
from jetpack.models import Package, PackageRevision, SDK
|
||||
|
||||
log = commonware.log.getLogger('f.api.tests')
|
||||
|
||||
|
||||
from utils.test import TestCase
|
||||
class ImportDocsTest(TestCase):
|
||||
fixtures = ['mozilla_user']
|
||||
|
||||
def setUp(self):
|
||||
self.mozilla = User.objects.get(username='mozilla')
|
||||
self.sdk_filename = get_latest_sdk_dir()
|
||||
# create fake core-lib and addon-kit
|
||||
core_lib = Package.objects.create(
|
||||
name='core-lib-fake',
|
||||
type='l',
|
||||
author=self.mozilla,
|
||||
public_permission=2)
|
||||
self.sdk = SDK.objects.create(
|
||||
version='test-sdk',
|
||||
core_lib=core_lib.latest,
|
||||
dir=self.sdk_filename)
|
||||
|
||||
|
||||
def test_import_files(self):
|
||||
pass
|
||||
|
||||
|
||||
class CuddleTest(TestCase):
|
||||
|
@ -22,6 +50,7 @@ class CuddleTest(TestCase):
|
|||
"""
|
||||
exporting hunks
|
||||
"""
|
||||
from cuddlefish import apiparser
|
||||
from api.views import SDKPACKAGESDIR
|
||||
#XXX: the path is different now
|
||||
docs_dir = os.path.join(
|
||||
|
@ -29,6 +58,3 @@ class CuddleTest(TestCase):
|
|||
text = open(os.path.join(docs_dir, 'url.md')).read()
|
||||
self.failUnless(len(list(apiparser.parse_hunks(text))) > 0)
|
||||
|
||||
|
||||
class ImportDocsTest(TestCase):
|
||||
pass
|
||||
|
|
|
@ -18,16 +18,6 @@ ALLOWED_CORE_NAMES = {
|
|||
}
|
||||
|
||||
|
||||
class SimpleException(Exception):
|
||||
" Exception to be inherited in more precised Exception "
|
||||
|
||||
def __init__(self, value=None):
|
||||
self.parameter = value
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.parameter)
|
||||
|
||||
|
||||
class SDKVersionNotUniqueException(SimpleException):
|
||||
" Not unique version of SDK "
|
||||
|
||||
|
@ -93,18 +83,6 @@ def get_or_create_core_author():
|
|||
return core_author
|
||||
|
||||
|
||||
def import_docs(sdk_source, tar_filename="addon-sdk-docs.tgz"):
|
||||
"""import docs from addon-sdk-docs.tgz """
|
||||
tar_path = os.path.join(sdk_source, tar_filename)
|
||||
if not os.path.isfile(tar_path):
|
||||
raise SimpleException(
|
||||
"%s does not exist. Have you forgotten to run `csf sdocs`?" %
|
||||
tar_path)
|
||||
if not tarfile.is_tarfile(tar_path):
|
||||
raise SimpleException("%s is not a tar file" % tar_path)
|
||||
|
||||
|
||||
|
||||
def _get_code(path):
|
||||
handle = open(path, 'r')
|
||||
code = handle.read()
|
||||
|
|
|
@ -488,12 +488,12 @@ class PackageRevision(models.Model):
|
|||
return reverse(
|
||||
'jp_addon_switch_sdk_version',
|
||||
args=[self.package.id_number, self.revision_number])
|
||||
|
||||
|
||||
def get_add_folder_url(self):
|
||||
return reverse(
|
||||
'jp_%s_revision_add_folder' % self.package.get_type_name(),
|
||||
args=[self.package.id_number, self.revision_number])
|
||||
|
||||
|
||||
def get_remove_folder_url(self):
|
||||
return reverse(
|
||||
'jp_%s_revision_remove_folder' % self.package.get_type_name(),
|
||||
|
@ -603,7 +603,7 @@ class PackageRevision(models.Model):
|
|||
# reassign all dependencies
|
||||
for dep in origin.dependencies.all():
|
||||
self.dependencies.add(dep)
|
||||
|
||||
|
||||
for dir in origin.folders.all():
|
||||
self.folders.add(dir)
|
||||
|
||||
|
@ -612,7 +612,7 @@ class PackageRevision(models.Model):
|
|||
|
||||
for att in origin.attachments.all():
|
||||
self.attachments.add(att)
|
||||
|
||||
|
||||
|
||||
self.package.latest = self
|
||||
self.package.save()
|
||||
|
@ -672,7 +672,7 @@ class PackageRevision(models.Model):
|
|||
if self.attachments.filter(filename=filename, ext=ext).count():
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def validate_folder_name(self, foldername):
|
||||
if self.folders.filter(name=foldername).count():
|
||||
return False
|
||||
|
@ -709,7 +709,7 @@ class PackageRevision(models.Model):
|
|||
" copy to new revision, remove module "
|
||||
self.save()
|
||||
return self.modules.remove(mod)
|
||||
|
||||
|
||||
def folder_add(self, dir, save=True):
|
||||
" copy to new revision, add EmptyDir "
|
||||
if not self.validate_folder_name(dir.name):
|
||||
|
@ -718,11 +718,11 @@ class PackageRevision(models.Model):
|
|||
'with the name "%s". Each folder in your add-on '
|
||||
'needs to have a unique name.') % dir.name
|
||||
)
|
||||
|
||||
|
||||
if save:
|
||||
self.save()
|
||||
return self.folders.add(dir)
|
||||
|
||||
|
||||
def folder_remove(self, dir):
|
||||
" copy to new revision, remove folder "
|
||||
self.save()
|
||||
|
@ -911,7 +911,7 @@ class PackageRevision(models.Model):
|
|||
} for a in self.attachments.all()
|
||||
] if self.attachments.count() > 0 else []
|
||||
return simplejson.dumps(a_list)
|
||||
|
||||
|
||||
def get_folders_list_json(self):
|
||||
" returns empty folders list as JSON object "
|
||||
f_list = [{
|
||||
|
@ -1242,10 +1242,10 @@ class EmptyDir(models.Model):
|
|||
related_name='folders', blank=True)
|
||||
name = models.CharField(max_length=255)
|
||||
author = models.ForeignKey(User, related_name='folders')
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
return 'Dir: %s (by %s)' % (self.name, self.author.username)
|
||||
|
||||
|
||||
|
||||
class SDK(models.Model):
|
||||
"""
|
||||
|
@ -1254,7 +1254,7 @@ class SDK(models.Model):
|
|||
"""
|
||||
version = models.CharField(max_length=10, unique=True)
|
||||
|
||||
# It has to be accompanied with a jetpack-core version
|
||||
# It has to be accompanied with a core library
|
||||
# needs to exist before SDK is created
|
||||
core_lib = models.OneToOneField(PackageRevision,
|
||||
related_name="parent_sdk_core+")
|
||||
|
@ -1281,6 +1281,17 @@ class SDK(models.Model):
|
|||
def is_deprecated(self):
|
||||
return self.version < '0.9'
|
||||
|
||||
def import_docs(self, tar_filename="addon-sdk-docs.tgz"):
|
||||
from api.models import DocPage
|
||||
"""import docs from addon-sdk-docs.tgz """
|
||||
tar_path = os.path.join(self.get_sdk_dirource_dir(), tar_filename)
|
||||
if not os.path.isfile(tar_path):
|
||||
raise SimpleException(
|
||||
"%s does not exist. Have you forgotten to run `cfx sdocs`?" %
|
||||
tar_path)
|
||||
if not tarfile.is_tarfile(tar_path):
|
||||
raise SimpleException("%s is not a tar file" % tar_path)
|
||||
|
||||
|
||||
def _get_next_id_number():
|
||||
"""
|
||||
|
@ -1359,13 +1370,13 @@ def manage_empty_dirs(instance, action, **kwargs):
|
|||
"""
|
||||
create EmptyDirs when all modules in a "dir" are deleted,
|
||||
and remove EmptyDirs when any modules are added into the "dir"
|
||||
"""
|
||||
"""
|
||||
if not (isinstance(instance, PackageRevision)
|
||||
and action in ('post_add', 'post_remove')):
|
||||
return
|
||||
|
||||
|
||||
pk_set = kwargs.get('pk_set', [])
|
||||
|
||||
|
||||
if action == 'post_add':
|
||||
for pk in pk_set:
|
||||
mod = Module.objects.get(pk=pk)
|
||||
|
@ -1381,11 +1392,11 @@ def manage_empty_dirs(instance, action, **kwargs):
|
|||
dirname = mod.get_path()
|
||||
if not dirname:
|
||||
continue
|
||||
|
||||
|
||||
if not instance.modules.filter(filename__startswith=dirname).count():
|
||||
emptydir = EmptyDir(name=dirname, author=instance.author)
|
||||
emptydir.save()
|
||||
|
||||
|
||||
instance.folders.add(emptydir)
|
||||
m2m_changed.connect(manage_empty_dirs, sender=Module.revisions.through)
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class PackageTest(TestCase):
|
|||
# all add-ons have PackageRevision created
|
||||
self.failUnless(package.version and package.latest)
|
||||
self.assertEqual(package.version.id, package.latest.id)
|
||||
# name is created automtically if no given
|
||||
# name is created automatically if none given
|
||||
self.failUnless(package.full_name)
|
||||
self.failUnless(package.name)
|
||||
self.assertEqual(package.full_name, self.author.username)
|
||||
|
|
|
@ -16,5 +16,12 @@
|
|||
"email": "",
|
||||
"date_joined": "2010-09-27 05:39:25"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "person.profile",
|
||||
"fields": {
|
||||
"user": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -3,26 +3,29 @@ import os
|
|||
from test_utils import TestCase as _TestCase
|
||||
from django.conf import settings
|
||||
|
||||
def get_latest_sdk_dir():
|
||||
sdks = os.listdir(os.path.join(settings.FRAMEWORK_PATH, 'lib'))
|
||||
found = None
|
||||
sdk_time = -1
|
||||
for sdk in sdks:
|
||||
if sdk != '__init__.py':
|
||||
sdk_inf = os.stat(os.path.join(settings.FRAMEWORK_PATH, 'lib',
|
||||
sdk))
|
||||
if sdk_time < 0 or sdk_time < sdk_inf.st_ctime:
|
||||
sdk_time = sdk_inf.st_ctime
|
||||
found = sdk
|
||||
return found
|
||||
|
||||
class TestCase(_TestCase):
|
||||
"""
|
||||
Base class for tests depending on existance of lib/jetpack-sdk
|
||||
"""
|
||||
def createCore(self):
|
||||
def createCore(self, core_dir='jetpack-sdk'):
|
||||
" discover the newest dir and link to it "
|
||||
# find the newest SDK
|
||||
sdks = os.listdir(os.path.join(settings.FRAMEWORK_PATH, 'lib'))
|
||||
self.sdk_filename = None
|
||||
sdk_time = -1
|
||||
for sdk in sdks:
|
||||
if sdk != '__init__.py':
|
||||
sdk_inf = os.stat(os.path.join(settings.FRAMEWORK_PATH, 'lib',
|
||||
sdk))
|
||||
if sdk_time < 0 or sdk_time > sdk_inf.st_ctime:
|
||||
sdk_time = sdk_inf.st_ctime
|
||||
self.sdk_filename = sdk
|
||||
self.sdk_filename = get_latest_sdk_dir()
|
||||
self.sdk_path = os.path.join(settings.FRAMEWORK_PATH,
|
||||
'lib/jetpack-sdk')
|
||||
'lib/', core_dir)
|
||||
sdk_orig = os.path.join(settings.FRAMEWORK_PATH, 'lib',
|
||||
self.sdk_filename)
|
||||
self.core_link_created = False
|
||||
|
|
Загрузка…
Ссылка в новой задаче