Browse Source

return user object with login endpoint instead of no content

Guénaël Muller 6 years ago
parent
commit
1726a50321

+ 11 - 2
tracim/tests/functional/test_session.py View File

@@ -37,7 +37,7 @@ class TestLoginEndpointUnititedDB(FunctionalTestNoDB):
37 37
 
38 38
 class TestLoginEndpoint(FunctionalTest):
39 39
 
40
-    def test_api__try_login_enpoint__ok_204__nominal_case(self):
40
+    def test_api__try_login_enpoint__ok_200__nominal_case(self):
41 41
         params = {
42 42
             'email': 'admin@admin.admin',
43 43
             'password': 'admin@admin.admin',
@@ -45,8 +45,17 @@ class TestLoginEndpoint(FunctionalTest):
45 45
         res = self.testapp.post_json(
46 46
             '/api/v2/sessions/login',
47 47
             params=params,
48
-            status=204,
48
+            status=200,
49 49
         )
50
+        assert res.json_body['display_name'] == 'Global manager'
51
+        assert res.json_body['email'] == 'admin@admin.admin'
52
+        assert res.json_body['created']
53
+        assert res.json_body['is_active']
54
+        assert res.json_body['profile']
55
+        assert isinstance(res.json_body['profile']['id'], int)
56
+        assert res.json_body['profile']['slug'] == 'administrators'
57
+        assert res.json_body['caldav_url'] is None
58
+        assert res.json_body['avatar_url'] is None
50 59
 
51 60
     def test_api__try_login_enpoint__err_400__bad_password(self):
52 61
         params = {

+ 4 - 2
tracim/views/core_api/session_controller.py View File

@@ -25,7 +25,8 @@ class SessionController(Controller):
25 25
     @hapic.handle_exception(AuthenticationFailed, HTTPStatus.BAD_REQUEST)
26 26
     # TODO - G.M - 17-04-2018 - fix output header ?
27 27
     # @hapic.output_headers()
28
-    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
28
+    @hapic.output_body(UserSchema(),)
29
+    #@hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
29 30
     def login(self, context, request: TracimRequest, hapic_data=None):
30 31
         """
31 32
         Logs user into the system
@@ -38,7 +39,8 @@ class SessionController(Controller):
38 39
             session=request.dbsession,
39 40
             config=app_config,
40 41
         )
41
-        return uapi.authenticate_user(login.email, login.password)
42
+        user = uapi.authenticate_user(login.email, login.password)
43
+        return uapi.get_user_with_context(user)
42 44
 
43 45
     @hapic.with_api_doc()
44 46
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8