-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added unit tests for serialize function
- Loading branch information
1 parent
471bf04
commit ded9b1d
Showing
2 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.test import TestCase | ||
from edx_ace.utils.signals import make_serializable_object | ||
|
||
class TestMakeSerializableObject(TestCase): | ||
def test_primitive_types(self): | ||
self.assertEqual(make_serializable_object(42), 42) | ||
self.assertEqual(make_serializable_object(3.14), 3.14) | ||
self.assertEqual(make_serializable_object("string"), "string") | ||
self.assertEqual(make_serializable_object(True), True) | ||
self.assertEqual(make_serializable_object(None), None) | ||
|
||
def test_dict(self): | ||
input_dict = { | ||
"int": 1, | ||
"float": 2.0, | ||
"str": "test", | ||
"bool": False, | ||
"none": None, | ||
"list": [1, 2, 3], | ||
"nested_dict": {"key": "value"} | ||
} | ||
self.assertEqual(make_serializable_object(input_dict), input_dict) | ||
|
||
def test_list(self): | ||
input_list = [1, 2.0, "test", False, None, [1, 2, 3], {"key": "value"}] | ||
self.assertEqual(make_serializable_object(input_list), input_list) | ||
|
||
def test_non_serializable(self): | ||
class NonSerializable: | ||
pass | ||
|
||
obj = NonSerializable() | ||
self.assertEqual(make_serializable_object(obj), str(obj)) | ||
|
||
def test_non_serializable_list(self): | ||
class NonSerializable: | ||
pass | ||
|
||
obj = NonSerializable() | ||
obj2 = NonSerializable() | ||
obj_list = [obj, obj2] | ||
self.assertEqual(make_serializable_object(obj_list), [str(obj), str(obj2)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters