Permalink
Browse files

tox and pytest setup

  • Loading branch information...
jms committed May 31, 2016
1 parent 593ac59 commit 0cdec946cbea1ad55e265327516e433f9653e700
View
@@ -58,4 +58,4 @@ target/
# ide stuff
.idea
MANIFEST
View
@@ -1,3 +1,6 @@
# file GENERATED by distutils, do NOT edit
main.py
setup.cfg
setup.py
check_phonenumber/__init__.py
check_phonenumber/service.py
@@ -0,0 +1 @@
from service import CheckPhoneNumber
@@ -0,0 +1,26 @@
import phonenumbers
from phonenumbers import carrier, NumberParseException
class CheckPhoneNumber:
@staticmethod
def validate_phone(data):
try:
phone_number = data.get('phone_number')
cc = data.get('country_code')
number_data = phonenumbers.parse(phone_number, cc)
check_possible_number = phonenumbers.is_possible_number(number_data)
check_valid_number = phonenumbers.is_valid_number(number_data)
carrier_info = carrier.name_for_number(number_data, "en")
carrier_data = str(carrier_info)
check_result = {
"number_data": str(number_data),
"possible_number": check_possible_number,
"valid_number": check_valid_number,
"carrier_data": carrier_data
}
except NumberParseException:
check_result = {"success": False, "message": "Number not valid or no possible"}
except KeyError:
check_result = {"success": False, "message": "key missing on json data"}
return check_result
View
34 main.py
@@ -1,43 +1,25 @@
from bottle import Bottle, run, error, request, response, debug
import phonenumbers
from phonenumbers import carrier, NumberParseException
from check_phonenumber.service import CheckPhoneNumber
app = Bottle()
@app.route('/', method='GET')
def hello():
return "Check Phone micro service"
def index():
return "Get Phone Number Information service"
@app.route('/check-phone', method='POST')
def check_phone():
try:
data = request.json
phone_number = data['phone_number']
cc = data['country_code']
# print(data)
number_data = phonenumbers.parse(phone_number, cc)
check_possible_number = phonenumbers.is_possible_number(number_data)
check_valid_number = phonenumbers.is_valid_number(number_data)
carrier_info = carrier.name_for_number(number_data, "en")
carrier_data = str(carrier_info)
check_result = {
"number_data": str(number_data),
"possible_number": check_possible_number,
"valid_number": check_valid_number,
"carrier_data": carrier_data
}
except NumberParseException:
check_result = {"success": False, "message": "Number not valid or no possible"}
except KeyError:
check_result = {"success": False, "message": "key missing on json data"}
data = request.json
check_result = CheckPhoneNumber.validate_phone(data)
response.content_type = 'application/json'
return check_result
@error(404)
def error404(error):
return 'Release the Kraken'
return error
debug(True)
File renamed without changes.
View
@@ -1,4 +1,4 @@
bottle==0.12.8
phonenumbers==7.0.5
tox
pytest
bottle==0.12.9
phonenumbers==7.4.1
tox==2.3.1
pytest==2.9.1
View
@@ -1,2 +1,2 @@
bottle==0.12.8
phonenumbers==7.0.5
bottle==0.12.9
phonenumbers==7.4.1
View
@@ -0,0 +1,2 @@
[aliases]
test=pytest
View
@@ -1,10 +1,13 @@
from distutils.core import setup
from setuptools import setup, find_packages
setup(
name='check-phone-number',
version='1.0',
url="https://github.com/jms/check-phone-number",
author="Jeronimo Martinez Sanchez",
author_email="jms@rz0r.net",
description="Bottle microservice to verify phone numbers",
py_modules=['main']
)
py_modules=['main', 'check_phonenumber.service'],
setup_requires=['pytest-runner', ],
tests_require=['pytest', ]
)
View
No changes.
View
@@ -0,0 +1,16 @@
import pytest
import check_phonenumber.service
@pytest.fixture
def test_data():
data = {
"phone_number": "+40721234567",
"country_code": "RO"
}
return data
def test_service(test_data):
result = check_phonenumber.service.CheckPhoneNumber.validate_phone(data=test_data)
assert result.get('valid_number') is True
View
11 tox.ini
@@ -4,9 +4,12 @@
# and then run "tox" from this directory.
[tox]
envlist = py27, py35
envlist = py27, py34
[testenv]
commands = {envpython} setup.py test
deps =
;[testenv]
;commands = {envpython} setup.py test
;deps = pytest
[testenv]
deps=pytest
commands=py.test {posargs} # substitute with tox' positional arguments
View
No changes.

0 comments on commit 0cdec94

Please sign in to comment.