Browse Source

better test for error case : check response_body structure

Guénaël Muller 6 years ago
parent
commit
1464da73d7
1 changed files with 20 additions and 0 deletions
  1. 20 0
      tracim/tests/functional/test_session.py

+ 20 - 0
tracim/tests/functional/test_session.py View File

29
             params=params,
29
             params=params,
30
             status=500,
30
             status=500,
31
         )
31
         )
32
+        assert isinstance(res.json, dict)
33
+        assert 'code' in res.json.keys()
34
+        assert 'message' in res.json.keys()
35
+        assert 'details' in res.json.keys()
32
 
36
 
33
 
37
 
34
 class TestLoginEndpoint(FunctionalTest):
38
 class TestLoginEndpoint(FunctionalTest):
54
             status=400,
58
             status=400,
55
             params=params,
59
             params=params,
56
         )
60
         )
61
+        assert isinstance(res.json, dict)
62
+        assert 'code' in res.json.keys()
63
+        assert 'message' in res.json.keys()
64
+        assert 'details' in res.json.keys()
57
 
65
 
58
     def test_api__try_login_enpoint__err_400__unregistered_user(self):
66
     def test_api__try_login_enpoint__err_400__unregistered_user(self):
59
         params = {
67
         params = {
65
             status=400,
73
             status=400,
66
             params=params,
74
             params=params,
67
         )
75
         )
76
+        assert isinstance(res.json, dict)
77
+        assert 'code' in res.json.keys()
78
+        assert 'message' in res.json.keys()
79
+        assert 'details' in res.json.keys()
68
 
80
 
69
     def test_api__try_login_enpoint__err_400__no_json_body(self):
81
     def test_api__try_login_enpoint__err_400__no_json_body(self):
70
         res = self.testapp.post_json('/api/v2/sessions/login', status=400)
82
         res = self.testapp.post_json('/api/v2/sessions/login', status=400)
83
+        assert isinstance(res.json, dict)
84
+        assert 'code' in res.json.keys()
85
+        assert 'message' in res.json.keys()
86
+        assert 'details' in res.json.keys()
71
 
87
 
72
 
88
 
73
 class TestWhoamiEndpoint(FunctionalTest):
89
 class TestWhoamiEndpoint(FunctionalTest):
100
             )
116
             )
101
         )
117
         )
102
         res = self.testapp.get('/api/v2/sessions/whoami', status=401)
118
         res = self.testapp.get('/api/v2/sessions/whoami', status=401)
119
+        assert isinstance(res.json, dict)
120
+        assert 'code' in res.json.keys()
121
+        assert 'message' in res.json.keys()
122
+        assert 'details' in res.json.keys()