Im trying to write a custom extractor for json arrays. Essentially I have a list of objects and I would like to extract the UUID given a name for an object
Context.. My http response looks something like this. List of roles..
Here is my extractor code in its own file "extractor_custom.py"
import pyresttest.validators as validators
class RoleExtractorFromListWithRoleName(validators.AbstractExtractor):
validators.AbstractExtractor.is_header_extractor = False
## Parse method
@staticmethod
def parse(config):
print "*** In Parse ... ***"
extractor = RoleExtractorFromListWithOrgIdAndRoleName()
extractor.config = config
extractor.roles = config.get('roles')
extractor.roleName = config.get('roleName')
return extractor
## Method to extract role id from a list of roles based on Role Name
@classmethod
def extract_role_id_with_name(self, config):
print "*** In Extraction Fn ... ***"
self = self.parse(config)
if not self.roles:
print "\n*** No Roles to iterate through ***\n"
return None
for role in self.roles:
print "*************"
current_role_name = role.get('name').lower()
if self.roleName.lower() in current_role_name:
print current_role_name
return role.get('id')
print "*************\n"
return None
Here's the error I get when i try to run that test
*** In Extraction Fn ... ***
*** In Parse ... ***
config == {'roleName': 'Adminstrator', 'jsonpath_mini': '.', 'roles': '.'}
extractor == .
*************
role ==> .
Traceback (most recent call last):
File "/Users/pshokeen/Library/Python/2.7/bin/pyresttest", line 4, in <module>
resttest.command_line_run(sys.argv[1:])
File "/Users/pshokeen/Library/Python/2.7/lib/python/site-packages/pyresttest/resttest.py", line 913, in command_line_run
main(args)
File "/Users/pshokeen/Library/Python/2.7/lib/python/site-packages/pyresttest/resttest.py", line 826, in main
working_directory=os.path.dirname(test_file), vars=my_vars)
File "/Users/pshokeen/Library/Python/2.7/lib/python/site-packages/pyresttest/resttest.py", line 213, in parse_testsets
base_url, import_test_structure, test_files, vars=vars)
File "/Users/pshokeen/Library/Python/2.7/lib/python/site-packages/pyresttest/resttest.py", line 224, in parse_testsets
mytest = Test.parse_test(base_url, child)
File "/Users/pshokeen/Library/Python/2.7/lib/python/site-packages/pyresttest/tests.py", line 377, in parse_test
extractor_type, extractor_config)
File "/Users/pshokeen/Library/Python/2.7/lib/python/site-packages/pyresttest/validators.py", line 492, in parse_extractor
parsed = parse(config)
File "/Users/pshokeen/code/acceptance-testing/mashery_extractors.py", line 39, in extract_role_id_with_name
current_role_name = role.get('name').lower()
AttributeError: 'str' object has no attribute 'get'
Hi @svanoort
Im trying to write a custom extractor for json arrays. Essentially I have a list of objects and I would like to extract the UUID given a name for an object
Context.. My http response looks something like this. List of roles..
Here is my extractor code in its own file "extractor_custom.py"
Ive registered it as an "EXTRACTOR"
The problem arises when i try to plug it in a yaml test file. Sample Test case
Here's the error I get when i try to run that test