コード例 #1
0
ファイル: test_views.py プロジェクト: st-tu-dresden/inloop
 def test_not_modified_when_ref_not_master(self, mock):
     data = b'{"ref": "refs/heads/develop"}'
     request = self.FACTORY.post("/", data=data, content_type="application/json")
     request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature(data, self.KEY)
     request.META["HTTP_X_GITHUB_EVENT"] = "push"
     response = webhook_handler(request)
     self.assertContains(response, "Event ignored")
     self.assertEqual(mock.call_count, 0)
コード例 #2
0
ファイル: test_views.py プロジェクト: st-tu-dresden/inloop
 def test_push_with_valid_signature(self, mock):
     data = b'{"ref": "refs/heads/master"}'
     request = self.FACTORY.post("/", data=data, content_type="application/json")
     request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature(data, self.KEY)
     request.META["HTTP_X_GITHUB_EVENT"] = "push"
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(mock.call_count, 1)
コード例 #3
0
 def test_not_modified_when_ref_not_master(self, mock):
     data = b'{"ref": "refs/heads/develop"}'
     request = self.FACTORY.post('/', data=data, content_type='application/json')
     request.META['HTTP_X_HUB_SIGNATURE'] = compute_signature(data, self.KEY)
     request.META['HTTP_X_GITHUB_EVENT'] = 'push'
     response = webhook_handler(request)
     self.assertContains(response, 'Event ignored')
     self.assertEqual(mock.call_count, 0)
コード例 #4
0
 def test_push_with_valid_signature(self, mock):
     data = b'{"ref": "refs/heads/master"}'
     request = self.FACTORY.post('/', data=data, content_type='application/json')
     request.META['HTTP_X_HUB_SIGNATURE'] = compute_signature(data, self.KEY)
     request.META['HTTP_X_GITHUB_EVENT'] = 'push'
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(mock.call_count, 1)
コード例 #5
0
ファイル: test_views.py プロジェクト: st-tu-dresden/inloop
 def test_push_with_invalid_json(self, mock):
     data = b'<xml-is-not-json/>'
     request = self.FACTORY.post("/", data=data, content_type="application/json")
     request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature(data, self.KEY)
     request.META["HTTP_X_GITHUB_EVENT"] = "push"
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 400)
     self.assertTrue(b"malformed" in response.content.lower())
     self.assertEqual(mock.call_count, 0)
コード例 #6
0
 def test_push_with_invalid_json(self, mock):
     data = b'<xml-is-not-json/>'
     request = self.FACTORY.post('/', data=data, content_type='application/json')
     request.META['HTTP_X_HUB_SIGNATURE'] = compute_signature(data, self.KEY)
     request.META['HTTP_X_GITHUB_EVENT'] = 'push'
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 400)
     self.assertTrue(b'malformed' in response.content.lower())
     self.assertEqual(mock.call_count, 0)
コード例 #7
0
ファイル: test_views.py プロジェクト: probaku1234/inloop
 def test_not_modified_when_event_not_push(self, mock):
     data = b'{"ref": "refs/heads/master"}'
     request = self.FACTORY.post("/",
                                 data=data,
                                 content_type="application/json")
     request.META["HTTP_X_HUB_SIGNATURE"] = compute_signature(
         data, self.KEY)
     request.META["HTTP_X_GITHUB_EVENT"] = "ping"
     response = webhook_handler(request)
     self.assertContains(response, "Event ignored")
     self.assertEqual(mock.call_count, 0)
コード例 #8
0
ファイル: test_views.py プロジェクト: probaku1234/inloop
 def test_push_with_invalid_signature(self, mock):
     data = b'{"ref": "refs/heads/master"}'
     request = self.FACTORY.post("/",
                                 data=data,
                                 content_type="application/json")
     request.META["HTTP_X_HUB_SIGNATURE"] = "invalid"
     request.META["HTTP_X_GITHUB_EVENT"] = "push"
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 400)
     self.assertTrue(b"invalid" in response.content.lower())
     self.assertEqual(mock.call_count, 0)
コード例 #9
0
ファイル: test_views.py プロジェクト: probaku1234/inloop
 def test_get_not_allowed(self, mock):
     request = self.FACTORY.get("/")
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 405)
     self.assertEqual(mock.call_count, 0)
コード例 #10
0
ファイル: test_views.py プロジェクト: st-tu-dresden/inloop
 def test_get_not_allowed(self, mock):
     request = self.FACTORY.get("/")
     response = webhook_handler(request)
     self.assertEqual(response.status_code, 405)
     self.assertEqual(mock.call_count, 0)