Add a simple unit test for the settings model

This commit is contained in:
Oliver Walters 2020-10-20 08:29:06 +11:00
parent c6e61c20fe
commit 226a91718b
2 changed files with 32 additions and 2 deletions

View File

@ -97,7 +97,7 @@ class InvenTreeSetting(models.Model):
else:
return
setting.value = value
setting.value = str(value)
setting.save()
key = models.CharField(max_length=50, blank=False, unique=True, help_text=_('Settings key (must be unique - case insensitive'))

View File

@ -2,8 +2,9 @@
from __future__ import unicode_literals
from django.test import TestCase
from django.contrib.auth import get_user_model
from .models import Currency
from .models import Currency, InvenTreeSetting
class CurrencyTest(TestCase):
@ -17,3 +18,32 @@ class CurrencyTest(TestCase):
# Simple test for now (improve this later!)
self.assertEqual(Currency.objects.count(), 2)
class SettingsTest(TestCase):
"""
Tests for the 'settings' model
"""
def setUp(self):
User = get_user_model()
self.user = User.objects.create_user('username', 'user@email.com', 'password')
self.user.is_staff = True
self.user.save()
self.client.login(username='username', password='password')
def test_defaults(self):
"""
Populate the settings with default values
"""
for key in InvenTreeSetting.DEFAULT_VALUES.keys():
value = InvenTreeSetting.DEFAULT_VALUES[key]
InvenTreeSetting.set_setting(key, value, self.user)
self.assertEqual(str(value), InvenTreeSetting.get_setting(key))