-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_base.py
executable file
·38 lines (27 loc) · 1.05 KB
/
test_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python3
"""Tests for the Base class with unittest"""
import unittest
from models.base import Base
class TestBase(unittest.TestCase):
"""Class tests"""
def test_id(self):
base1 = Base()
self.assertEqual(base1.id, 1)
base2 = Base()
self.assertEqual(base2.id, 2)
base3 = Base(125)
self.assertEqual(base3.id, 125)
def test_to_json_string_none(self):
self.assertEqual(Base.to_json_string(None), '[]')
def test_to_json_string_empty(self):
self.assertEqual(Base.to_json_string([]), '[]')
def test_to_json_string_exists(self):
self.assertEqual(Base.to_json_string([{'id': 12}]), '[{"id": 12}]')
def test_from_json_string_none(self):
self.assertEqual(Base.from_json_string(None), [])
def test_from_json_string_empty(self):
self.assertEqual(Base.from_json_string("[]"), [])
def test_from_json_string_exists(self):
self.assertEqual(Base.from_json_string('[{ "id": 89 }]'), [{'id': 89}])
if __name__ == "__main__":
unittest.main()