Sobes.tech
Junior — Senior

Creating tests to verify link formation

livecode

Task condition

It is necessary to write a set of unit tests that confirm the correctness of URL construction by the function get(name, version, is_package). The function takes three parameters: the package name, its version, and a flag indicating that the request pertains to a package. Inside the function, the parameter is_package is overridden with the string ".json", after which the URL is formed as https://package.manager/{name}/{version}.{is_package} and returned. Commented code shows that there are plans to perform an HTTP request to the formed address in the future.

import requests

def get(name, version, is_package):
    is_package = ".json"
    url = f"https://package.manager/{name}/{version}.{is_package}"
    return url
    # result = requests.get(url)
    # return result

Tests should verify that for different values of name and version, the function returns the expected URL, and that overriding is_package does not affect the result.