Пример #1
0
    def test_call_custom_hook(self, app):
        webhook = GithubWebhook()
        webhook.init_app(app)
        cli = app.test_client()
        endpoint = app.config["GITHUB_WEBHOOK_ENDPOINT"]
        event = "pull_request"

        hook_test_data = {"request": {"key": "value"}, "hook_called": False}

        @webhook.hook(event_type=event)
        def pull_request_hook(data):
            hook_test_data["hook_called"] = True

            assert data is not None

            assert len(
                set(data.keys()).difference(
                    set(hook_test_data["request"].keys()))) == 0
            for key, value in data.items():
                assert hook_test_data["request"][key] == value

        response = cli.post(endpoint,
                            github_event=event,
                            json=hook_test_data["request"])

        assert response.status_code == 204
        assert hook_test_data["hook_called"]
Пример #2
0
    def test_default_config(self, app):
        webhook = GithubWebhook()
        webhook.init_app(app)

        assert len(
            [a for a in app.url_map.iter_rules(endpoint="/postreceive")]) == 1
        assert app.extensions["github_webhook"] == webhook
        assert webhook._webhook._secret is None
Пример #3
0
    def test_register_default_hook(self, app):
        webhook = GithubWebhook()
        webhook.init_app(app)

        @webhook.hook()
        def push_hook(data):
            pass

        assert push_hook in webhook._webhook._hooks["push"]
Пример #4
0
    def test_register_custom_hook(self, app):
        webhook = GithubWebhook()
        webhook.init_app(app)

        @webhook.hook("pull_request")
        def pull_request_hook(data):
            pass

        assert pull_request_hook in webhook._webhook._hooks["pull_request"]
Пример #5
0
    def test_custom_config(self, app):
        endpoint = "/test_endpoint"
        secret = "sup3rsecret!"

        app.config["GITHUB_WEBHOOK_ENDPOINT"] = endpoint
        app.config["GITHUB_WEBHOOK_SECRET"] = secret

        webhook = GithubWebhook()
        webhook.init_app(app)

        assert len([a for a in app.url_map.iter_rules(endpoint=endpoint)]) == 1
        assert app.extensions["github_webhook"] == webhook
        assert webhook._webhook._secret == secret.encode("utf-8")
Пример #6
0
    def test_custom_config(self, app):
        endpoint = '/test_endpoint'
        secret = 'sup3rsecret!'

        app.config['GITHUB_WEBHOOK_ENDPOINT'] = endpoint
        app.config['GITHUB_WEBHOOK_SECRET'] = secret

        webhook = GithubWebhook()
        webhook.init_app(app)

        assert len([a for a in app.url_map.iter_rules(endpoint=endpoint)]) == 1
        assert app.extensions['github_webhook'] == webhook
        assert webhook._webhook._secret == secret.encode('utf-8')
Пример #7
0
from flask_jwt_extended import JWTManager
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_migrate import Migrate
from dotenv import load_dotenv
from flask_github_webhook import GithubWebhook
from flask_cors import CORS
from celery import Celery
from celery_utils import init_celery
import settings

db = SQLAlchemy(session_options={'expire_on_commit': False})
login_manager = LoginManager()
migrate = Migrate()
jwt = JWTManager()
WEBHOOK = GithubWebhook()
celery = Celery(__name__, broker=settings.CELERY_BROKER, include=['tasks'])


def create_app():
    load_dotenv()
    app = Flask(__name__, static_folder='static')
    app.config.from_object('settings')

    db.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)
    WEBHOOK.init_app(app)
    CORS(app)
    init_celery(celery, app)
Пример #8
0
    def test_extension_pattern_initialization(self, app):
        webhook = GithubWebhook()
        webhook.init_app(app)

        assert app.extensions["github_webhook"] == webhook
Пример #9
0
    def test_direct_initialization(self, app):
        webhook = GithubWebhook(app)

        assert app.extensions["github_webhook"] == webhook