コード例 #1
0
def slackify_test():
    app = Flask(__name__)
    slackify = Slackify(app=app)

    @slackify.event('reaction_added')
    def react_to_reaction(payload):
        return '🐍'

    return slackify
コード例 #2
0
def test_injector_with_blueprint():
    bp = Blueprint('TestBlueprint', __name__, url_prefix='/bp_url_prefix')
    slackify = Slackify(app=bp, endpoint='/slack')

    @slackify.command
    def greeting(command):
        return f'I am {command}'

    app = Flask('Bare')
    app.register_blueprint(bp)

    with app.test_client() as client:
        rv = client.post('/bp_url_prefix/slack',
                         data={'command': '/greeting'},
                         content_type='application/x-www-form-urlencoded')
        assert b'I am /greeting' == rv.data, rv.data
コード例 #3
0
ファイル: test_blueprint.py プロジェクト: fakegit/slackify
def test_we_can_add_a_custom_endpoint_besides_blueprint_prefix():
    bp = Blueprint('TestBlueprint', __name__, url_prefix='/blueprintBla')
    slackify = Slackify(app=bp, endpoint='/slack')

    @slackify.command
    def hello():
        return 'Hello from special endpoint'

    app = Flask('Bare')
    app.register_blueprint(bp)

    client = app.test_client()
    rv = client.post('/blueprintBla/slack',
                     data={'command': '/hello'},
                     content_type='application/x-www-form-urlencoded')
    assert rv.status == '200 OK'
    assert rv.data == b'Hello from special endpoint'
コード例 #4
0
ファイル: test_blueprint.py プロジェクト: fakegit/slackify
def client():
    bp = Blueprint('TestBlueprint', __name__, url_prefix='/blueprintBla')
    slackify = Slackify(app=bp)

    @slackify.command
    def hello():
        return 'Hello from blueprint'

    @slackify.command(methods=('POST', 'GET'))
    def bye():
        return 'Bye from blueprint'

    app = Flask('Main')
    app.register_blueprint(bp)

    with app.test_client() as cli:
        yield cli
コード例 #5
0
def test_app():
    app = Flask(__name__)
    slackify = Slackify(app=app)

    @slackify.command(name='chau')
    def hello():
        return 'Hello'

    @slackify.command
    def goodbye():
        return 'Bye'

    @slackify.shortcut('my-shortcut')
    def shortcut():
        return 'Shortcut'

    @slackify.action('my-action-id')
    def my_action():
        return 'Action'

    @slackify.action(action_id='the-id', block_id='a-block-id')
    def complex_action():
        return 'Complex Action'

    @slackify.view('my-first-view')
    def my_view():
        return 'View'

    @slackify.default
    def unknown_command():
        return 'Unknown Command'

    @slackify.event('reaction_added')
    def react_to_reaction(payload):
        return '🐍'

    return app
コード例 #6
0
ファイル: home_tab.py プロジェクト: fakegit/slackify
import os
from flask import Flask
from slackify import Slackify, request, reply_text, Slack, ACK

# Initialize App
app = Flask(__name__)
slackify = Slackify(app=app)
cli = Slack(os.getenv('SLACK_BOT_TOKEN'))


@slackify.command
def update_home_view():
    user = request.form['user_id']
    sample = {
        "type": "home",
        "blocks": [
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "A simple stack of blocks for the simple sample Block Kit Home tab."
                }
            },
            {
                "type": "actions",
                "elements": [
                    {
                        "type": "button",
                        "action_id": "tell_joke",
                        "text": {
                            "type": "plain_text",
コード例 #7
0
def test_app():
    return Slackify()
コード例 #8
0
ファイル: test_blueprint.py プロジェクト: fakegit/slackify
def test_we_cant_use_a_bp_with_no_url_prefix():
    with pytest.raises(ValueError, match="Missing required 'url_prefix' for blueprint TestBlueprint"):
        no_prefix_bp = Blueprint('TestBlueprint', __name__)
        Slackify(app=no_prefix_bp)
コード例 #9
0
def bare_app():
    return Slackify()
コード例 #10
0
# slack_blueprint.py
from flask import Blueprint
from slackify import Slackify, reply_text

bp = Blueprint('slackify_bp', __name__, url_prefix='/slack')
slackify = Slackify(app=bp)


@slackify.command
def hello():
    return reply_text('Hello from a blueprint')


# app.py
from flask import Flask
# from slack_blueprint import bp

def create_app():
    app = Flask(__name__)
    app.register_blueprint(bp)
    return app