2010-10-20 20:35:11 +04:00
|
|
|
import os
|
|
|
|
|
|
|
|
from test_utils import TestCase as _TestCase
|
2010-11-02 14:05:20 +03:00
|
|
|
from django.conf import settings
|
2011-11-07 19:18:32 +04:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
|
|
from jetpack.models import SDK, Package
|
2010-10-20 20:35:11 +04:00
|
|
|
|
2011-02-03 15:28:10 +03:00
|
|
|
def get_latest_sdk_dir():
|
2011-02-09 22:14:43 +03:00
|
|
|
lib_dir = os.path.join(settings.FRAMEWORK_PATH, 'lib')
|
|
|
|
sdks = os.listdir(lib_dir)
|
2011-02-03 15:28:10 +03:00
|
|
|
found = None
|
|
|
|
sdk_time = -1
|
2011-03-09 02:20:24 +03:00
|
|
|
if hasattr(settings, 'TEST_SDK'):
|
|
|
|
return settings.TEST_SDK
|
2011-02-03 15:28:10 +03:00
|
|
|
for sdk in sdks:
|
2011-02-09 22:14:43 +03:00
|
|
|
if os.path.isdir(os.path.join(lib_dir, sdk)):
|
|
|
|
sdk_inf = os.stat(os.path.join(lib_dir, sdk))
|
2011-02-03 15:28:10 +03:00
|
|
|
if sdk_time < 0 or sdk_time < sdk_inf.st_ctime:
|
|
|
|
sdk_time = sdk_inf.st_ctime
|
|
|
|
found = sdk
|
|
|
|
return found
|
2010-10-20 20:35:11 +04:00
|
|
|
|
|
|
|
class TestCase(_TestCase):
|
|
|
|
"""
|
|
|
|
Base class for tests depending on existance of lib/jetpack-sdk
|
|
|
|
"""
|
2011-02-03 15:28:10 +03:00
|
|
|
def createCore(self, core_dir='jetpack-sdk'):
|
2010-10-20 20:35:11 +04:00
|
|
|
" discover the newest dir and link to it "
|
2010-10-20 20:58:24 +04:00
|
|
|
# find the newest SDK
|
2011-02-03 15:28:10 +03:00
|
|
|
self.sdk_filename = get_latest_sdk_dir()
|
2011-02-01 18:23:39 +03:00
|
|
|
self.sdk_path = os.path.join(settings.FRAMEWORK_PATH,
|
2011-02-03 15:28:10 +03:00
|
|
|
'lib/', core_dir)
|
2011-02-01 18:23:39 +03:00
|
|
|
sdk_orig = os.path.join(settings.FRAMEWORK_PATH, 'lib',
|
|
|
|
self.sdk_filename)
|
2010-10-20 20:35:11 +04:00
|
|
|
self.core_link_created = False
|
|
|
|
if not os.path.exists(self.sdk_path):
|
|
|
|
os.symlink(sdk_orig, self.sdk_path)
|
|
|
|
self.core_link_created = True
|
|
|
|
|
|
|
|
def deleteCore(self):
|
|
|
|
" remove symlink "
|
2010-10-20 20:58:24 +04:00
|
|
|
if not hasattr(self, 'core_link_created'):
|
2010-10-20 20:35:11 +04:00
|
|
|
return
|
|
|
|
if self.core_link_created:
|
|
|
|
os.remove(self.sdk_path)
|
2011-11-07 19:18:32 +04:00
|
|
|
|
|
|
|
def createTestSDK(self, name='test'):
|
|
|
|
if SDK.objects.count():
|
|
|
|
core_sdk = SDK.objects.latest('pk')
|
|
|
|
core_lib = core_sdk.core_lib
|
|
|
|
core_lib.save()
|
|
|
|
kit_lib = core_sdk.kit_lib
|
|
|
|
kit_lib.save()
|
|
|
|
else:
|
|
|
|
# create Package and PackageRevision
|
|
|
|
author = User.objects.create(username='SDK owner')
|
|
|
|
core_lib = Package.objects.create(
|
|
|
|
full_name='Core Lib',
|
|
|
|
type='l',
|
|
|
|
author=author).latest
|
|
|
|
kit_lib = Package.objects.create(
|
|
|
|
full_name='Kit Lib',
|
|
|
|
type='l',
|
|
|
|
author=author).latest
|
|
|
|
|
|
|
|
self.test_sdk = SDK.objects.create(
|
|
|
|
version='test',
|
|
|
|
core_lib=core_lib,
|
|
|
|
kit_lib=kit_lib,
|
|
|
|
dir=settings.TEST_SDK)
|
|
|
|
|