Skip to content

Commit ab83580

Browse files
committed
add test for utils.dict2object
1 parent 07628ef commit ab83580

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

hobbit_core/flask_hobbit/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class dict2object(dict):
1010
1111
Examples::
1212
13-
In [2]: obj = dict2object({'a':2, 'c':3})
13+
In [2]: obj = dict2object({'a': 2, 'c': 3})
1414
1515
In [3]: obj.a
1616
Out[3]: 2
@@ -32,7 +32,7 @@ def __setattr__(self, name, value):
3232

3333

3434
def secure_filename(filename):
35-
"""Borrowed from werkzeug.utils.secure_filename. Python3 only.
35+
"""Borrowed from werkzeug.utils.secure_filename. **Python3 only**.
3636
3737
Pass it a filename and it will return a secure version of it. This
3838
filename can then safely be stored on a regular file system and passed
@@ -70,7 +70,7 @@ def secure_filename(filename):
7070
'LPT2', 'LPT3', 'PRN', 'NUL',
7171
)
7272
if os.name == 'nt' and filename and \
73-
filename.split('.')[0].upper() in windows_device_files:
73+
filename.split('.')[0].upper() in windows_device_files:
7474
filename = '_' + filename
7575

7676
return filename

tests/test_utils.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# -*- encoding: utf-8 -*-
2-
from hobbit_core.flask_hobbit.utils import secure_filename
2+
import pytest
3+
4+
from hobbit_core.flask_hobbit import utils
35

46
from . import BaseTest, python3_only
57

68

79
class TestUtils(BaseTest):
810

11+
def test_dict2object(self):
12+
obj = utils.dict2object({'a': 2, 'c': 3})
13+
assert obj.a == 2
14+
assert obj.c == 3
15+
16+
# test setattr
17+
obj.a = 4
18+
assert obj.a == 4
19+
20+
# test getattr
21+
with pytest.raises(AttributeError):
22+
print(obj.b)
23+
924
@python3_only
1025
def test_secure_filename(self):
1126
filenames = (
@@ -19,4 +34,4 @@ def test_secure_filename(self):
1934
'i_contain_cool_umlauts.txt',
2035
)
2136
for i, filename in enumerate(filenames):
22-
assert secure_filename(filename) == excepted[i]
37+
assert utils.secure_filename(filename) == excepted[i]

0 commit comments

Comments
 (0)