コード例 #1
0
def test_CreateProduct(httpConnection, data, expected):
    userUUID = common.addUser(data, httpConnection)
    if userUUID is None:
        return

    dataToSend = dict()
    dataToSend["product"] = data["product"]
    dataToSend["user"] = userUUID

    try:
        r = httpConnection.POST("/add-product", dataToSend)
    except Exception:
        pytest.fail("Failed to send POST request")
        return

    response = common.getResponse(r.text, expected)
    if response is None:
        return None
    if r.status_code == 201:
        if response["name"] != expected["name"]:
            pytest.fail(
                f"Test failed\nReturned: {response}\nExpected: {expected}")
        return

    if response != expected:
        pytest.fail(f"Request failed\nStatus code: \
            {r.status_code}\nReturned: {response}\nExpected: {expected}")
コード例 #2
0
def test_GetProduct(httpConnection, data, expected):
    userUUID = common.addUser(data, httpConnection)
    if userUUID is None:
        return

    productUUID = common.addProduct(data, userUUID, httpConnection)
    if productUUID is None:
        return

    try:
        r = httpConnection.GET("/get-product-by-id", {"id": productUUID})
    except Exception:
        pytest.fail("Failed to send GET request")
        return

    response = common.getResponse(r.text, expected)
    if response is None:
        return None
    if r.status_code == 200:
        try:
            status = handleProductIDCheck(response, expected)
            if status is None:
                return

            if response != expected:
                pytest.fail(
                    f"Test failed\nReturned: {response}\nExpected: {expected}")
            return
        except Exception as e:
            pytest.fail(f"Failed to compare results.\nDetails: {e}")
            return

    if response != expected:
        pytest.fail(f"Request failed\nStatus code: \
            {r.status_code}\nReturned: {response}\nExpected: {expected}")
コード例 #3
0
def test_GetProducts(httpConnection, data, expected):
    uuidList = list()
    userUUID = common.addUser(data, httpConnection)
    if userUUID is None:
        return

    if "product" in data:
        for element in data["product"]:
            if "name" in element:
                dataToSend = dict()
                dataToSend["product"] = element
                if userUUID == "":
                    pytest.fail("Missing user test data")
                    return
                dataToSend["user"] = userUUID
                try:
                    r = httpConnection.POST("/add-product", dataToSend)
                except Exception:
                    pytest.fail("Failed to send POST request")
                    return

                if r.status_code != 201:
                    pytest.fail(f"Failed to add product.\nDetails: {r.text}")
                    return

                response = common.getResponse(r.text, expected)
                if response is None:
                    return None
                uuidList.append(response["id"])
            else:
                uuidList.append(element["product_id"])

    try:
        r = httpConnection.GET("/get-products", {"ids": uuidList})
    except Exception:
        pytest.fail("Failed to send GET request")
        return

    response = common.getResponse(r.text, expected)
    if response is None:
        return None
    if r.status_code == 200:
        try:
            for index, product in enumerate(response):
                status = handleProductIDCheck(product, expected[index])
                if status is None:
                    return
                if response[index] != expected[index]:
                    pytest.fail(f"Test failed\n\
Returned: {response[index]}\nExpected: {expected[index]}")
            return
        except Exception as e:
            pytest.fail(f"Failed to compare results.\nDetails: {e}")
            return

    if response != expected:
        pytest.fail(f"Request failed\nStatus code: \
            {r.status_code}\nReturned: {response}\nExpected: {expected}")
コード例 #4
0
def test_AddProductUsers(httpConnection, data, expected):
    partnerUUIDs = list()

    userUUID = common.addUser(data, httpConnection)
    if userUUID is None:
        return

    productUUID = common.addProduct(data, userUUID, httpConnection)
    if productUUID is None:
        return

    if "partner_user" in data:
        for user in data["partner_user"]:
            try:
                r = httpConnection.POST("/add-user", user["user"])
            except Exception:
                pytest.fail("Failed to send POST request")
                return

            response = common.getResponse(r.text, expected)
            if response is None:
                return None
            if r.status_code != 201:
                pytest.fail(f"Failed to add product.\nDetails: {response}")
                return

            partnerUUID = dict()
            partnerUUID["id"] = response["id"]
            partnerUUID["privilege"] = user["privilege"]
            partnerUUIDs.append(partnerUUID)

    dataToSend = dict()
    dataToSend["product_id"] = productUUID
    dataToSend["users"] = partnerUUIDs
    try:
        r = httpConnection.POST("/add-product-user", dataToSend)
    except Exception:
        pytest.fail("Failed to send POST request")
        return

    response = common.getResponse(r.text, expected)
    if response is None:
        return None
    if response != expected:
        pytest.fail(f"Request failed\nStatus code: \
            {r.status_code}\nReturned: {response}\nExpected: {expected}")
