def test_override_token_post(): responses.add(responses.POST, "https://slack.com/api/chat.postMessage") app = Flask(__name__) slack_bp = make_slack_blueprint( client_id="foo", client_secret="bar", backend=MemoryBackend({"access_token": "abcde"}), ) app.register_blueprint(slack_bp, url_prefix="/login") with app.test_request_context("/"): app.preprocess_request() resp = slack.post("chat.postMessage", data={ "token": "xyz", "channel": "#general", "text": "ping", "icon_emoji": ":robot_face:", }) request_data = url_decode(resp.request.body) assert request_data["token"] == "xyz" assert request_data["channel"] == "#general" assert request_data["text"] == "ping" assert request_data["icon_emoji"] == ":robot_face:" # should not be present url = URLObject(resp.request.url) assert "token" not in url.query_dict
def test_override_token_post(make_app): responses.add(responses.POST, "https://slack.com/api/chat.postMessage") app = make_app( client_id="foo", client_secret="bar", storage=MemoryStorage({"access_token": "abcde"}), ) with app.test_request_context("/"): app.preprocess_request() resp = slack.post( "chat.postMessage", data={ "token": "xyz", "channel": "#general", "text": "ping", "icon_emoji": ":robot_face:", }, ) request_data = url_decode(resp.request.body) assert request_data["token"] == "xyz" assert request_data["channel"] == "#general" assert request_data["text"] == "ping" assert request_data["icon_emoji"] == ":robot_face:" # should not be present url = URLObject(resp.request.url) assert "token" not in url.query_dict
def test_auto_token_post(make_app): responses.add(responses.POST, "https://slack.com/api/chat.postMessage") app = make_app( client_id="foo", client_secret="bar", storage=MemoryStorage({"access_token": "abcde"}), ) with app.test_request_context("/"): app.preprocess_request() resp = slack.post( "chat.postMessage", data={ "channel": "#general", "text": "ping", "icon_emoji": ":robot_face:" }, ) request_data = url_decode(resp.request.body) assert request_data["channel"] == "#general" assert request_data["text"] == "ping" assert request_data["icon_emoji"] == ":robot_face:" # the `token` parameter should have been automatically added assert request_data["token"] == "abcde"
def test_auto_token_post(): responses.add(responses.POST, "https://slack.com/api/chat.postMessage") app = Flask(__name__) slack_bp = make_slack_blueprint( client_id="foo", client_secret="bar", backend=MemoryBackend({"access_token": "abcde"}), ) app.register_blueprint(slack_bp, url_prefix="/login") with app.test_request_context("/"): app.preprocess_request() resp = slack.post("chat.postMessage", data={ "channel": "#general", "text": "ping", "icon_emoji": ":robot_face:", }) request_data = url_decode(resp.request.body) assert request_data["channel"] == "#general" assert request_data["text"] == "ping" assert request_data["icon_emoji"] == ":robot_face:" # the `token` parameter should have been automatically added assert request_data["token"] == "abcde"
def check_validate_with_auth_test(token): headers = { 'Content-type': 'application/json; charset=utf-8', } response = slack.post('/api/auth.test', headers=headers, data=json.dumps({'token': token})) print(response.request.headers) print(response.request.body) print(response.json()) return response.json()['ok']
def index(): if not slack.authorized: return redirect(url_for("slack.login")) resp = slack.post("chat.postMessage", data={ "channel": "#general", "text": "ping", "icon_emoji": ":robot_face:", }) assert resp.ok, resp.text return resp.text
def create(): if not slack.authorized: return redirect(url_for("slack.login")) resp = slack.post("chat.postMessage", data={ "text": 'HeyBooster!', "channel": "#general", "icon_emoji": ":male-technologist:", }) print('TOKEN: ', slack.token) txt = resp.text username = request.form.get('username') mongo.db.user.insert_one({'username': username, 'text': txt}) assert resp.json()["ok"], resp.text return redirect('/')
def test_auto_token_post_no_token(make_app): responses.add(responses.POST, "https://slack.com/api/chat.postMessage") app = make_app(client_id="foo", client_secret="bar") with app.test_request_context("/"): app.preprocess_request() resp = slack.post( "chat.postMessage", data={"channel": "#general", "text": "ping", "icon_emoji": ":robot_face:"}, ) request_data = url_decode(resp.request.body) assert request_data["channel"] == "#general" assert request_data["text"] == "ping" assert request_data["icon_emoji"] == ":robot_face:" assert "token" not in request_data url = URLObject(resp.request.url) assert "token" not in url.query_dict
def revoke(): response = slack.post('/api/auth.revoke?token={}'.format(slack.token['access_token'])) return 'api key를 revoke 했습니다.'