Exemplo n.º 1
0
def user_id_role_check(user_id, role, expected_tf, assert_text):
    # This takes 2 requests to complete
    #    1: get the id of the user
    #    2: check that user has that role
    
    world.conn.request("GET", add_params(world.path_users + str(user_id) + "/roles"))
    response = world.conn.getresponse()
    assert_equal(response.status, 200, "Fetched a user")

    # walk through all roles for this user to see if it has the requested one
    
    roleJsonList = get_resp_list(response, ns("role")) 
    
    foundRole = False
    for roleJson in roleJsonList:
        assert isinstance(roleJson, dict), "unexpected type:\n" + jstr(roleJson)
        if (roleJson.get(ns("description")) == role):
            foundRole = True
    assert_equal(foundRole, expected_tf, assert_text + ": " + jstr(roleJsonList))
Exemplo n.º 2
0
def check_role_existence(roles):
    
    # fetch the user's resource identity
    world.conn.request("GET", add_params(world.path_roles))
    response = world.conn.getresponse()
    assert_equal(response.status, 200, "Fetched list of all roles")

    respJson = get_resp_list(response, "role")

    # now walk through the expected roles and check the response
    # to see that it is represented
    for exp_role in roles:
        found = False
        for act_role in respJson:
            exp = exp_role.get(ns("description"))
            act = act_role.get(ns("description"))
            if (exp == act):
                found = True
        assert_equal(found, True, "Didn't find role of:\n" + jstr(exp_role) + 
                     "\n in data:\n" + jstr(respJson))
Exemplo n.º 3
0
def product_foo_has_environment_bar(step, product, haveness, environment):
    # fetch the product's resource identity
    product_id = get_product_resid(product)
    
    
#    if haveness.strip() == "does not have":

    world.conn.request("GET", add_params(world.path_products + product_id + "/environments"))
    response = world.conn.getresponse()
    assert_equal(response.status, 200, "Fetched environments")

    jsonList = get_resp_list(response, "environment")

    found = False
    for item in jsonList:
        assert isinstance(item, dict), "expected a list of dicts in:\n" + jstr(jsonList)
        if (item.get(ns("name")) == environment):
            found = True
    
    shouldFind = (haveness == "has")
    assert_equal(found, shouldFind, "looking for environment of " + environment)
Exemplo n.º 4
0
def foo_has_these_assignments(step, name):
    user_id = get_user_resid(name)
    world.conn.request("GET", add_params(world.path_users + user_id + "/assignments"))
    response = world.conn.getresponse()
    assert_equal(response.status, 200, "Fetched a user")

    # walk through all roles for this user to see if it has the requested one
    respJson = get_resp_list(response, "testcase")

    # now walk through the expected roles and check the response
    # to see that it is represented
    exp_list = step.hashes
    for exp_item in exp_list:
        found = False
        for act_item in respJson:
            exp = exp_item.get(ns("name"))
            act = act_item.get(ns("name"))
            if (exp == act):
                found = True
        assert_equal(found, True, "expected assignment of: " + str(exp) +
                      "\nin response:\n" + jstr(respJson))
Exemplo n.º 5
0
def logged_in_as_user_foo(step, name):
    names = name.split()
    
    name_headers = { 'firstname':names[0], 'lastname': names[1] }

    world.conn.request("GET", add_params(world.path_users + "current"), None, name_headers)
    response = world.conn.getresponse()
    assert_equal(response.status, 200, "Fetched a user")
    
    thisUser = get_single_item(response, ns("user"))

    #save this off for later steps
    world.userResId = thisUser.get("resourceIdentity").get("id")
    assert world.userResId != None, "must have some value for user resourceIdentity: "+ jstr(thisUser)
    
    assert_equal(thisUser.get(ns("firstname")), names[0], "First Name field didn't match")
    assert_equal(thisUser.get(ns("lastname")), names[1], "Last Name field didn't match")
Exemplo n.º 6
0
def test_case_foo_has_attachment_bar(step, test_case, haveness, attachment):
    # fetch the test case's resource identity
    test_case_id = get_test_case_resid(test_case)
    
    
#    if haveness.strip() == "does not have":

    world.conn.request("GET", add_params(world.path_testcases + test_case_id + "/attachments"))
    response = world.conn.getresponse()
    assert_equal(response.status, 200, "Fetched environments")

    jsonList = get_resp_list(response, "attachment")

    found = False
    for item in jsonList:
        if (item.get(ns("fileName")) == attachment):
            found = True
    
    shouldFind = (haveness == "has")
    assert_equal(found, shouldFind, "looking for attachment of " + attachment + " in:\n" + jstr(jsonList))