Bladeren bron

return user object with login endpoint instead of no content

Guénaël Muller 6 jaren geleden
bovenliggende
commit
1726a50321
2 gewijzigde bestanden met toevoegingen van 15 en 4 verwijderingen
  1. 11 2
      tracim/tests/functional/test_session.py
  2. 4 2
      tracim/views/core_api/session_controller.py

+ 11 - 2
tracim/tests/functional/test_session.py Bestand weergeven

37
 
37
 
38
 class TestLoginEndpoint(FunctionalTest):
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
         params = {
41
         params = {
42
             'email': 'admin@admin.admin',
42
             'email': 'admin@admin.admin',
43
             'password': 'admin@admin.admin',
43
             'password': 'admin@admin.admin',
45
         res = self.testapp.post_json(
45
         res = self.testapp.post_json(
46
             '/api/v2/sessions/login',
46
             '/api/v2/sessions/login',
47
             params=params,
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
     def test_api__try_login_enpoint__err_400__bad_password(self):
60
     def test_api__try_login_enpoint__err_400__bad_password(self):
52
         params = {
61
         params = {

+ 4 - 2
tracim/views/core_api/session_controller.py Bestand weergeven

25
     @hapic.handle_exception(AuthenticationFailed, HTTPStatus.BAD_REQUEST)
25
     @hapic.handle_exception(AuthenticationFailed, HTTPStatus.BAD_REQUEST)
26
     # TODO - G.M - 17-04-2018 - fix output header ?
26
     # TODO - G.M - 17-04-2018 - fix output header ?
27
     # @hapic.output_headers()
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
     def login(self, context, request: TracimRequest, hapic_data=None):
30
     def login(self, context, request: TracimRequest, hapic_data=None):
30
         """
31
         """
31
         Logs user into the system
32
         Logs user into the system
38
             session=request.dbsession,
39
             session=request.dbsession,
39
             config=app_config,
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
     @hapic.with_api_doc()
45
     @hapic.with_api_doc()
44
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
46
     @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8