mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
kvstore: Convert tests to pytest style
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
8587df1f4a
commit
0fb7cb9331
@ -21,34 +21,32 @@ Test module for key/value store.
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
from plinth import kvstore
|
from plinth import kvstore
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
class KVStoreTestCase(TestCase):
|
|
||||||
"""Verify the behavior of the kvstore module."""
|
|
||||||
|
|
||||||
def test_get_set(self):
|
def test_get_set():
|
||||||
"""Verify that a set value can be retrieved."""
|
"""Verify that a set value can be retrieved."""
|
||||||
key = 'name'
|
key = 'name'
|
||||||
expected_value = 'Guido'
|
expected_value = 'Guido'
|
||||||
kvstore.set(key, expected_value)
|
kvstore.set(key, expected_value)
|
||||||
actual_value = kvstore.get(key)
|
actual_value = kvstore.get(key)
|
||||||
self.assertEqual(expected_value, actual_value)
|
assert expected_value == actual_value
|
||||||
|
|
||||||
def test_get_set_complex_structures(self):
|
|
||||||
"""Verify that complex structures can be stored and retrieved."""
|
|
||||||
key = 'compex_structure'
|
|
||||||
expected_value = {'k1': 1, 'k2': [2, 3], 'k3': 4.5, 'k4': 'Hello',
|
|
||||||
'k5': {'a': 'b'}}
|
|
||||||
kvstore.set(key, expected_value)
|
|
||||||
actual_value = kvstore.get(key)
|
|
||||||
self.assertEqual(expected_value, actual_value)
|
|
||||||
|
|
||||||
def test_get_default(self):
|
def test_get_set_complex_structures():
|
||||||
"""Verify that either a set value or its default can be retrieved."""
|
"""Verify that complex structures can be stored and retrieved."""
|
||||||
expected = 'default'
|
key = 'compex_structure'
|
||||||
actual = kvstore.get_default('bad_key', expected)
|
expected_value = {'k1': 1, 'k2': [2, 3], 'k3': 4.5, 'k4': 'Hello',
|
||||||
self.assertEqual(expected, actual)
|
'k5': {'a': 'b'}}
|
||||||
|
kvstore.set(key, expected_value)
|
||||||
|
actual_value = kvstore.get(key)
|
||||||
|
assert expected_value == actual_value
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_default():
|
||||||
|
"""Verify that either a set value or its default can be retrieved."""
|
||||||
|
expected = 'default'
|
||||||
|
actual = kvstore.get_default('bad_key', expected)
|
||||||
|
assert expected == actual
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user