Skip to content

Commit

Permalink
add coveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Jan 2, 2018
1 parent cc3551c commit 7693b62
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ python:
install:
- pip install -r requirements.txt
script:
- pytest -v
- coverage run --source=lemon setup.py test
- coveralls
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lemon 🍋 [![Build Status](https://travis-ci.org/joway/lemon.svg?branch=master)](https://travis-ci.org/joway/lemon)
# Lemon 🍋 [![Build Status](https://travis-ci.org/joway/lemon.svg?branch=master)](https://travis-ci.org/joway/lemon) [![Coverage Status](https://coveralls.io/repos/github/joway/lemon/badge.svg?branch=feature%2Ftestcase)](https://coveralls.io/github/joway/lemon?branch=feature%2Ftestcase)

Lemon is an async and lightweight restful framework for python . Inspired by [Koa](https://github.com/koajs/koa) and [Sanic](https://github.com/channelcat/sanic) .

Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
uvloop==0.9.1
httptools==0.0.10
pytest==3.3.1
requests==2.18.4
requests==2.18.4
coveralls==1.2.0
pytest-runner==3.0
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[aliases]
test=pytest

[tool:pytest]
addopts = --verbose
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
license='MIT',
packages=['lemon'],
keywords='lemon restful api async python',
setup_requires=['pytest-runner'],
tests_require=['pytest'],
)
13 changes: 10 additions & 3 deletions tests/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ def base_url(self):
)

def get(self, path, params=None):
req = requests.get('{0}{1}'.format(self.base_url, path), params=params, headers={'Connection': 'close'})
req.close()
return req
return requests.get('{0}{1}'.format(self.base_url, path), params=params, headers={'Connection': 'close'})

def post(self, path, params=None):
return requests.get('{0}{1}'.format(self.base_url, path), params=params, headers={'Connection': 'close'})

def put(self, path, params=None):
return requests.put('{0}{1}'.format(self.base_url, path), params=params, headers={'Connection': 'close'})

def delete(self, path, params=None):
return requests.delete('{0}{1}'.format(self.base_url, path), params=params, headers={'Connection': 'close'})

def create_server(self, listen, **kwargs):
process = Process(target=listen, kwargs=kwargs)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ async def handle(ctx: Context):

client.stop_server()

def test_other_method(self):
async def handle(ctx: Context):
ctx.body = {
'ack': 'yeah !',
}

client = self.create_http_server([handle])
req = client.post('/')
data = req.json()
assert req.status_code == 200
assert data['ack'] == 'yeah !'
req = client.delete('/')
data = req.json()
assert req.status_code == 200
assert data['ack'] == 'yeah !'
req = client.put('/')
data = req.json()
assert req.status_code == 200
assert data['ack'] == 'yeah !'

client.stop_server()

def test_throw(self):
async def handle(ctx: Context):
raise Exception
Expand Down

0 comments on commit 7693b62

Please sign in to comment.