mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add a simple unit test for the settings model
This commit is contained in:
parent
c6e61c20fe
commit
226a91718b
@ -97,7 +97,7 @@ class InvenTreeSetting(models.Model):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
setting.value = value
|
setting.value = str(value)
|
||||||
setting.save()
|
setting.save()
|
||||||
|
|
||||||
key = models.CharField(max_length=50, blank=False, unique=True, help_text=_('Settings key (must be unique - case insensitive'))
|
key = models.CharField(max_length=50, blank=False, unique=True, help_text=_('Settings key (must be unique - case insensitive'))
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.test import TestCase
|
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):
|
class CurrencyTest(TestCase):
|
||||||
@ -17,3 +18,32 @@ class CurrencyTest(TestCase):
|
|||||||
# Simple test for now (improve this later!)
|
# Simple test for now (improve this later!)
|
||||||
|
|
||||||
self.assertEqual(Currency.objects.count(), 2)
|
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user