# Path: databot/utils/urls.py
# def url(url, domains=None, query=None):
#     query = [query] if isinstance(query, str) else query or []
# 
#     url = urllib.parse.urlparse(url) if isinstance(url, str) else url
#     qry = urllib.parse.parse_qsl(url.query, keep_blank_values=True)
#     if query:
#         qry = [(k, v) for k, v in qry if k in query]
#     qry = sorted(qry)
# 
#     checks = [
#         check_domains(url, domains),
#         check_query(qry, query),
#     ]
#     if not all(checks):
#         return None
# 
#     url = url._replace(query=urllib.parse.urlencode(qry), fragment='')
#     return urllib.parse.urlunparse(url)


from databot.utils.urls import url


def test_url_domains():
    assert url('http://example.com', domains='example.com') == 'http://example.com'
    assert url('http://www.example.com', domains='example.com') is None

# Path: databot/utils/urls.py
# def url(url, domains=None, query=None):
#     query = [query] if isinstance(query, str) else query or []
# 
#     url = urllib.parse.urlparse(url) if isinstance(url, str) else url
#     qry = urllib.parse.parse_qsl(url.query, keep_blank_values=True)
#     if query:
#         qry = [(k, v) for k, v in qry if k in query]
#     qry = sorted(qry)
# 
#     checks = [
#         check_domains(url, domains),
#         check_query(qry, query),
#     ]
#     if not all(checks):
#         return None
# 
#     url = url._replace(query=urllib.parse.urlencode(qry), fragment='')
#     return urllib.parse.urlunparse(url)


# Path: tests/test_urls.py
from databot.utils.urls import url



def test_url_domains():
    assert url('http://example.com', domains='example.com') == 'http://example.com'
    assert url('http://www.example.com', domains='example.com') is None

    assert url('http://example.com', domains='www.example.com') is None