pycodestype (pep8) fixes
This commit is contained in:
parent
50e2a3f1dc
commit
7609c08cb4
3 changed files with 70 additions and 39 deletions
12
app.py
12
app.py
|
@ -35,10 +35,12 @@ class HealthHandler(tornado.web.RequestHandler, metaclass=ABCMeta):
|
||||||
# if not available, try git
|
# if not available, try git
|
||||||
if v is None:
|
if v is None:
|
||||||
try:
|
try:
|
||||||
v = subprocess.check_output(["git", "describe", "--always", "--dirty"],
|
v = subprocess.check_output(["git", "describe", "--always",
|
||||||
|
"--dirty"],
|
||||||
cwd=os.path.dirname(__file__)).strip().decode()
|
cwd=os.path.dirname(__file__)).strip().decode()
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print("Checking git version lead to non-null return code ", e.returncode)
|
print("Checking git version lead to non-null return code ",
|
||||||
|
e.returncode)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@ -50,7 +52,8 @@ class HealthHandler(tornado.web.RequestHandler, metaclass=ABCMeta):
|
||||||
health['git-version'] = self.git_version
|
health['git-version'] = self.git_version
|
||||||
|
|
||||||
health['timestamp'] = isodate.datetime_isoformat(datetime.now())
|
health['timestamp'] = isodate.datetime_isoformat(datetime.now())
|
||||||
health['uptime'] = isodate.duration_isoformat(datetime.now() - startup_timestamp)
|
health['uptime'] = isodate.duration_isoformat(datetime.now()
|
||||||
|
- startup_timestamp)
|
||||||
|
|
||||||
self.set_header("Content-Type", "application/json")
|
self.set_header("Content-Type", "application/json")
|
||||||
self.write(json.dumps(health, indent=4))
|
self.write(json.dumps(health, indent=4))
|
||||||
|
@ -61,7 +64,8 @@ class Oas3Handler(tornado.web.RequestHandler, metaclass=ABCMeta):
|
||||||
def get(self):
|
def get(self):
|
||||||
self.set_header("Content-Type", "text/plain")
|
self.set_header("Content-Type", "text/plain")
|
||||||
# This is the proposed content type,
|
# This is the proposed content type,
|
||||||
# but browsers like Firefox try to download instead of display the content
|
# but browsers like Firefox try to download instead of
|
||||||
|
# display the content
|
||||||
# self.set_header("Content-Type", "text/vnd.yml")
|
# self.set_header("Content-Type", "text/vnd.yml")
|
||||||
with open('OAS3.yml', 'r') as f:
|
with open('OAS3.yml', 'r') as f:
|
||||||
oas3 = f.read()
|
oas3 = f.read()
|
||||||
|
|
80
test.py
80
test.py
|
@ -22,11 +22,16 @@ class TestBaseAPI(tornado.testing.AsyncHTTPTestCase):
|
||||||
|
|
||||||
health = json.loads(response.body.decode())
|
health = json.loads(response.body.decode())
|
||||||
|
|
||||||
self.assertIn('api-version', health, msg="api-version is not provided by health endpoint")
|
self.assertIn('api-version', health,
|
||||||
self.assertEqual("v0", health['api-version'], msg="API version should be v0")
|
msg="api-version is not provided by health endpoint")
|
||||||
self.assertIn('git-version', health, msg="git-version is not provided by health endpoint")
|
self.assertEqual("v0", health['api-version'],
|
||||||
self.assertIn('timestamp', health, msg="timestamp is not provided by health endpoint")
|
msg="API version should be v0")
|
||||||
self.assertIn('uptime', health, msg="uptime is not provided by health endpoint")
|
self.assertIn('git-version', health,
|
||||||
|
msg="git-version is not provided by health endpoint")
|
||||||
|
self.assertIn('timestamp', health,
|
||||||
|
msg="timestamp is not provided by health endpoint")
|
||||||
|
self.assertIn('uptime', health,
|
||||||
|
msg="uptime is not provided by health endpoint")
|
||||||
|
|
||||||
def test_oas3(self):
|
def test_oas3(self):
|
||||||
response = self.fetch('/v0/oas3',
|
response = self.fetch('/v0/oas3',
|
||||||
|
@ -35,7 +40,8 @@ class TestBaseAPI(tornado.testing.AsyncHTTPTestCase):
|
||||||
|
|
||||||
# check contents against local OAS3.yml
|
# check contents against local OAS3.yml
|
||||||
with open('OAS3.yml') as oas3f:
|
with open('OAS3.yml') as oas3f:
|
||||||
self.assertEqual(response.body.decode(), oas3f.read(), "OAS3 content differs from spec file!")
|
self.assertEqual(response.body.decode(), oas3f.read(),
|
||||||
|
"OAS3 content differs from spec file!")
|
||||||
|
|
||||||
|
|
||||||
class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
||||||
|
@ -50,74 +56,90 @@ class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
||||||
method='POST',
|
method='POST',
|
||||||
body=json.dumps(entity))
|
body=json.dumps(entity))
|
||||||
|
|
||||||
self.assertEqual(200, response.code, "Validation must always return 200")
|
self.assertEqual(200, response.code,
|
||||||
|
"Validation must always return 200")
|
||||||
|
|
||||||
validation_result = json.loads(response.body.decode())
|
validation_result = json.loads(response.body.decode())
|
||||||
|
|
||||||
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result")
|
self.assertIn('valid', validation_result,
|
||||||
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
"Key 'valid' expected in validation result")
|
||||||
|
self.assertFalse(validation_result['valid'],
|
||||||
|
"Validation result is expected to be valid==false")
|
||||||
|
|
||||||
def test_valid_entity(self):
|
def test_valid_entity(self):
|
||||||
with open('test_cases/valid/valid.json','r') af f:
|
with open('test_cases/valid/valid.json', 'r') af f:
|
||||||
entity_file = json.load(f)
|
entity_file = json.load(f)
|
||||||
|
|
||||||
response = self.fetch('/v0/validate',
|
response = self.fetch('/v0/validate',
|
||||||
method='POST',
|
method='POST',
|
||||||
body=json.dumps(entity_file))
|
body=json.dumps(entity_file))
|
||||||
|
|
||||||
self.assertEqual(200, response.code, "Validation must always return 200")
|
self.assertEqual(200, response.code,
|
||||||
|
"Validation must always return 200")
|
||||||
|
|
||||||
validation_result = json.loads(response.body.decode())
|
validation_result = json.loads(response.body.decode())
|
||||||
|
|
||||||
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result")
|
self.assertIn('valid', validation_result,
|
||||||
self.assertTrue(validation_result['valid'], "Validation result is expected to be valid==true")
|
"Key 'valid' expected in validation result")
|
||||||
|
self.assertTrue(validation_result['valid'],
|
||||||
|
"Validation result is expected to be valid==true")
|
||||||
|
|
||||||
def test_invalid_iban(self):
|
def test_invalid_iban(self):
|
||||||
with open('test_cases/invalid/invalid_iban.json','r') af f:
|
with open('test_cases/invalid/invalid_iban.json', 'r') af f:
|
||||||
entity_file = json.load(f)
|
entity_file = json.load(f)
|
||||||
|
|
||||||
response = self.fetch('/v0/validate',
|
response = self.fetch('/v0/validate',
|
||||||
method='POST',
|
method='POST',
|
||||||
body=json.dumps(entity_file))
|
body=json.dumps(entity_file))
|
||||||
|
|
||||||
self.assertEqual(200, response.code, "Validation must always return 200")
|
self.assertEqual(200, response.code,
|
||||||
|
"Validation must always return 200")
|
||||||
|
|
||||||
validation_result = json.loads(response.body.decode())
|
validation_result = json.loads(response.body.decode())
|
||||||
|
|
||||||
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result")
|
self.assertIn('valid', validation_result,
|
||||||
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
"Key 'valid' expected in validation result")
|
||||||
|
self.assertFalse(validation_result['valid'],
|
||||||
|
"Validation result is expected to be valid==false")
|
||||||
|
|
||||||
def test_missing_id(self):
|
def test_missing_id(self):
|
||||||
with open('test_cases/invalid/missing_id.json','r') af f:
|
with open('test_cases/invalid/missing_id.json', 'r') af f:
|
||||||
entity_file = json.load(f)
|
entity_file = json.load(f)
|
||||||
|
|
||||||
response = self.fetch('/v0/validate',
|
response = self.fetch('/v0/validate',
|
||||||
method='POST',
|
method='POST',
|
||||||
body=json.dumps(entity_file))
|
body=json.dumps(entity_file))
|
||||||
|
|
||||||
self.assertEqual(200, response.code, "Validation must always return 200")
|
self.assertEqual(200, response.code,
|
||||||
|
"Validation must always return 200")
|
||||||
|
|
||||||
validation_result = json.loads(response.body.decode())
|
validation_result = json.loads(response.body.decode())
|
||||||
|
|
||||||
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result")
|
self.assertIn('valid', validation_result,
|
||||||
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
"Key 'valid' expected in validation result")
|
||||||
|
self.assertFalse(validation_result['valid'],
|
||||||
|
"Validation result is expected to be valid==false")
|
||||||
self.assertIn('id', validation_result['errors'])
|
self.assertIn('id', validation_result['errors'])
|
||||||
|
|
||||||
def test_invalid_id(self):
|
def test_invalid_id(self):
|
||||||
with open('test_cases/invalid/invalid_id.json','r') af f:
|
with open('test_cases/invalid/invalid_id.json', 'r') af f:
|
||||||
entity_file = json.load(f)
|
entity_file = json.load(f)
|
||||||
|
|
||||||
response = self.fetch('/v0/validate',
|
response = self.fetch('/v0/validate',
|
||||||
method='POST',
|
method='POST',
|
||||||
body=json.dumps(entity_file))
|
body=json.dumps(entity_file))
|
||||||
|
|
||||||
self.assertEqual(200, response.code, "Validation must always return 200")
|
self.assertEqual(200, response.code,
|
||||||
|
"Validation must always return 200")
|
||||||
|
|
||||||
validation_result = json.loads(response.body.decode())
|
validation_result = json.loads(response.body.decode())
|
||||||
|
|
||||||
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result")
|
self.assertIn('valid', validation_result,
|
||||||
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
"Key 'valid' expected in validation result")
|
||||||
|
self.assertFalse(validation_result['valid'],
|
||||||
|
"Validation result is expected to be valid==false")
|
||||||
self.assertIn('id', validation_result['errors'])
|
self.assertIn('id', validation_result['errors'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -2,6 +2,7 @@ from schwifty import IBAN, BIC
|
||||||
import datetime
|
import datetime
|
||||||
from validator_collection import validators, errors
|
from validator_collection import validators, errors
|
||||||
|
|
||||||
|
|
||||||
def valid_iban(field, value, error):
|
def valid_iban(field, value, error):
|
||||||
try:
|
try:
|
||||||
IBAN(value)
|
IBAN(value)
|
||||||
|
@ -9,6 +10,7 @@ def valid_iban(field, value, error):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
error(field, 'not a valid IBAN')
|
error(field, 'not a valid IBAN')
|
||||||
|
|
||||||
|
|
||||||
def valid_bic(field, value, error):
|
def valid_bic(field, value, error):
|
||||||
try:
|
try:
|
||||||
BIC(value)
|
BIC(value)
|
||||||
|
@ -16,6 +18,7 @@ def valid_bic(field, value, error):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
error(field, 'not a valid BIC')
|
error(field, 'not a valid BIC')
|
||||||
|
|
||||||
|
|
||||||
def iso_date(field, value, error):
|
def iso_date(field, value, error):
|
||||||
try:
|
try:
|
||||||
datetime.datetime.strptime(value, "%Y-%m-%d")
|
datetime.datetime.strptime(value, "%Y-%m-%d")
|
||||||
|
@ -23,6 +26,7 @@ def iso_date(field, value, error):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
error(field, 'not a valid ISO 8601 date')
|
error(field, 'not a valid ISO 8601 date')
|
||||||
|
|
||||||
|
|
||||||
def valid_money_amount(field, value, error):
|
def valid_money_amount(field, value, error):
|
||||||
try:
|
try:
|
||||||
# value is string, check formatting by parsing as float
|
# value is string, check formatting by parsing as float
|
||||||
|
@ -31,6 +35,7 @@ def valid_money_amount(field, value, error):
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
error(field, 'not a valid money value')
|
error(field, 'not a valid money value')
|
||||||
|
|
||||||
|
|
||||||
def valid_email(field, value, error):
|
def valid_email(field, value, error):
|
||||||
try:
|
try:
|
||||||
validators.email(value)
|
validators.email(value)
|
||||||
|
|
Loading…
Reference in a new issue