If you haven’t read the installation and setup instructions, please visit them here. This also includes a basic example in working with the data model as well.

Example 2: Automated Test runs:

In this example we’ll iterate through a Project’s set of items, find any unverified requirements, determine if a test exists, and then if so, kick off the test to change the status

Before we start, we’ll want to create a helper function that creates a lookup table of all items in the project’s dataset. This data is returned by the API as a list, so we turn it into a dictionary.

""" get_unique_project_item_lut(itemlist):
    returns a dictonary where item's dataid is used as key

    params:
    itemlist = list response from verve_py.get.item_pid_pid
               in form of [item_dict, item_dict...]
"""
def get_unique_project_item_lut(itemlist):
    return {item['did']:item for item in itemlist}
PY

Second, we’ll set a project ID and retrieve the projects

project_id = 0

## pull requirements list
itemlist = verve_py.get.item_pid_pid(project_id)
print("Retrieved %i items" % len(itemlist))

## generate a lookup table of all items
itemdict = get_unique_project_item_lut(itemlist)
print("Item ID's retrieved:", list(itemdict.keys()))
PY

Next, let's break out the items based on their type and create separate lists of Verification Events and Requirements. You can do this with any item type stored in the database

## tell the user what we found
reqlist = list(filter(lambda s: s['type'] == "Requirement", itemlist))
velist = list(filter(lambda s: s['type'] == "Verification", itemlist))
print("Found %i requirements and %i verifications" % (len(reqlist), len(velist)))
PY

Let's step through each of the Verification Events and run a test for each one of them. After the “test” completes, we’ll set the status to be one of the following:

  • unverified

  • in_progress

  • verified

  • failed

This is further detailed on the Item API page. In this example, we’re updating all of the items to verified.

## showing off individual verification events
for ve in velist:
    ve_status = ve['verification_status']
    print("Processing %s " % ve['title'])
    if ve_status[0] != 'Verified':
        print("Running test...")
        ## Perform your test operation here
        payload = json.dumps({"verification_status": "verified", "title": ve['title']})
        resp = verve_py.put.item_did_did(ve['did'], payload)

print("done")
PY

After we upload, lets retrieve the updated items and print the updated list of Verification Events

# refresh project list
itemlist = verve_py.get.item_pid_pid(project_id)
velist = list(filter(lambda s: s['type'] == "Verification", itemlist))
import pprint
pprint.pprint(velist)
PY