'Creates a tko test from pb_test.
Extracts data from pb_test by calling helper methods and
creates a tko test using the models.test constructor.
:param:
test: a pb_test where fields will be extracted from.
:return: a new instance of models.test'

def get_tko_test(self, test):

    fields_dict = self.get_trivial_attr(test, self.test_type_dict)
    fields_dict['kernel'] = self.get_tko_kernel(test.kernel)
    fields_dict['iterations'] = [self.get_tko_iteration(iteration) for iteration in test.iterations]
    fields_dict['attributes'] = dict(((keyval.name, keyval.value) for keyval in test.attributes))
    fields_dict['labels'] = list(test.labels)
    return models.test(fields_dict['subdir'], fields_dict['testname'], fields_dict['status'], fields_dict['reason'], fields_dict['kernel'], fields_dict['machine'], fields_dict['started_time'], fields_dict['finished_time'], fields_dict['iterations'], fields_dict['attributes'], fields_dict['labels'])
