summaryrefslogtreecommitdiffstats
path: root/test/test_parsers.py
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2016-05-08 01:19:03 +0200
committerOliver Poignant <oliver@poignant.se>2016-05-08 01:19:03 +0200
commit6e6fd2e4f13cfb827ae1f5a0c3e83f14cc1fa15a (patch)
tree5a8d88d329413a0e9b8f786529c4ee2ce118fbe7 /test/test_parsers.py
parentae3c50f997427bc128ff303b4a3dbaea19c18fde (diff)
downloadGit-Auto-Deploy-6e6fd2e4f13cfb827ae1f5a0c3e83f14cc1fa15a.zip
Git-Auto-Deploy-6e6fd2e4f13cfb827ae1f5a0c3e83f14cc1fa15a.tar.gz
Git-Auto-Deploy-6e6fd2e4f13cfb827ae1f5a0c3e83f14cc1fa15a.tar.bz2
Automated testing of weebhook request handling
Diffstat (limited to 'test/test_parsers.py')
-rw-r--r--test/test_parsers.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/test/test_parsers.py b/test/test_parsers.py
new file mode 100644
index 0000000..a5ba65f
--- /dev/null
+++ b/test/test_parsers.py
@@ -0,0 +1,85 @@
+import unittest
+from utils import WebhookTestCaseBase
+
+class WebhookTestCase(WebhookTestCaseBase):
+
+ test_case = None
+ test_name = None
+
+ def set_test_case(self, test_case, test_name):
+ self.test_case = test_case
+ self.test_name = test_name
+
+ def shortDescription(self):
+ return self.test_name
+
+ def runTest(self):
+ import requests
+ import json
+
+ # GAD configuration for this test case
+ config = {
+ 'port': 0,
+ 'intercept-stdout': False,
+ 'detailed-response': True,
+ 'log-level': 'WARNING',
+ 'log-test-case': True,
+ 'repositories': []
+ }
+
+ if 'url' in self.test_case['config']:
+ config['repositories'].append(self.test_case['config'])
+
+ # Start GAD instance
+ self.start_gad(config)
+
+ # Send webhook request
+ session = requests.session()
+ response = requests.post('http://localhost:%s/' % self.gad_port(), data=json.dumps(self.test_case['payload']), headers=self.test_case['headers'])
+
+ # Verify response status
+ self.assertEqual(response.status_code, self.test_case['expected']['status'])
+
+ # Compare results
+ if 'data' in self.test_case['expected'] and self.test_case['expected']['data']:
+ actual = json.dumps(response.json())
+ expected = json.dumps(self.test_case['expected']['data'])
+ self.assertEqual(actual, expected)
+
+ # Wait for GAD to handle the request
+ self.await_gad()
+
+def suite():
+ import os
+ import json
+
+ suite = unittest.TestSuite()
+
+ # Look for test cases in samples dir
+ samples_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'samples')
+ for item in os.listdir(samples_dir):
+
+ if not item[-15:] == '.test-case.json':
+ continue
+
+ file = open(os.path.join(samples_dir, item), 'r')
+ test_case = json.loads(file.read())
+
+ t = WebhookTestCase()
+ t.set_test_case(test_case, item)
+
+ suite.addTest(t)
+
+ return suite
+
+if __name__ == '__main__':
+ from unittest import TestResult
+ #result = TestResult()
+
+ #suite().run(result)
+ #unittest.main()
+ #print result
+
+ suite = suite()
+ result = unittest.TextTestRunner(verbosity=2).run(suite)
+