properly close file contexts
This commit is contained in:
parent
eaf6aeeccc
commit
50e2a3f1dc
1 changed files with 18 additions and 14 deletions
32
test.py
32
test.py
|
@ -58,7 +58,8 @@ class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
|||
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
||||
|
||||
def test_valid_entity(self):
|
||||
entity_file = json.load(open('test_cases/valid/valid.json','r'))
|
||||
with open('test_cases/valid/valid.json','r') af f:
|
||||
entity_file = json.load(f)
|
||||
|
||||
response = self.fetch('/v0/validate',
|
||||
method='POST',
|
||||
|
@ -72,7 +73,8 @@ class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
|||
self.assertTrue(validation_result['valid'], "Validation result is expected to be valid==true")
|
||||
|
||||
def test_invalid_iban(self):
|
||||
entity_file = json.load(open('test_cases/invalid/invalid_iban.json','r'))
|
||||
with open('test_cases/invalid/invalid_iban.json','r') af f:
|
||||
entity_file = json.load(f)
|
||||
|
||||
response = self.fetch('/v0/validate',
|
||||
method='POST',
|
||||
|
@ -86,23 +88,25 @@ class TestValidation(tornado.testing.AsyncHTTPTestCase):
|
|||
self.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
||||
|
||||
def test_missing_id(self):
|
||||
entity_file = json.load(open('test_cases/invalid/missing_id.json','r'))
|
||||
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")
|
||||
response = self.fetch('/v0/validate',
|
||||
method='POST',
|
||||
body=json.dumps(entity_file))
|
||||
|
||||
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.assertFalse(validation_result['valid'], "Validation result is expected to be valid==false")
|
||||
self.assertIn('id', validation_result['errors'])
|
||||
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):
|
||||
entity_file = json.load(open('test_cases/invalid/invalid_id.json','r'))
|
||||
|
||||
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))
|
||||
|
|
Loading…
Reference in a new issue