コード例 #5
0
def test_UpdateProjectAsset(httpConnection, data, expected):
    dataToSend = dict()
    userUUID = common.addUser(data, httpConnection)
    if userUUID is None:
        return

    productUUID = common.addProduct(data, userUUID, httpConnection)
    if productUUID is None:
        return

    dataToSend["project"] = data["project"]
    dataToSend["product_id"] = productUUID
    dataToSend["owner_id"] = userUUID
    if "project" in data:
        try:
            r = httpConnection.POST("/add-project", dataToSend)
        except Exception:
            pytest.fail("Failed to send POST request")
            return

        if r.status_code != 201:
            pytest.fail(f"Failed to add project.\nDetails: {r.text}")
            return
        response = common.getResponse(r.text, expected)
        if response is None:
            return None

        dataToSend = dict()
        dataToSend["project"] = response
        for k, v in data["details_entry"].items():
            dataToSend["project"]["assets"]["datamap"][k] = v

    try:
        r = httpConnection.POST("/update-project-assets", dataToSend)
    except Exception:
        pytest.fail("Failed to send POST request")
        return

    response = common.getResponse(r.text, expected)
    if response is None:
        return None
    if response != expected:
        pytest.fail(f"Request failed\nStatus code: \
            {r.status_code}\nReturned: {response}\nExpected: {expected}")
コード例 #6
0
def test_DeleteProductUser(httpConnection, data, expected):
    userUUID = common.addUser(data, httpConnection)
    if userUUID is None:
        return

    productUUID = common.addProduct(data, userUUID, httpConnection)
    if productUUID is None:
        return

    dataToSend = dict()
    dataToSend["product_id"] = productUUID
    dataToSend["user_id"] = userUUID
    try:
        r = httpConnection.POST("/delete-product-user", dataToSend)
    except Exception:
        pytest.fail("Failed to send POST request")
        return

    response = common.getResponse(r.text, expected)
    if response is None:
        return None
    if response != expected:
        pytest.fail(f"Request failed\nStatus code: \
            {r.status_code}\nReturned: {response}\nExpected: {expected}")
コード例 #7
0
def test_DeleteUser(httpConnection, data, expected):
    userUUID = common.addUser(data, httpConnection)
    if userUUID is None:
        return

    productUUIDs = list()
    if "products_to_delete" in data:
        for product in data["products_to_delete"]:
            dataToSend = dict()
            dataToSend["product"] = product
            dataToSend["user"] = userUUID
            try:
                r = httpConnection.POST("/add-product", dataToSend)
            except Exception:
                pytest.fail("Failed to send POST request")
                return

            response = common.getResponse(r.text, expected)
            if response is None:
                return None
            if r.status_code != 201:
                pytest.fail(f"Failed to add user.\nDetails: {response}")
                return
            productUUIDs.append(response["id"])

    # Add nominated users and their product relationship
    nominatedUUIDs = list()
    if "nominated_users" in data:
        for nominatedUser in data["nominated_users"]:
            try:
                r = httpConnection.POST("/add-user", nominatedUser)
            except Exception:
                pytest.fail("Failed to send POST request")
                return

            response = common.getResponse(r.text, expected)
            if response is None:
                return None
            if r.status_code != 201:
                pytest.fail(
                    f"Failed to add nominated user.\nDetails: {r.text}")
                return

            nominatedUUIDs.append(response["id"])

            productUsers = list()
            productUser = dict()
            productUser["id"] = response["id"]
            productUser["privilege"] = 2
            productUsers.append(productUser)
            dataToSend = dict()
            dataToSend["product_id"] = productUUIDs[0]
            dataToSend["users"] = productUsers

            try:
                r = httpConnection.POST("/add-product-user", dataToSend)
            except Exception:
                pytest.fail("Failed to send POST request")
                return

            response = common.getResponse(r.text, expected)
            if response is None:
                return None
            if r.status_code != 201:
                pytest.fail(
                    f"Failed to add nominated user.\nDetails: {response}")
                return

    if len(nominatedUUIDs) > len(productUUIDs):
        pytest.fail("Too many nominated users.")
        return

    nominees = dict()
    for index, nominee in enumerate(nominatedUUIDs):
        nominees[productUUIDs[index]] = nominee

    try:
        r = httpConnection.POST("/delete-user", {
            "id": userUUID,
            "nominees": nominees
        })
    except Exception:
        pytest.fail("Failed to send POST request")
        return

    response = common.getResponse(r.text, expected)
    if response is None:
        return None
    if response != expected:
        pytest.fail(f"Request failed\nStatus code: \
            {r.status_code}\nReturned: {response}\nExpected: {expected}")