Skip to content

Commit

Permalink
Merge branch 'release/0.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunbhardwaj committed Aug 12, 2016
2 parents 1cf8c1d + 21e4b66 commit cc0b744
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion spree/__init__.py
Expand Up @@ -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
15 changes: 14 additions & 1 deletion spree/spree.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Expand Up @@ -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(
Expand Down
10 changes: 9 additions & 1 deletion tests/test_spree.py
Expand Up @@ -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'

0 comments on commit cc0b744

Please sign in to comment.