示例#1
0
    def test_my_account_remove_api_key(self):
        usr = self.log_user(base.TEST_USER_REGULAR2_LOGIN,
                            base.TEST_USER_REGULAR2_PASS)
        user = User.get(usr['user_id'])
        response = self.app.post(
            base.url('my_account_api_keys'), {
                'description': 'desc',
                'lifetime': -1,
                '_session_csrf_secret_token': self.session_csrf_secret_token()
            })
        self.checkSessionFlash(response, 'API key successfully created')
        response = response.follow()

        # now delete our key
        keys = UserApiKeys.query().all()
        assert 1 == len(keys)

        response = self.app.post(
            base.url('my_account_api_keys_delete'), {
                'del_api_key': keys[0].api_key,
                '_session_csrf_secret_token': self.session_csrf_secret_token()
            })
        self.checkSessionFlash(response, 'API key successfully deleted')
        keys = UserApiKeys.query().all()
        assert 0 == len(keys)
示例#2
0
    def test_remove_api_key(self):
        self.log_user()
        user = User.get_by_username(base.TEST_USER_REGULAR_LOGIN)
        user_id = user.user_id

        response = self.app.post(
            base.url('edit_user_api_keys_update', id=user_id), {
                'description': 'desc',
                'lifetime': -1,
                '_session_csrf_secret_token': self.session_csrf_secret_token()
            })
        self.checkSessionFlash(response, 'API key successfully created')
        response = response.follow()

        # now delete our key
        keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
        assert 1 == len(keys)

        response = self.app.post(
            base.url('edit_user_api_keys_delete', id=user_id), {
                'del_api_key': keys[0].api_key,
                '_session_csrf_secret_token': self.session_csrf_secret_token()
            })
        self.checkSessionFlash(response, 'API key successfully deleted')
        keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
        assert 0 == len(keys)
示例#3
0
 def get_api_keys(self, user, show_expired=True):
     user = User.guess_instance(user)
     user_api_keys = UserApiKeys.query() \
         .filter(UserApiKeys.user_id == user.user_id)
     if not show_expired:
         user_api_keys = user_api_keys.filter_by(is_expired=False)
     return user_api_keys
示例#4
0
    def _get_api_keys(self):
        api_keys = [self.api_key]
        for api_key in UserApiKeys.query() \
                .filter_by(user_id=self.user_id, is_expired=False):
            api_keys.append(api_key.api_key)

        return api_keys
示例#5
0
 def get_api_keys(self, user, show_expired=True):
     user = User.guess_instance(user)
     user_api_keys = UserApiKeys.query() \
         .filter(UserApiKeys.user_id == user.user_id)
     if not show_expired:
         user_api_keys = user_api_keys.filter_by(is_expired=False)
     return user_api_keys
示例#6
0
    def _get_api_keys(self):
        api_keys = [self.api_key]
        for api_key in UserApiKeys.query() \
                .filter_by(user_id=self.user_id, is_expired=False):
            api_keys.append(api_key.api_key)

        return api_keys
    def test_my_account_remove_api_key(self):
        usr = self.log_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS)
        user = User.get(usr['user_id'])
        response = self.app.post(url('my_account_api_keys'),
                                 {'description': 'desc', 'lifetime': -1, '_authentication_token': self.authentication_token()})
        self.checkSessionFlash(response, 'API key successfully created')
        response = response.follow()

        #now delete our key
        keys = UserApiKeys.query().all()
        assert 1 == len(keys)

        response = self.app.post(url('my_account_api_keys_delete'),
                 {'del_api_key': keys[0].api_key, '_authentication_token': self.authentication_token()})
        self.checkSessionFlash(response, 'API key successfully deleted')
        keys = UserApiKeys.query().all()
        assert 0 == len(keys)
