def test_build_headers(): with Client(*generate_opts_and_sess(ALT_MODE)) as c: headers = c._build_headers({}) assert headers[ACCESS_TOKEN_HEADER] == "123" with Client(*generate_opts_and_sess()) as c: headers = c._build_headers({}) assert ACCESS_TOKEN_HEADER not in headers
def test_rest_rate_limit(): with Client(*generate_opts_and_sess()) as c: for i in range(2): c.options.time_store.append(c.session, c.options.deferrer.current_time()) c.rest("get", "/admin/api/shop.json") assert len(c.options.time_store.all(c.session)) == 1
def test_rest_return(local_server): with Client(*generate_opts_and_sess()) as c: response = c.rest("get", "/admin/api/shop.json") assert isinstance(response.body, dict) assert response.body["shop"]["name"] == "Apple Computers" assert response.link.next is None assert response.link.prev is None assert response.errors is None
def test_rest_extract_link(): page_info = "eyJsYXN0X2lkIjo0MDkwMTQ0ODQ5OTgyLCJsYXN_0X3ZhbHVlIjoiPGh0bWw-PGh0bWw-MiBZZWFyIERWRCwgQmx1LVJheSwgU2F0ZWxsaXRlLCBhbmQgQ2FibGUgRnVsbCBDaXJjbGXihKIgMTAwJSBWYWx1ZSBCYWNrIFByb2R1Y3QgUHJvdGVjdGlvbiB8IDIgYW4gc3VyIGxlcyBsZWN0ZXVycyBEVkQgZXQgQmx1LXJheSBldCBwYXNzZXJlbGxlcyBtdWx0aW3DqWRpYXMgYXZlYyByZW1pc2Ugw6AgMTAwICUgQ2VyY2xlIENvbXBsZXQ8c3VwPk1DPFwvc3VwPjxcL2h0bWw-PFwvaHRtbD4iLCJkaXJlY3Rpb24iOiJuZXh0In0" with Client(*generate_opts_and_sess()) as c: result = c._rest_extract_link({ "link": f"<https://example.myshopify.com/admin/api/unstable/products.json?page_info={page_info}>; rel=\"next\"" }) assert result.next == page_info assert result.prev is None
def test_graphql_cost_limit(): with Client(*generate_opts_and_sess()) as c: for i in range(2): c.options.time_store.append(c.session, c.options.deferrer.current_time()) c.options.cost_store.append(c.session, 100) c.graphql("{ shop { name } }") assert len(c.options.time_store.all(c.session)) == 1 assert len(c.options.cost_store.all(c.session)) == 1
def test_graphql_retry(): with Client(*generate_opts_and_sess()) as c: response = c.graphql( query="{ shop { name } }", headers={ "x-test-status": f"{HTTPStatus.BAD_GATEWAY.value} {HTTPStatus.BAD_GATEWAY.phrase}" }, ) assert 502 in response.status assert response.retries == c.options.max_retries
def test_rest_retry(): with Client(*generate_opts_and_sess()) as c: response = c.rest( method="get", path="/admin/shop.json", headers={ "x-test-status": f"{HTTPStatus.BAD_GATEWAY.value} {HTTPStatus.BAD_GATEWAY.phrase}" }, ) assert 502 in response.status assert response.retries == c.options.max_retries
def test_rest_error_return(local_server): with Client(*generate_opts_and_sess()) as c: response = c.rest("get", "/admin/api/error.json") assert response.body is None assert response.errors == "Not found" response = c.rest("get", "/admin/api/errors.json") assert response.body is None assert response.errors == "Not found" response = c.rest("get", "/admin/api/decode_error.json") assert response.body is None assert isinstance(response.errors, JSONDecodeError)
def test_build_request(): with Client(*generate_opts_and_sess()) as c: request = c._build_request( method="get", path="/admin/api/shop.json", params={"fields": "id"}, ) assert "params" in request assert "2020-04" in request["url"] request = c._build_request( method="post", path="/admin/api/shop.json", params={"fields": "id"}, ) assert "json" in request
def test_graphql_return(local_server): with Client(*generate_opts_and_sess()) as c: response = c.graphql("{ shop { name } }") assert isinstance(response.body, dict) assert response.body["data"]["shop"]["name"] == "Apple Computers" assert response.errors is None
def test_is_authable(): with Client(*generate_opts_and_sess()) as c: assert c.is_authable("/admin/api/shop.json") is True assert c.is_authable("/oauth/access_token") is False
def test_version_path(): with Client(*generate_opts_and_sess()) as c: assert c.version_path("/admin/api/shop.json") == "/admin/api/2020-04/shop.json" assert c.version_path("/admin/api/shop.json", True) == "/admin/api/2020-04/shop.json"