def test_list_actions(self):
     user_log.log_user_action(self.user_object.id, action='/testaction')
     action = user_log.list_actions(user=self.user_object)
     self.assertIsNotNone(action)
     expected = {'action': '/testaction', 'user_id': 1}
     self.assertTrue(
         all(item in action[0].items() for item in expected.items()))
 def test_list_user_actions(self):
     user_log.log_user_action(self.user_object.id, action='/users/login')
     user_action = user_log.list_user_actions(self.user_object.id,
                                              user=self.user_object)
     expected = {'action': '/users/login', 'user_id': 1}
     self.assertTrue(
         all(item in user_action[0].items() for item in expected.items()))
Example #3
0
def logout():
    """User logout."""
    user_log_api.log_user_action(current_user, request.path)
    user_api.clean_user_token(
        current_user, current_user.token
    )
    logout_user()
Example #4
0
 def test_list_actions(self):
     user_log.log_user_action(
         self.user_object.id,
         action='/testaction'
     )
     action = user_log.list_actions(self.user_object)
     self.assertIsNotNone(action)
Example #5
0
def _login(use_cookie):
    """User login helper function."""
    data = _get_request_data()
    if 'email' not in data or 'password' not in data:
        raise exception_handler.BadRequest(
            'missing email or password in data'
        )
    if 'expires' not in data:
        expire_timestamp = (
            datetime.datetime.now() + app.config['REMEMBER_COOKIE_DURATION']
        )
    else:
        expire_timestamp = util.parse_datetime(
            data['expires'], exception_handler.BadRequest
        )

    data['expire_timestamp'] = expire_timestamp
    user = auth_handler.authenticate_user(**data)
    if not login_user(user, remember=data.get('remember', False)):
        raise exception_handler.UserDisabled('failed to login: %s' % user)

    user_log_api.log_user_action(user.id, request.path)
    response_data = {'id': user.id}
    user_api.record_user_token(
        user, user.token, user.expire_timestamp
    )
    if not use_cookie:
        response_data['token'] = user.token
        response_data['expires'] = util.format_datetime(user.expire_timestamp)

    return utils.make_json_response(200, response_data)
Example #6
0
 def test_list_none_user_actions(self):
     user_log.log_user_action(
         self.user_object.id,
         action='/testaction'
     )
     user_action = user_log.list_user_actions(
         2,
         user=self.user_object
     )
     self.assertEqual([], user_action)
Example #7
0
 def test_list_none_user_actions(self):
     user_log.log_user_action(
         self.user_object.id,
         action='/testaction'
     )
     self.assertRaises(
         exception.RecordNotExists,
         user_log.list_user_actions,
         2, user=self.user_object
     )
Example #8
0
 def test_del_actions(self):
     user_log.log_user_action(
         self.user_object.id,
         action='/testaction'
     )
     user_log.del_actions(
         user=self.user_object
     )
     del_action = user_log.list_actions(
         user=self.user_object
     )
     self.assertEqual([], del_action)
Example #9
0
 def test_list_user_actions(self):
     user_log.log_user_action(
         self.user_object.id,
         action='/testaction'
     )
     user_action = user_log.list_user_actions(
         self.user_object,
         self.user_object.id
     )
     self.assertEqual(
         1,
         user_action[0]['user_id']
     )
Example #10
0
 def test_list_actions(self):
     user_log.log_user_action(
         self.user_object.id,
         action='/testaction'
     )
     action = user_log.list_actions(user=self.user_object)
     self.assertIsNotNone(action)
     expected = {
         'action': '/testaction',
         'user_id': 1
     }
     self.assertTrue(
         all(item in action[0].items()
             for item in expected.items()))
Example #11
0
 def test_list_user_actions(self):
     user_log.log_user_action(
         self.user_object.id,
         action='/users/login'
     )
     user_action = user_log.list_user_actions(
         self.user_object.id,
         user=self.user_object
     )
     expected = {
         'action': '/users/login',
         'user_id': 1
     }
     self.assertTrue(
         all(item in user_action[0].items()
             for item in expected.items()))
Example #12
0
 def test_del_actions(self):
     user_log.log_user_action(self.user_object.id, action='/testaction')
     user_log.del_actions(user=self.user_object)
     del_action = user_log.list_actions(user=self.user_object)
     self.assertEqual([], del_action)
Example #13
0
 def test_list_none_user_actions(self):
     user_log.log_user_action(self.user_object.id, action='/testaction')
     self.assertRaises(exception.RecordNotExists,
                       user_log.list_user_actions,
                       2,
                       user=self.user_object)
Example #14
0
 def decorated_api(*args, **kwargs):
     user_log_api.log_user_action(current_user.id, request.path)
     return func(*args, **kwargs)