Merge pull request #166 from zalun/bug-792951-is_sdk_version_deprecated

compare versions
This commit is contained in:
Sean McArthur 2012-09-21 09:51:57 -07:00
Родитель 68987e7baa a44d9aef6a
Коммит b662c9fa6c
2 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -12,6 +12,7 @@ import codecs
import waffle
from decimal import Decimal, getcontext
from copy import deepcopy
from distutils.version import LooseVersion
from django.core.exceptions import (ObjectDoesNotExist, ValidationError,
MultipleObjectsReturned)
@ -2502,7 +2503,8 @@ class SDK(BaseModel):
return os.path.join(settings.SDK_SOURCE_DIR, self.dir)
def is_deprecated(self):
return self.version < settings.LOWEST_APPROVED_SDK
return LooseVersion(self.version) < LooseVersion(
settings.LOWEST_APPROVED_SDK)
def delete(self, purge=True, *args, **kwargs):
"""Override delete method to allow purging

Просмотреть файл

@ -7,6 +7,7 @@ import commonware
from test_utils import TestCase
from nose.tools import eq_
from django.conf import settings
from django.contrib.auth.models import User
from jetpack.models import Package, PackageRevision, SDK
@ -21,6 +22,10 @@ class SDKTests(TestCase):
self.addon = Package.objects.filter(type='a')[0]
self.mozuser = User.objects.get(username='4757633')
self.sdk = SDK.objects.get()
self.LOWEST_APPROVED_SDK = settings.LOWEST_APPROVED_SDK
def tearDown(self):
settings.LOWEST_APPROVED_SDK = self.LOWEST_APPROVED_SDK
def test_purge(self):
version = 'testsdk'
@ -42,3 +47,23 @@ class SDKTests(TestCase):
sdk.delete(purge=True)
eq_(len(PackageRevision.objects.filter(version_name=version)), 0)
def test_is_deprecated(self):
settings.LOWEST_APPROVED_SDK = '1.0.2'
self.sdk.version = '1.0'
assert self.sdk.is_deprecated()
self.sdk.version = '1.0.10'
assert not self.sdk.is_deprecated()
self.sdk.version = '1.0.2'
assert not self.sdk.is_deprecated()
# Althought it is broken here there is no danger hence we are not
# allow for beta SDK in production
# If needed, the solution is to use parse_version from pkg_resources
# library (proposed in http://stackoverflow.com/a/6972866/23457)
#self.sdk.version = '1.0.2.beta1'
#assert self.sdk.is_deprecated()
settings.LOWEST_APPROVED_SDK = '1.0.2.beta2'
self.sdk.version = '1.0.2.beta1'
assert self.sdk.is_deprecated()