def remove(self): self.token.remove() cache.delete(third_party_settings.ACCESS_TOKEN_CACHE_KEY % self.token.uid) return self.json_ok()
def accept(self): self.token.accept(self.account) cache.delete(third_party_settings.ACCESS_TOKEN_CACHE_KEY % self.token.uid) return self.json_ok()
def remove_all(self): tokens = prototypes.AccessTokenPrototype.get_list_by_account_id( self.account.id) for token in tokens: token.remove() cache.delete(third_party_settings.ACCESS_TOKEN_CACHE_KEY % token.uid) return self.json_ok()
def test_full__accepted(self): api_client = Client() request_token_url = url('accounts:third-party:tokens:request-authorisation', api_version='1.0', api_client=project_settings.API_CLIENT) response = api_client.post(request_token_url, {'application_name': 'app-name', 'application_info': 'app-info', 'application_description': 'app-descr'}) self.check_ajax_ok(response) token_url = s11n.from_json(response.content.decode('utf-8'))['data']['authorisation_page'] token = prototypes.AccessTokenPrototype._db_latest() self.assertEqual(url('accounts:third-party:tokens:show', token.uid), token_url) self.check_html_ok(self.request_html(token_url), texts=['app-name', 'app-info', 'app-descr']) authorisation_state_url = url('accounts:third-party:tokens:authorisation-state', api_version='1.0', api_client=project_settings.API_CLIENT) self.check_ajax_ok(api_client.get(authorisation_state_url), data={'account_id': None, 'account_name': None, 'state': relations.AUTHORISATION_STATE.UNPROCESSED.value, 'session_expire_at': 666.6}) # emulate accept view token.accept(self.account_1) cache.delete(third_party_settings.ACCESS_TOKEN_CACHE_KEY % token.uid) self.check_ajax_ok(api_client.get(authorisation_state_url), data={'account_id': self.account_1.id, 'account_name': self.account_1.nick_verbose, 'state': relations.AUTHORISATION_STATE.ACCEPTED.value, 'session_expire_at': 666.6}) self.assertIn('_auth_user_id', api_client.session) self.assertIn(third_party_settings.ACCESS_TOKEN_SESSION_KEY, api_client.session) self.check_ajax_ok(api_client.post(logout_url())) self.assertNotIn('_auth_user_id', api_client.session) self.assertEqual(prototypes.AccessTokenPrototype.get_by_uid(token.uid), None) self.assertNotIn(third_party_settings.ACCESS_TOKEN_SESSION_KEY, api_client.session)