mirror of
https://github.com/gryf/ferrit.git
synced 2026-02-07 08:45:53 +01:00
Added more tests for change merged and comment added events
This commit is contained in:
@@ -182,9 +182,9 @@ class App(bottle.Bottle):
|
||||
"target": "_blank"}]}}
|
||||
|
||||
def _changes(self, project, branch, id, commit_id):
|
||||
# We are looking for labels in the json
|
||||
labels = bottle.request.json.get('labels', {})
|
||||
if not labels:
|
||||
# We are looking for result of the job, not the notification about
|
||||
# starting the job.
|
||||
if bottle.request.json.get('message', '').startswith('Build Started'):
|
||||
return
|
||||
|
||||
LOG.info(json.dumps(bottle.request.json))
|
||||
|
||||
@@ -4,6 +4,8 @@ import subprocess
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class BaseTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -25,3 +27,24 @@ class BaseTestCase(unittest.TestCase):
|
||||
os.killpg(self.process.pid, signal.SIGTERM)
|
||||
os.unlink('ferrit-http.log')
|
||||
os.unlink('ferrit-ssh.log')
|
||||
|
||||
def _send_and_get_response(self, event_type):
|
||||
counter = 20
|
||||
result = None
|
||||
requests.post('http://localhost:8181/make/event',
|
||||
data='type=%s' % event_type)
|
||||
while counter:
|
||||
if not os.path.exists('ferrit-http.log'):
|
||||
counter -= 1
|
||||
time.sleep(1)
|
||||
continue
|
||||
|
||||
with open('ferrit-http.log') as fobj:
|
||||
result = fobj.read()
|
||||
if not result:
|
||||
time.sleep(1)
|
||||
counter -= 1
|
||||
else:
|
||||
break
|
||||
|
||||
return result
|
||||
|
||||
13
tests/test_change_merged.py
Normal file
13
tests/test_change_merged.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import json
|
||||
|
||||
from tests import base
|
||||
|
||||
|
||||
class TestChangeMerged(base.BaseTestCase):
|
||||
|
||||
def test_deploy(self):
|
||||
result = self._send_and_get_response('change-merged')
|
||||
|
||||
self.assertTrue(result)
|
||||
result = json.loads(result)
|
||||
self.assertIn('--tag', result['message'])
|
||||
13
tests/test_comment_added.py
Normal file
13
tests/test_comment_added.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import json
|
||||
|
||||
from tests import base
|
||||
|
||||
|
||||
class TestCommentAdded(base.BaseTestCase):
|
||||
|
||||
def test_recheck(self):
|
||||
result = self._send_and_get_response('comment-added')
|
||||
|
||||
self.assertTrue(result)
|
||||
result = json.loads(result)
|
||||
self.assertEqual(result['labels']['Verified'], 1)
|
||||
Reference in New Issue
Block a user