本文整理汇总了Python中tests.Test.url方法的典型用法代码示例。如果您正苦于以下问题:Python Test.url方法的具体用法?Python Test.url怎么用?Python Test.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.Test
的用法示例。
在下文中一共展示了Test.url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_failed_get
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_failed_get(self):
""" Test GET that should fail """
test = Test()
test.url = self.prefix + "/api/person/500/"
test_response = resttest.run_test(test)
self.assertEqual(False, test_response.passed)
self.assertEqual(404, test_response.response_code)
示例2: test_get
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_get(self):
""" Basic local get test """
test = Test()
test.url = self.prefix + "/api/person/"
test_response = resttest.run_test(test)
self.assertTrue(test_response.passed)
self.assertEqual(200, test_response.response_code)
示例3: test_get_validators
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_get_validators(self):
""" Test that validators work correctly """
test = Test()
test.url = self.prefix + "/api/person/"
# Validators need library calls to configure them
test.validators = list()
cfg_exists = {"jsonpath_mini": "objects.0", "test": "exists"}
test.validators.append(validators.parse_validator("extract_test", cfg_exists))
cfg_exists_0 = {"jsonpath_mini": "meta.offset", "test": "exists"}
test.validators.append(validators.parse_validator("extract_test", cfg_exists_0))
cfg_not_exists = {"jsonpath_mini": "objects.100", "test": "not_exists"}
test.validators.append(validators.parse_validator("extract_test", cfg_not_exists))
cfg_compare_login = {"jsonpath_mini": "objects.0.login", "expected": "gbaltar"}
test.validators.append(validators.parse_validator("compare", cfg_compare_login))
cfg_compare_id = {"jsonpath_mini": "objects.1.id", "comparator": "gt", "expected": -1}
test.validators.append(validators.parse_validator("compare", cfg_compare_id))
test_response = resttest.run_test(test)
for failure in test_response.failures:
print("REAL FAILURE")
print("Test Failure, failure type: {0}, Reason: {1}".format(failure.failure_type, failure.message))
if failure.details:
print("Validator/Error details: " + str(failure.details))
self.assertFalse(test_response.failures)
self.assertTrue(test_response.passed)
示例4: test_get_validators
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_get_validators(self):
""" Test that validators work correctly """
test = Test()
test.url = self.prefix + '/api/person/'
# Validators need library calls to configure them
test.validators = list()
cfg_exists = {'jsonpath_mini': "objects.0", 'test':'exists'}
test.validators.append(validators.parse_validator('extract_test', cfg_exists))
cfg_exists_0 = {'jsonpath_mini': "meta.offset", 'test':'exists'}
test.validators.append(validators.parse_validator('extract_test', cfg_exists_0))
cfg_not_exists = {'jsonpath_mini': "objects.100", 'test':'not_exists'}
test.validators.append(validators.parse_validator('extract_test', cfg_not_exists))
cfg_compare_login = {'jsonpath_mini': 'objects.0.login', 'expected': 'gbaltar'}
test.validators.append(validators.parse_validator('compare', cfg_compare_login))
cfg_compare_id = {'jsonpath_mini': 'objects.1.id', 'comparator':'gt', 'expected': -1}
test.validators.append(validators.parse_validator('compare', cfg_compare_id))
test_response = resttest.run_test(test)
for failure in test_response.failures:
print "REAL FAILURE"
print "Test Failure, failure type: {0}, Reason: {1}".format(failure.failure_type, failure.message)
if failure.details:
print "Validator/Error details: "+str(failure.details)
self.assertFalse(test_response.failures)
self.assertTrue(test_response.passed)
示例5: test_get_redirect
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_get_redirect(self):
""" Basic local get test """
test = Test()
test.curl_options = {"FOLLOWLOCATION": True}
test.url = self.prefix + "/api/person"
test_response = resttest.run_test(test)
self.assertTrue(test_response.passed)
self.assertEqual(200, test_response.response_code)
示例6: parse_testsets
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def parse_testsets(base_url, test_structure, test_files = set(), working_directory = None):
""" Convert a Python datastructure read from validated YAML to a set of structured testsets
The data stucture is assumed to be a list of dictionaries, each of which describes:
- a tests (test structure)
- a simple test (just a URL, and a minimal test is created)
- or overall test configuration for this testset
- an import (load another set of tests into this one, from a separate file)
- For imports, these are recursive, and will use the parent config if none is present
Note: test_files is used to track tests that import other tests, to avoid recursive loops
This returns a list of testsets, corresponding to imported testsets and in-line multi-document sets
"""
tests_out = list()
test_config = TestConfig()
testsets = list()
benchmarks = list()
if working_directory is None:
working_directory = os.path.abspath(os.getcwd())
#returns a testconfig and collection of tests
for node in test_structure: #Iterate through lists of test and configuration elements
if isinstance(node,dict): #Each config element is a miniature key-value dictionary
node = lowercase_keys(node)
for key in node:
if key == u'import':
importfile = node[key] #import another file
if importfile not in test_files:
logger.debug("Importing test sets: " + importfile)
test_files.add(importfile)
import_test_structure = read_test_file(importfile)
with cd(os.path.dirname(os.path.realpath(importfile))):
import_testsets = parse_testsets(base_url, import_test_structure, test_files)
testsets.extend(import_testsets)
elif key == u'url': #Simple test, just a GET to a URL
mytest = Test()
val = node[key]
assert isinstance(val,str) or isinstance(val,unicode)
mytest.url = base_url + val
tests_out.append(mytest)
elif key == u'test': #Complex test with additional parameters
with cd(working_directory):
child = node[key]
mytest = Test.parse_test(base_url, child)
tests_out.append(mytest)
elif key == u'benchmark':
benchmark = parse_benchmark(base_url, node[key])
benchmarks.append(benchmark)
elif key == u'config' or key == u'configuration':
test_config = parse_configuration(node[key])
testset = TestSet()
testset.tests = tests_out
testset.config = test_config
testset.benchmarks = benchmarks
testsets.append(testset)
return testsets
示例7: test_post
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_post(self):
""" Test POST to create an item """
test = Test()
test.url = self.prefix + "/api/person/"
test.method = u"POST"
test.expected_status = [200, 201, 204]
test.body = '{"first_name": "Willim","last_name": "Adama","login": "theadmiral"}'
test.headers = {u"Content-Type": u"application/json"}
test_response = resttest.run_test(test)
self.assertEqual(True, test_response.passed)
self.assertEqual(201, test_response.response_code)
# Test user was created
test2 = Test()
test2.url = self.prefix + "/api/person/?login=theadmiral"
test_response2 = resttest.run_test(test2)
self.assertTrue(test_response2.passed)
obj = json.loads(str(test_response2.body))
print(json.dumps(obj))
示例8: test_put_created
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_put_created(self):
""" Test PUT where item DOES NOT already exist """
test = Test()
test.url = self.prefix + "/api/person/100/"
test.method = u"PUT"
test.expected_status = [200, 201, 204]
test.body = '{"first_name": "Willim","last_name": "Adama","login":"theadmiral", "id": 100}'
test.headers = {u"Content-Type": u"application/json"}
test_response = resttest.run_test(test)
self.assertEqual(True, test_response.passed)
self.assertEqual(201, test_response.response_code)
# Test it was actually created
test2 = Test()
test2.url = test.url
test_response2 = resttest.run_test(test2)
self.assertTrue(test_response2.passed)
self.assertTrue(u'"last_name": "Adama"' in test_response2.unicode_body())
self.assertTrue(u'"login": "theadmiral"' in test_response2.unicode_body())
示例9: test_patch
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_patch(self):
""" Basic local get test """
test = Test()
test.url = self.prefix + "/api/person/2/"
test.method = "PATCH"
test.body = '{"login":"special"}'
test.headers = {u"Content-Type": u"application/json", u"X-HTTP-Method-Override": u"PATCH"}
test.expected_status = [202, 400] # Django issues give a 400, sigh
test_response = resttest.run_test(test)
self.assertTrue(test_response.passed)
示例10: test_put_inplace
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_put_inplace(self):
""" Test PUT where item already exists """
test = Test()
test.url = self.prefix + "/api/person/1/"
test.method = u"PUT"
test.body = '{"first_name": "Gaius","id": 1,"last_name": "Baltar","login": "gbaltar"}'
test.headers = {u"Content-Type": u"application/json"}
test_response = resttest.run_test(test)
self.assertEqual(True, test_response.passed)
self.assertEqual(200, test_response.response_code)
示例11: test_header_validators
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_header_validators(self):
test = Test()
test.url = self.prefix + "/api/person/1/"
config = {"header": "server", "comparator": "contains", "expected": "WSGI"}
test.validators = list()
test.validators.append(validators.parse_validator("comparator", config))
result = resttest.run_test(test)
if result.failures:
for fail in result.failures:
print(fail)
self.assertTrue(result.passed)
示例12: test_delete
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_delete(self):
""" Try removing an item """
test = Test()
test.url = self.prefix + "/api/person/1/"
test.expected_status = [200, 202, 204]
test.method = u"DELETE"
test_response = resttest.run_test(test)
self.assertEqual(True, test_response.passed)
self.assertEqual(204, test_response.response_code)
# Verify it's really gone
test.method = u"GET"
test.expected_status = [404]
test_response = resttest.run_test(test)
self.assertEqual(True, test_response.passed)
self.assertEqual(404, test_response.response_code)
# Check it's gone by name
test2 = Test()
test2.url = self.prefix + "/api/person/?first_name__contains=Gaius"
test_response2 = resttest.run_test(test2)
self.assertTrue(test_response2.passed)
self.assertTrue(u'"objects": []' in test_response2.unicode_body())
示例13: test_get_validators_fail
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_get_validators_fail(self):
""" Test validators that should fail """
test = Test()
test.url = self.prefix + '/api/person/'
test.validators = list()
cfg_exists = {'jsonpath_mini': "objects.500", 'test':'exists'}
test.validators.append(validators.parse_validator('extract_test', cfg_exists))
cfg_not_exists = {'jsonpath_mini': "objects.1", 'test':'not_exists'}
test.validators.append(validators.parse_validator('extract_test', cfg_not_exists))
cfg_compare = {'jsonpath_mini': "objects.1.last_name", 'expected':'NotJenkins'}
test.validators.append(validators.parse_validator('compare', cfg_compare))
test_response = resttest.run_test(test)
self.assertFalse(test_response.passed)
self.assertTrue(test_response.failures)
self.assertEqual(3, len(test_response.failures))
示例14: test_get_validators_fail
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_get_validators_fail(self):
""" Test validators that should fail """
test = Test()
test.url = self.prefix + "/api/person/"
test.validators = list()
cfg_exists = {"jsonpath_mini": "objects.500", "test": "exists"}
test.validators.append(validators.parse_validator("extract_test", cfg_exists))
cfg_not_exists = {"jsonpath_mini": "objects.1", "test": "not_exists"}
test.validators.append(validators.parse_validator("extract_test", cfg_not_exists))
cfg_compare = {"jsonpath_mini": "objects.1.last_name", "expected": "NotJenkins"}
test.validators.append(validators.parse_validator("compare", cfg_compare))
test_response = resttest.run_test(test)
self.assertFalse(test_response.passed)
self.assertTrue(test_response.failures)
self.assertEqual(3, len(test_response.failures))
示例15: test_header_validators
# 需要导入模块: from tests import Test [as 别名]
# 或者: from tests.Test import url [as 别名]
def test_header_validators(self):
test = Test()
test.url = self.prefix + '/api/person/1/'
config = {
'header': 'server',
'comparator': 'contains',
'expected': 'WSGI'
}
test.validators = list()
test.validators.append(
validators.parse_validator('comparator', config))
result = resttest.run_test(test)
if result.failures:
for fail in result.failures:
print(fail)
self.assertTrue(result.passed)