1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
import os
import sys
import unittest
from pyactiveresource.activeresource import ActiveResource
from pyactiveresource.testing import http_fake
import shopify
class TestCase(unittest.TestCase):
def setUp(self):
ActiveResource.site = None
ActiveResource.headers = None
shopify.ShopifyResource.clear_session()
shopify.ShopifyResource.site = "https://this-is-my-test-show.myshopify.com/admin/api/unstable"
shopify.ShopifyResource.password = None
shopify.ShopifyResource.user = None
http_fake.initialize()
self.http = http_fake.TestHandler
self.http.set_response(Exception("Bad request"))
self.http.site = "https://this-is-my-test-show.myshopify.com"
def load_fixture(self, name, format="json"):
with open(os.path.dirname(__file__) + "/fixtures/%s.%s" % (name, format), "rb") as f:
return f.read()
def fake(self, endpoint, **kwargs):
body = kwargs.pop("body", None) or self.load_fixture(endpoint)
format = kwargs.pop("format", "json")
method = kwargs.pop("method", "GET")
prefix = kwargs.pop("prefix", "/admin/api/unstable")
if "extension" in kwargs and not kwargs["extension"]:
extension = ""
else:
extension = ".%s" % (kwargs.pop("extension", "json"))
url = "https://this-is-my-test-show.myshopify.com%s/%s%s" % (prefix, endpoint, extension)
try:
url = kwargs["url"]
except KeyError:
pass
headers = {}
if kwargs.pop("has_user_agent", True):
userAgent = "ShopifyPythonAPI/%s Python/%s" % (shopify.VERSION, sys.version.split(" ", 1)[0])
headers["User-agent"] = userAgent
try:
headers.update(kwargs["headers"])
except KeyError:
pass
code = kwargs.pop("code", 200)
self.http.respond_to(
method, url, headers, body=body, code=code, response_headers=kwargs.pop("response_headers", None)
)
|