Joining strings to form a URL
You can simplify the solution if, instead of checking for a presence of the slash, you would str.strip() the slashes from both sides of each argument and then str.join() the arguments:

def slash_join(*args):
    return "/".join(arg.strip("/") for arg in args)


urljoin() unfortunately does not allow to join more than 2 url parts - it can only do a base and one more part. There is though this clever functools.reduce() usage that may help to adapt it here:

from urllib.parse import urljoin
from functools import reduce

def slash_join(*args):
    return reduce(urljoin, args).rstrip("/")


Note that I'm explicitly stripping a possible right slash but not sure if it is actually needed since the url with a trailing slash would still be valid - e.g. http://foo.com/test/.