Skip to content

Instantly share code, notes, and snippets.

@exit99
Created March 17, 2017 14:32
Show Gist options
  • Save exit99/122f7549e2126af31a95608e1f3cd8ce to your computer and use it in GitHub Desktop.
Save exit99/122f7549e2126af31a95608e1f3cd8ce to your computer and use it in GitHub Desktop.
import json
def mock_api_call(path, schema):
with open(schema, 'r') as f:
data = json.loads(f.read())
if path == "http://test.net/products":
return data["properties"]["items"]
elif path == "http://test.net/products/0"
return data["properties"]["items"][0]
# DANIEL: Continue this logic here for all the endpoints you need.
# This is probably not the best way to do it, but it is the easiest
# to understand, and at least you can finish the project quickly.
class Product(models.Model):
name = models.StringField(max_length=255)
description = models.StringField(max_length=255)
# Example of saving to db
product = mock_api_call("http://www.test.com/products/0", "product_list.schema")
Product.objects.create(name=product["name"], description=product["description"]
def product_list(request):
products = mock_api_call("http://www.test.com/products", "product_list.schema")
context = {"products": products}
return render(request, "mytemplate.html", context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment