From 2f196926af51ae0422a3086d3f3b579bec677b02 Mon Sep 17 00:00:00 2001 From: Ritesh Shrivastav Date: Wed, 10 Aug 2016 16:22:15 +0530 Subject: [PATCH 1/2] Provision to fetch variant with 'id' [#128046895] --- spree/spree.py | 15 ++++++++++++++- tests/conftest.py | 5 +++++ tests/test_spree.py | 10 +++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/spree/spree.py b/spree/spree.py index 059c039..18e9544 100644 --- a/spree/spree.py +++ b/spree/spree.py @@ -22,7 +22,7 @@ def order(self): def get_stock_item(self, location_id): return StockItem(location_id, connection=self) - def get_variant(self, product_id): + def variant(self, product_id=None): return Variant(product_id, connection=self) @property @@ -257,6 +257,19 @@ def __init__(self, product_id, *args, **kwargs): def path(self): return '/products/%s/variants' % self.product_id + def get(self, id): + "Fetch a record with given id" + if not self.product_id: + path = self.connection.url + '/variants' + response = self.connection.session.get( + path, params={'q[id_eq]': id} + ) + self.validate_response(response) + response, = response.json()[self.item_attribute] + return response + + return super(Variant, self).get(id) + class Shipment(Resource): """ diff --git a/tests/conftest.py b/tests/conftest.py index b021ce4..8824b9c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -69,6 +69,11 @@ def resp(fp): 'http://mystore/api/products/ruby-on-rails-jr-spaghetti/variants', body=open(fp('responses/variant-ROR-00013.json'), 'r').read() ) + rsps.add( + responses.GET, + 'http://mystore/api/variants', + body=open(fp('responses/variant-ROR-00013.json'), 'r').read() + ) "Stock Locations" rsps.add( diff --git a/tests/test_spree.py b/tests/test_spree.py index dcba41e..806612f 100644 --- a/tests/test_spree.py +++ b/tests/test_spree.py @@ -98,9 +98,17 @@ def test_finding_one_stock_item(resp, spree): def test_variant_via_permalink(resp, spree): "test fetching variant by product permalink" - variant = spree.get_variant('ruby-on-rails-jr-spaghetti') + variant = spree.variant('ruby-on-rails-jr-spaghetti') test_variants = variant.find() test_variant = test_variants[0] assert test_variant['sku'] == 'ROR-00013' assert test_variant['price'] == '19.99' assert test_variant['cost_price'] == '17.0' + + +def test_variant_with_out_permalink(resp, spree): + "test fetching variant by product permalink" + variant = spree.variant().get(4) + assert variant['sku'] == 'ROR-00013' + assert variant['price'] == '19.99' + assert variant['cost_price'] == '17.0' From 21e4b66f525e6e5f449e203f5c622141ff6fcea0 Mon Sep 17 00:00:00 2001 From: Tarun Bhardwaj Date: Fri, 12 Aug 2016 20:04:56 +0530 Subject: [PATCH 2/2] Released version 0.4.2 --- setup.py | 2 +- spree/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index d9e04e2..0040ca2 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( name='spree', - version='0.4.1', + version='0.4.2', description="Spree python api client", long_description=readme + '\n\n' + history, author="Fulfil.IO Inc.", diff --git a/spree/__init__.py b/spree/__init__.py index 0c27300..b0d12d8 100644 --- a/spree/__init__.py +++ b/spree/__init__.py @@ -2,6 +2,6 @@ __author__ = 'Fulfil.IO Inc.' __email__ = 'info@fulfil.io' -__version__ = '0.4.1' +__version__ = '0.4.2' from .spree import Spree # noqa