Add tests for github webhook
This commit is contained in:
parent
c1fe8ca16a
commit
a090c6160e
3 changed files with 70 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ test = [
|
|||
"pytest",
|
||||
"pytest-cov",
|
||||
"pytest-dotenv",
|
||||
"pytest-mock",
|
||||
]
|
||||
mypy = [
|
||||
"mypy",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ pyparsing==2.4.7
|
|||
pytest==6.2.5
|
||||
pytest-cov==3.0.0
|
||||
pytest-dotenv==0.5.2
|
||||
pytest-mock==3.6.1
|
||||
python-dotenv==0.19.2
|
||||
toml==0.10.2
|
||||
tomli==1.2.2
|
||||
|
|
|
|||
68
tests/test_webhook.py
Normal file
68
tests/test_webhook.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from runboat.app import app
|
||||
from runboat.controller import controller
|
||||
from runboat.github import CommitInfo
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_webhook_github_push(mocker: MockerFixture) -> None:
|
||||
mock = mocker.patch("fastapi.BackgroundTasks.add_task")
|
||||
response = client.post(
|
||||
"/webhooks/github",
|
||||
headers={
|
||||
"X-GitHub-Event": "push",
|
||||
},
|
||||
json={
|
||||
"repository": {"full_name": "oca/mis-builder"},
|
||||
"ref": "refs/heads/15.0",
|
||||
"after": "abcde",
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
mock.assert_called_with(
|
||||
controller.deploy_or_start,
|
||||
CommitInfo(
|
||||
repo="oca/mis-builder",
|
||||
target_branch="15.0",
|
||||
pr=None,
|
||||
git_commit="abcde",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("action", ["opened", "synchronize"])
|
||||
def test_webhook_github_pr_open_synchronize(action: str, mocker: MockerFixture) -> None:
|
||||
mock = mocker.patch("fastapi.BackgroundTasks.add_task")
|
||||
response = client.post(
|
||||
"/webhooks/github",
|
||||
headers={
|
||||
"X-GitHub-Event": "pull_request",
|
||||
},
|
||||
json={
|
||||
"action": action,
|
||||
"repository": {"full_name": "oca/mis-builder"},
|
||||
"pull_request": {
|
||||
"base": {
|
||||
"ref": "15.0",
|
||||
},
|
||||
"number": 381,
|
||||
"head": {
|
||||
"sha": "abcde",
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
mock.assert_called_with(
|
||||
controller.deploy_or_start,
|
||||
CommitInfo(
|
||||
repo="oca/mis-builder",
|
||||
target_branch="15.0",
|
||||
pr=381,
|
||||
git_commit="abcde",
|
||||
),
|
||||
)
|
||||
Loading…
Reference in a new issue