示例#8
0
    def test_my_account_remove_api_key(self):
        usr = self.log_user('test_regular2', 'test12')
        user = User.get(usr['user_id'])
        response = self.app.post(url('my_account_api_keys'),
                                 {'description': 'desc', 'lifetime': -1})
        self.checkSessionFlash(response, 'Api key successfully created')
        response = response.follow()

        #now delete our key
        keys = UserApiKeys.query().all()
        self.assertEqual(1, len(keys))

        response = self.app.post(url('my_account_api_keys'),
                 {'_method': 'delete', 'del_api_key': keys[0].api_key})
        self.checkSessionFlash(response, 'Api key successfully deleted')
        keys = UserApiKeys.query().all()
        self.assertEqual(0, len(keys))
示例#9
0
    def get_api_keys(self):
        api_keys = [self.api_key]
        for api_key in UserApiKeys.query()\
                .filter(UserApiKeys.user_id == self.user_id)\
                .filter(or_(UserApiKeys.expires == -1,
                            UserApiKeys.expires >= time.time())).all():
            api_keys.append(api_key.api_key)

        return api_keys
示例#10
0
    def get_api_keys(self):
        api_keys = [self.api_key]
        for api_key in UserApiKeys.query()\
                .filter(UserApiKeys.user_id == self.user_id)\
                .filter(or_(UserApiKeys.expires == -1,
                            UserApiKeys.expires >= time.time())).all():
            api_keys.append(api_key.api_key)

        return api_keys
示例#11
0
 def get_api_keys(self, user, show_expired=True):
     user = self._get_user(user)
     user_api_keys = UserApiKeys.query()\
         .filter(UserApiKeys.user_id == user.user_id)
     if not show_expired:
         user_api_keys = user_api_keys\
             .filter(or_(UserApiKeys.expires == -1,
                         UserApiKeys.expires >= time.time()))
     return user_api_keys
    def test_remove_api_key(self):
        self.log_user()
        user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
        user_id = user.user_id

        response = self.app.post(url('edit_user_api_keys_update', id=user_id),
                {'description': 'desc', 'lifetime': -1, '_authentication_token': self.authentication_token()})
        self.checkSessionFlash(response, 'API key successfully created')
        response = response.follow()

        #now delete our key
        keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
        assert 1 == len(keys)

        response = self.app.post(url('edit_user_api_keys_delete', id=user_id),
                 {'del_api_key': keys[0].api_key, '_authentication_token': self.authentication_token()})
        self.checkSessionFlash(response, 'API key successfully deleted')
        keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
        assert 0 == len(keys)
示例#13
0
    def test_remove_api_key(self):
        self.log_user()
        user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
        user_id = user.user_id

        response = self.app.post(url('edit_user_api_keys', id=user_id),
                {'_method': 'put', 'description': 'desc', 'lifetime': -1})
        self.checkSessionFlash(response, 'Api key successfully created')
        response = response.follow()

        #now delete our key
        keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
        self.assertEqual(1, len(keys))

        response = self.app.post(url('edit_user_api_keys', id=user_id),
                 {'_method': 'delete', 'del_api_key': keys[0].api_key})
        self.checkSessionFlash(response, 'Api key successfully deleted')
        keys = UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all()
        self.assertEqual(0, len(keys))
示例#14
0
    def test_my_account_remove_api_key(self):
        usr = self.log_user('test_regular2', 'test12')
        user = User.get(usr['user_id'])
        response = self.app.post(url('my_account_api_keys'), {
            'description': 'desc',
            'lifetime': -1
        })
        self.checkSessionFlash(response, 'Api key successfully created')
        response = response.follow()

        #now delete our key
        keys = UserApiKeys.query().all()
        self.assertEqual(1, len(keys))

        response = self.app.post(url('my_account_api_keys'), {
            '_method': 'delete',
            'del_api_key': keys[0].api_key
        })
        self.checkSessionFlash(response, 'Api key successfully deleted')
        keys = UserApiKeys.query().all()
        self.assertEqual(0, len(keys))
