Skip to content

Commit 0475970

Browse files
committed
Merge pull request #43 from CodingForChange/api_v1
Criando versionamento na url (/v1)
2 parents 5890c87 + 6749c1e commit 0475970

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

PostmonServer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import bottle
12
from bottle import route, run, response
23
from CepTracker import CepTracker
34
from requests import ConnectionError
45

56
from database import MongoDb as Database
67

8+
app_v1 = bottle.Bottle()
9+
710
def expired(record_date):
811
from datetime import datetime, timedelta
912

@@ -25,6 +28,7 @@ def _get_info_from_source(cep):
2528

2629

2730
@route('/cep/<cep:re:\d{5}-?\d{3}>')
31+
@app_v1.route('/cep/<cep:re:\d{5}-?\d{3}>')
2832
def verifica_cep(cep):
2933
cep = cep.replace('-','')
3034
db = Database()
@@ -51,6 +55,7 @@ def verifica_cep(cep):
5155

5256
return result
5357

58+
bottle.mount('/v1', app_v1)
5459

5560
def _standalone(port=9876):
5661
run(host='localhost', port=port)

test/postmon_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,13 @@ def assertCep(self, cep):
113113
self.assertEqual(v, result[k])
114114

115115
self.assertNotIn('v_date', result)
116+
117+
class PostmonV1WebTest(PostmonWebTest):
118+
119+
'''
120+
Teste do servidor do Postmon no /v1
121+
'''
122+
123+
def get_cep(self, cep):
124+
response = self.app.get('/v1/cep/' + cep)
125+
return response.json

0 commit comments

Comments
 (0)