Fixing project validation on hooks app

remotes/origin/issue/4795/notification_even_they_are_disabled
Alejandro Alonso 2016-10-17 10:47:48 +02:00
parent b78d1b9a26
commit be55c5cb58
2 changed files with 14 additions and 1 deletions

View File

@ -44,7 +44,7 @@ class BaseWebhookApiViewSet(GenericViewSet):
try: try:
project = Project.objects.get(id=project_id) project = Project.objects.get(id=project_id)
return project return project
except Project.DoesNotExist: except (ValueError, Project.DoesNotExist):
return None return None
def _get_payload(self, request): def _get_payload(self, request):

View File

@ -43,6 +43,19 @@ from .. import factories as f
pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
def test_bad_project(client):
project = f.ProjectFactory()
url = reverse("github-hook-list")
url = "%s?project=%s-extra-text-added" % (url, project.id)
data = {"test:": "data"}
response = client.post(url, json.dumps(data),
HTTP_X_HUB_SIGNATURE="sha1=3c8e83fdaa266f81c036ea0b71e98eb5e054581a",
content_type="application/json")
response_content = response.data
assert response.status_code == 400
assert "The project doesn't exist" in response_content["_error_message"]
def test_bad_signature(client): def test_bad_signature(client):
project = f.ProjectFactory() project = f.ProjectFactory()
url = reverse("github-hook-list") url = reverse("github-hook-list")