def test_download_json_badjson(): with requests_mock.Mocker() as m: m.register_uri("GET", TEST_URL, text='{ not json lol }') with pytest.raises(MoulinetteError): download_json(TEST_URL)
def test_download_json_badjson(): with requests_mock.Mocker() as m: m.register_uri("GET", TEST_URL, text='{ not json lol }') with pytest.raises(MoulinetteError): download_json(TEST_URL)
def _dyndns_provides(provider, domain): """ Checks if a provider provide/manage a given domain. Keyword arguments: provider -- The url of the provider, e.g. "dyndns.yunohost.org" domain -- The full domain that you'd like.. e.g. "foo.nohost.me" Returns: True if the provider provide/manages the domain. False otherwise. """ logger.debug("Checking if %s is managed by %s ..." % (domain, provider)) try: # Dyndomains will be a list of domains supported by the provider # e.g. [ "nohost.me", "noho.st" ] dyndomains = download_json("https://%s/domains" % provider, timeout=30) except MoulinetteError as e: logger.error(str(e)) raise YunohostError("dyndns_could_not_check_provide", domain=domain, provider=provider) # Extract 'dyndomain' from 'domain', e.g. 'nohost.me' from 'foo.nohost.me' dyndomain = ".".join(domain.split(".")[1:]) return dyndomain in dyndomains
def test_download_json(): with requests_mock.Mocker() as m: m.register_uri("GET", TEST_URL, text='{ "foo":"bar" }') fetched_json = download_json(TEST_URL) assert "foo" in fetched_json.keys() assert fetched_json["foo"] == "bar"
def test_download_json(): with requests_mock.Mocker() as m: m.register_uri("GET", TEST_URL, text='{ "foo":"bar" }') fetched_json = download_json(TEST_URL) assert "foo" in fetched_json.keys() assert fetched_json["foo"] == "bar"
def _dyndns_available(provider, domain): """ Checks if a domain is available from a given provider. Keyword arguments: provider -- The url of the provider, e.g. "dyndns.yunohost.org" domain -- The full domain that you'd like.. e.g. "foo.nohost.me" Returns: True if the domain is available, False otherwise. """ logger.debug("Checking if domain %s is available on %s ..." % (domain, provider)) try: r = download_json("https://%s/test/%s" % (provider, domain), expected_status_code=None) except MoulinetteError as e: logger.error(str(e)) raise YunohostError("dyndns_could_not_check_available", domain=domain, provider=provider) return r == "Domain %s is available" % domain
def test_download_json_bad_json(test_url): with requests_mock.Mocker() as mock: mock.register_uri("GET", test_url, text="notjsonlol") with pytest.raises(MoulinetteError): download_json(test_url)
def test_download_json(test_url): with requests_mock.Mocker() as mock: mock.register_uri("GET", test_url, text='{"foo":"bar"}') fetched_json = download_json(test_url) assert "foo" in fetched_json.keys() assert fetched_json["foo"] == "bar"