Add unit tests
This commit is contained in:
parent
7404a4322d
commit
a5e327f90f
6 changed files with 84 additions and 6 deletions
1
Pipfile
1
Pipfile
|
@ -13,6 +13,7 @@ black = "*"
|
|||
isort = "*"
|
||||
mypy = "*"
|
||||
"flake8" = "*"
|
||||
"nose2" = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
|
|
48
Pipfile.lock
generated
48
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "683dc0a762a0d5cd59d704cb6fae259c6d16dbdae1754f102e5ba532f71df82e"
|
||||
"sha256": "87415b65be9abd963650b4ec4d7629d9b3798b85b1b1f815b7814d0777c5c759"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -112,6 +112,38 @@
|
|||
],
|
||||
"version": "==7.0"
|
||||
},
|
||||
"coverage": {
|
||||
"hashes": [
|
||||
"sha256:043d55226aec1d2baf4b2fcab5c204561ccf184a388096f41e396c1c092aff38",
|
||||
"sha256:10bfd0b80b01d0684f968abbe1186bc19962e07b4b7601bb43b175b617cf689d",
|
||||
"sha256:17e59864f19b3233032edb0566f26c25cc7f599503fb34d2645b5ce1fd6c2c3c",
|
||||
"sha256:2105ee183c51fed27e2b6801029b3903f5c2774c78e3f53bd920ca468d0f5679",
|
||||
"sha256:236505d15af6c7b7bfe2a9485db4b2bdea21d9239351483326184314418c79a8",
|
||||
"sha256:237284425271db4f30d458b355decf388ab20b05278bdf8dc9a65de0973726c6",
|
||||
"sha256:26d8eea4c840b73c61a1081d68bceb57b21a2d4f7afda6cac8ac38cb05226b00",
|
||||
"sha256:39a3740f7721155f4269aedf67b211101c07bd2111b334dfd69b807156ab15d9",
|
||||
"sha256:4bd0c42db8efc8a60965769796d43a5570906a870bc819f7388860aa72779d1b",
|
||||
"sha256:4dcddadea47ac30b696956bd18365cd3a86724821656601151e263b86d34798f",
|
||||
"sha256:51ea341289ac4456db946a25bd644f5635e5ae3793df262813cde875887d25c8",
|
||||
"sha256:5415cafb082dad78935b3045c2e5d8907f436d15ad24c3fdb8e1839e084e4961",
|
||||
"sha256:5631f1983074b33c35dbb84607f337b9d7e9808116d7f0f2cb7b9d6d4381d50e",
|
||||
"sha256:5e9249bc361cd22565fd98590a53fd25a3dd666b74791ed7237fa99de938bbed",
|
||||
"sha256:6a48746154f1331f28ef9e889c625b5b15a36cb86dd8021b4bdd1180a2186aa5",
|
||||
"sha256:71d376dbac64855ed693bc1ca121794570fe603e8783cdfa304ec6825d4e768f",
|
||||
"sha256:749ebd8a615337747592bd1523dfc4af7199b2bf6403b55f96c728668aeff91f",
|
||||
"sha256:8ec528b585b95234e9c0c31dcd0a89152d8ed82b4567aa62dbcb3e9a0600deee",
|
||||
"sha256:a1a9ccd879811437ca0307c914f136d6edb85bd0470e6d4966c6397927bcabd9",
|
||||
"sha256:abd956c334752776230b779537d911a5a12fcb69d8fd3fe332ae63a140301ae6",
|
||||
"sha256:ad18f836017f2e8881145795f483636564807aaed54223459915a0d4735300cf",
|
||||
"sha256:b07ac0b1533298ddbc54c9bf3464664895f22899fec027b8d6c8d3ac59023283",
|
||||
"sha256:d9385f1445e30e8e42b75a36a7899ea1fd0f5784233a626625d70f9b087de404",
|
||||
"sha256:db2d1fcd32dbeeb914b2660af1838e9c178b75173f95fd221b1f9410b5d3ef1d",
|
||||
"sha256:e1dec211147f1fd7cb7a0f9a96aeeca467a5af02d38911307b3b8c2324f9917e",
|
||||
"sha256:e96dffc1fa57bb8c1c238f3d989341a97302492d09cb11f77df031112621c35c",
|
||||
"sha256:ed4d97eb0ecdee29d0748acd84e6380729f78ce5ba0c7fe3401801634c25a1c5"
|
||||
],
|
||||
"version": "==5.0a3"
|
||||
},
|
||||
"flake8": {
|
||||
"hashes": [
|
||||
"sha256:6a35f5b8761f45c5513e3405f110a86bea57982c3b75b766ce7b65217abe1670",
|
||||
|
@ -151,6 +183,13 @@
|
|||
],
|
||||
"version": "==0.4.1"
|
||||
},
|
||||
"nose2": {
|
||||
"hashes": [
|
||||
"sha256:9052f2b46807b63d9bdf68e0768da1f8386368889b50043fd5d0889c470258f3"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.8.0"
|
||||
},
|
||||
"pycodestyle": {
|
||||
"hashes": [
|
||||
"sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83",
|
||||
|
@ -165,6 +204,13 @@
|
|||
],
|
||||
"version": "==2.0.0"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
|
||||
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
|
||||
],
|
||||
"version": "==1.11.0"
|
||||
},
|
||||
"toml": {
|
||||
"hashes": [
|
||||
"sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c",
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
set -e
|
||||
|
||||
black app/
|
||||
black app/ tests/
|
||||
|
||||
isort -rc app/
|
||||
isort -rc app/ tests/
|
||||
|
|
|
@ -2,14 +2,18 @@
|
|||
|
||||
set -e
|
||||
|
||||
echo "> Running unit-tests"
|
||||
nose2
|
||||
|
||||
echo "> Running black"
|
||||
black --check app/
|
||||
black --check app/ tests/
|
||||
|
||||
echo "> Running isort"
|
||||
isort -rc -c app/
|
||||
isort -rc -c app/ tests/
|
||||
|
||||
echo "> Running mypy"
|
||||
mypy --ignore-missing-imports app/
|
||||
mypy --ignore-missing-imports app/ tests/
|
||||
|
||||
echo "> Running flake8"
|
||||
flake8 --ignore=E128,E501 app
|
||||
flake8 --ignore=E128,E501 tests
|
||||
|
|
19
tests/__init__.py
Normal file
19
tests/__init__.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from unittest import TestCase
|
||||
from app.server import app
|
||||
import uuid
|
||||
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.app = app.test_client()
|
||||
|
||||
def send_webhook(self, event_type, data={}):
|
||||
return self.app.post(
|
||||
"/postreceive",
|
||||
json=data,
|
||||
headers={
|
||||
"X-GitHub-Event": event_type,
|
||||
"X-GitHub-Delivery": str(uuid.uuid4()),
|
||||
},
|
||||
)
|
8
tests/test_server.py
Normal file
8
tests/test_server.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from tests import BaseTestCase
|
||||
|
||||
|
||||
class PingEventTestCase(BaseTestCase):
|
||||
def test_pongs(self):
|
||||
response = self.send_webhook("ping")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json, {"ping": "pong"})
|
Reference in a new issue