Adds unit tests for version number comparison

This commit is contained in:
Oliver Walters 2021-03-15 08:51:50 +11:00
parent 6ea846ce45
commit 24823adc6d
2 changed files with 24 additions and 1 deletions

View File

@ -8,7 +8,6 @@ import logging
from datetime import datetime, timedelta
from django_q.models import Success
from django.core.exceptions import AppRegistryNotReady
from django.db.utils import OperationalError, ProgrammingError
@ -52,6 +51,12 @@ def heartbeat():
(There is probably a less "hacky" way of achieving this)?
"""
try:
from django_q.models import Success
logger.warning("Could not perform heartbeat task - App registry not ready")
except AppRegistryNotReady:
return
threshold = datetime.now() - timedelta(minutes=30)
# Delete heartbeat results more than half an hour old,

View File

@ -273,6 +273,9 @@ class TestSerialNumberExtraction(TestCase):
class TestVersionNumber(TestCase):
"""
Unit tests for version number functions
"""
def test_tuple(self):
@ -282,3 +285,18 @@ class TestVersionNumber(TestCase):
s = '.'.join([str(i) for i in v])
self.assertTrue(s in version.inventreeVersion())
def test_comparison(self):
"""
Test direct comparison of version numbers
"""
v_a = version.inventreeVersionTuple('1.2.0')
v_b = version.inventreeVersionTuple('1.2.3')
v_c = version.inventreeVersionTuple('1.2.4')
v_d = version.inventreeVersionTuple('2.0.0')
self.assertTrue(v_b > v_a)
self.assertTrue(v_c > v_b)
self.assertTrue(v_d > v_c)
self.assertTrue(v_d > v_a)