示例#15
0
    def delete(self, api_key, user=None):
        """
        Deletes given api_key, if user is set it also filters the object for
        deletion by given user.
        """
        api_key = UserApiKeys.query().filter(UserApiKeys.api_key == api_key)

        if user is not None:
            user = User.guess_instance(user)
            api_key = api_key.filter(UserApiKeys.user_id == user.user_id)

        api_key = api_key.scalar()
        Session().delete(api_key)
示例#16
0
    def delete(self, api_key, user=None):
        """
        Deletes given api_key, if user is set it also filters the object for
        deletion by given user.
        """
        api_key = UserApiKeys.query().filter(UserApiKeys.api_key == api_key)

        if user:
            user = self._get_user(user)
            api_key = api_key.filter(UserApiKeys.user_id == user.user_id)

        api_key = api_key.scalar()
        Session().delete(api_key)
示例#17
0
 def test_my_account_add_api_keys(self, desc, lifetime):
     usr = self.log_user('test_regular2', 'test12')
     user = User.get(usr['user_id'])
     response = self.app.post(url('my_account_api_keys'),
                              {'description': desc, 'lifetime': lifetime})
     self.checkSessionFlash(response, 'Api key successfully created')
     try:
         response = response.follow()
         user = User.get(usr['user_id'])
         for api_key in user.api_keys:
             response.mustcontain(api_key)
     finally:
         for api_key in UserApiKeys.query().all():
             Session().delete(api_key)
             Session().commit()
示例#18
0
 def test_my_account_add_api_keys(self, desc, lifetime):
     usr = self.log_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS)
     user = User.get(usr['user_id'])
     response = self.app.post(url('my_account_api_keys'),
                              {'description': desc, 'lifetime': lifetime, '_authentication_token': self.authentication_token()})
     self.checkSessionFlash(response, 'API key successfully created')
     try:
         response = response.follow()
         user = User.get(usr['user_id'])
         for api_key in user.api_keys:
             response.mustcontain(api_key)
     finally:
         for api_key in UserApiKeys.query().all():
             Session().delete(api_key)
             Session().commit()
示例#19
0
 def test_my_account_add_api_keys(self, desc, lifetime):
     usr = self.log_user('test_regular2', 'test12')
     user = User.get(usr['user_id'])
     response = self.app.post(url('my_account_api_keys'), {
         'description': desc,
         'lifetime': lifetime
     })
     self.checkSessionFlash(response, 'Api key successfully created')
     try:
         response = response.follow()
         user = User.get(usr['user_id'])
         for api_key in user.api_keys:
             response.mustcontain(api_key)
     finally:
         for api_key in UserApiKeys.query().all():
             Session().delete(api_key)
             Session().commit()
示例#20
0
    def test_add_api_keys(self, desc, lifetime):
        self.log_user()
        user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
        user_id = user.user_id

        response = self.app.post(url('edit_user_api_keys', id=user_id),
                 {'_method': 'put', 'description': desc, 'lifetime': lifetime})
        self.checkSessionFlash(response, 'Api key successfully created')
        try:
            response = response.follow()
            user = User.get(user_id)
            for api_key in user.api_keys:
                response.mustcontain(api_key)
        finally:
            for api_key in UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all():
                Session().delete(api_key)
                Session().commit()
示例#21
0
 def test_my_account_add_api_keys(self, desc, lifetime):
     usr = self.log_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS)
     user = User.get(usr['user_id'])
     response = self.app.post(
         url('my_account_api_keys'), {
             'description': desc,
             'lifetime': lifetime,
             '_authentication_token': self.authentication_token()
         })
     self.checkSessionFlash(response, 'API key successfully created')
     try:
         response = response.follow()
         user = User.get(usr['user_id'])
         for api_key in user.api_keys:
             response.mustcontain(api_key)
     finally:
         for api_key in UserApiKeys.query().all():
             Session().delete(api_key)
             Session().commit()