зеркало из 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()
|
||||
|
|
|
@ -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():
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче