def test_json_parsing(): test_json = """ { "order" : { "product" : "rails training", "description" : "rest training", "price" : "512.45", "link" : [ { "rel" : "self", "href" : "http://www.caelum.com.br/orders/1"}, { "rel" : "payment", "href" : "http://www.caelum.com.br/orders/1/payment"} ] } } """ resource = JsonResource(json.loads(test_json)) links = resource.links() assert len(resource) == 1 assert len(resource.order) == 4 assert len(links) == 2 assert links.self.rel == "self" assert links.self.href == "http://www.caelum.com.br/orders/1" assert links.payment.rel == "payment" assert links.payment.href == "http://www.caelum.com.br/orders/1/payment"
def test_json_parsing(): test_json = """ { "order" : { "product" : "rails training", "description" : "rest training", "price" : "512.45", "link" : [ { "rel" : "self", "href" : "http://www.caelum.com.br/orders/1"}, { "rel" : "payment", "href" : "http://www.caelum.com.br/orders/1/payment"} ] } } """ resource = JsonResource(json.loads(test_json)) links = resource.links() assert len(resource) == 1 assert len(resource.order) == 4 assert len(links) == 2 assert links.self.rel == "self" assert links.self.href == "http://www.caelum.com.br/orders/1" assert links.payment.rel == "payment" assert links.payment.href == "http://www.caelum.com.br/orders/1/payment"
def test_json_without_links(): test_json = """ { "order" : { "product" : "rails training", "description" : "rest training", "price" : "512.45" } } """ resource = JsonResource(json.loads(test_json)) links = resource.links() assert len(links) == 0
def test_json_without_links(): test_json = """ { "order" : { "product" : "rails training", "description" : "rest training", "price" : "512.45" } } """ resource = JsonResource(json.loads(test_json)) links = resource.links() assert len(links) == 0