File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def format_http_exception(ex):
30
30
code = getattr (ex , 'code' , None )
31
31
try :
32
32
status = int (code )
33
- except TypeError :
33
+ except ( TypeError , ValueError ) :
34
34
return
35
35
36
36
api_ex = STATUS_MAP .get (status )
Original file line number Diff line number Diff line change
1
+ from unittest .mock import Mock
2
+
3
+ from flask_combo_jsonapi import JsonApiException
4
+ from flask_combo_jsonapi .errors import format_http_exception
5
+
6
+
7
+ def test_format_http_exception__value_error ():
8
+ ex = Mock ()
9
+ ex .code = 'f405'
10
+
11
+ assert format_http_exception (ex ) is None
12
+
13
+
14
+ def test_format_http_exception__type_error ():
15
+ ex = Mock ()
16
+ ex .code = 'not_int'
17
+
18
+ assert format_http_exception (ex ) is None
19
+
20
+
21
+ def test_format_http_exception__success ():
22
+ ex = Mock ()
23
+ ex .code = 400
24
+
25
+ res = format_http_exception (ex )
26
+
27
+ assert isinstance (res , JsonApiException )
28
+ assert res .status == '400'
You can’t perform that action at this time.
0 commit comments