fix circular reference in utils and testcase module

This commit is contained in:
debugtalk
2017-11-02 12:45:59 +08:00
parent 6f04f5008a
commit 5fd4e28d34
7 changed files with 132 additions and 125 deletions

View File

@@ -8,81 +8,6 @@ from tests.base import ApiServerUnittest
class TestUtils(ApiServerUnittest):
def test_load_testcases_bad_filepath(self):
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo')
self.assertEqual(utils.load_tests(testcase_file_path), [])
def test_load_json_testcases(self):
testcase_file_path = os.path.join(
os.getcwd(), 'tests/data/demo_testset_hardcode.json')
testcases = utils.load_tests(testcase_file_path)
self.assertEqual(len(testcases), 3)
testcase = testcases[0]["test"]
self.assertIn('name', testcase)
self.assertIn('request', testcase)
self.assertIn('url', testcase['request'])
self.assertIn('method', testcase['request'])
def test_load_yaml_testcases(self):
testcase_file_path = os.path.join(
os.getcwd(), 'tests/data/demo_testset_hardcode.yml')
testcases = utils.load_tests(testcase_file_path)
self.assertEqual(len(testcases), 3)
testcase = testcases[0]["test"]
self.assertIn('name', testcase)
self.assertIn('request', testcase)
self.assertIn('url', testcase['request'])
self.assertIn('method', testcase['request'])
def test_load_yaml_file_file_format_error(self):
yaml_tmp_file = "tests/data/tmp.yml"
# create empty yaml file
with open(yaml_tmp_file, 'w') as f:
f.write("")
with self.assertRaises(exception.FileFormatError):
utils.load_yaml_file(yaml_tmp_file)
os.remove(yaml_tmp_file)
# create invalid format yaml file
with open(yaml_tmp_file, 'w') as f:
f.write("abc")
with self.assertRaises(exception.FileFormatError):
utils.load_yaml_file(yaml_tmp_file)
os.remove(yaml_tmp_file)
def test_load_json_file_file_format_error(self):
json_tmp_file = "tests/data/tmp.json"
# create empty file
with open(json_tmp_file, 'w') as f:
f.write("")
with self.assertRaises(exception.FileFormatError):
utils.load_json_file(json_tmp_file)
os.remove(json_tmp_file)
# create empty json file
with open(json_tmp_file, 'w') as f:
f.write("{}")
with self.assertRaises(exception.FileFormatError):
utils.load_json_file(json_tmp_file)
os.remove(json_tmp_file)
# create invalid format json file
with open(json_tmp_file, 'w') as f:
f.write("abc")
with self.assertRaises(exception.FileFormatError):
utils.load_json_file(json_tmp_file)
os.remove(json_tmp_file)
def test_load_folder_files(self):
folder = os.path.join(os.getcwd(), 'tests')
file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py')