|
|
|
@ -22,11 +22,16 @@ class TestBaseAPI(tornado.testing.AsyncHTTPTestCase):
|
|
|
|
|
|
|
|
|
|
health = json.loads(response.body.decode()) |
|
|
|
|
|
|
|
|
|
self.assertIn('api-version', health, msg="api-version is not provided by health endpoint") |
|
|
|
|
self.assertEqual("v0", health['api-version'], msg="API version should be v0") |
|
|
|
|
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") |
|
|
|
|
self.assertIn('api-version', health, |
|
|
|
|
msg="api-version is not provided by health endpoint") |
|
|
|
|
self.assertEqual("v0", health['api-version'], |
|
|
|
|
msg="API version should be v0") |
|
|
|
|
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): |
|
|
|
|
response = self.fetch('/v0/oas3', |
|
|
|
@ -35,7 +40,8 @@ class TestBaseAPI(tornado.testing.AsyncHTTPTestCase):
|
|
|
|
|
|
|
|
|
|
# check contents against local OAS3.yml |
|
|
|
|
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): |
|
|
|
@ -50,74 +56,90 @@ class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
|
|
|
|
method='POST', |
|
|
|
|
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()) |
|
|
|
|
|
|
|
|
|
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result") |
|
|
|
|
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false") |
|
|
|
|
self.assertIn('valid', validation_result, |
|
|
|
|
"Key 'valid' expected in validation result") |
|
|
|
|
self.assertFalse(validation_result['valid'], |
|
|
|
|
"Validation result is expected to be valid==false") |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
response = self.fetch('/v0/validate', |
|
|
|
|
method='POST', |
|
|
|
|
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()) |
|
|
|
|
|
|
|
|
|
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result") |
|
|
|
|
self.assertTrue(validation_result['valid'], "Validation result is expected to be valid==true") |
|
|
|
|
self.assertIn('valid', validation_result, |
|
|
|
|
"Key 'valid' expected in validation result") |
|
|
|
|
self.assertTrue(validation_result['valid'], |
|
|
|
|
"Validation result is expected to be valid==true") |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
response = self.fetch('/v0/validate', |
|
|
|
|
method='POST', |
|
|
|
|
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()) |
|
|
|
|
|
|
|
|
|
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result") |
|
|
|
|
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false") |
|
|
|
|
self.assertIn('valid', validation_result, |
|
|
|
|
"Key 'valid' expected in validation result") |
|
|
|
|
self.assertFalse(validation_result['valid'], |
|
|
|
|
"Validation result is expected to be valid==false") |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
response = self.fetch('/v0/validate', |
|
|
|
|
method='POST', |
|
|
|
|
body=json.dumps(entity_file)) |
|
|
|
|
|
|
|
|
|
self.assertEqual(200, response.code, "Validation must always return 200") |
|
|
|
|
method='POST', |
|
|
|
|
body=json.dumps(entity_file)) |
|
|
|
|
|
|
|
|
|
self.assertEqual(200, response.code, |
|
|
|
|
"Validation must always return 200") |
|
|
|
|
|
|
|
|
|
validation_result = json.loads(response.body.decode()) |
|
|
|
|
|
|
|
|
|
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result") |
|
|
|
|
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false") |
|
|
|
|
self.assertIn('valid', validation_result, |
|
|
|
|
"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']) |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response = self.fetch('/v0/validate', |
|
|
|
|
method='POST', |
|
|
|
|
body=json.dumps(entity_file)) |
|
|
|
|
|
|
|
|
|
self.assertEqual(200, response.code, "Validation must always return 200") |
|
|
|
|
method='POST', |
|
|
|
|
body=json.dumps(entity_file)) |
|
|
|
|
|
|
|
|
|
self.assertEqual(200, response.code, |
|
|
|
|
"Validation must always return 200") |
|
|
|
|
|
|
|
|
|
validation_result = json.loads(response.body.decode()) |
|
|
|
|
|
|
|
|
|
self.assertIn('valid', validation_result, "Key 'valid' expected in validation result") |
|
|
|
|
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false") |
|
|
|
|
self.assertIn('valid', validation_result, |
|
|
|
|
"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']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
unittest.main() |
|
|
|
|