Przeglądaj źródła

better test for error case : check response_body structure

Guénaël Muller 6 lat temu
rodzic
commit
1464da73d7
1 zmienionych plików z 20 dodań i 0 usunięć
  1. 20 0
      tracim/tests/functional/test_session.py

+ 20 - 0
tracim/tests/functional/test_session.py Wyświetl plik

@@ -29,6 +29,10 @@ class TestLoginEndpointUnititedDB(FunctionalTestNoDB):
29 29
             params=params,
30 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 38
 class TestLoginEndpoint(FunctionalTest):
@@ -54,6 +58,10 @@ class TestLoginEndpoint(FunctionalTest):
54 58
             status=400,
55 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 66
     def test_api__try_login_enpoint__err_400__unregistered_user(self):
59 67
         params = {
@@ -65,9 +73,17 @@ class TestLoginEndpoint(FunctionalTest):
65 73
             status=400,
66 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 81
     def test_api__try_login_enpoint__err_400__no_json_body(self):
70 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 89
 class TestWhoamiEndpoint(FunctionalTest):
@@ -100,3 +116,7 @@ class TestWhoamiEndpoint(FunctionalTest):
100 116
             )
101 117
         )
102 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()