<s> from decimal import Decimal <EOL> from django . contrib . sites . models import Site <EOL> from django . test import TestCase <EOL> from product . models import Option , OptionGroup , Product , Price <EOL> from product . modules . configurable . models import ConfigurableProduct , ProductVariation <EOL> import datetime <EOL> import keyedcache <EOL> from product . utils import serialize_options , productvariation_details <EOL> class OptionUtilsTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_base_sort_order ( self ) : <EOL> p = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> serialized = serialize_options ( p . configurableproduct ) <EOL> self . assert_ ( len ( serialized ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( serialized [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] , <NUM_LIT:1> ) <EOL> got_vals = [ opt . value for opt in serialized [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ] <EOL> self . assertEqual ( got_vals , [ '<STR_LIT:S>' , '<STR_LIT:M>' , '<STR_LIT:L>' ] ) <EOL> self . assertEqual ( serialized [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , <NUM_LIT:2> ) <EOL> def test_reordered ( self ) : <EOL> p = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> pv = p . configurableproduct . productvariation_set . all ( ) [ <NUM_LIT:0> ] <EOL> orig_key = pv . optionkey <EOL> orig_detl = productvariation_details ( p , False , None , create = True ) <EOL> sizegroup = OptionGroup . objects . get ( name = "<STR_LIT>" ) <EOL> sizegroup . sort_order = <NUM_LIT:100> <EOL> sizegroup . save ( ) <EOL> for opt in sizegroup . option_set . all ( ) : <EOL> opt . sort_order = <NUM_LIT:100> - opt . sort_order <EOL> opt . save ( ) <EOL> serialized = serialize_options ( p . configurableproduct ) <EOL> self . assert_ ( len ( serialized ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( serialized [ <NUM_LIT:1> ] [ '<STR_LIT:id>' ] , <NUM_LIT:1> ) <EOL> got_vals = [ opt . value for opt in serialized [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ] <EOL> self . assertEqual ( got_vals , [ '<STR_LIT:L>' , '<STR_LIT:M>' , '<STR_LIT:S>' ] ) <EOL> pv2 = ProductVariation . objects . get ( pk = pv . pk ) <EOL> self . assertEqual ( orig_key , pv2 . optionkey ) <EOL> reorder_detl = productvariation_details ( p , False , None ) <EOL> self . assertEqual ( orig_detl , reorder_detl ) <EOL> class OptionGroupTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . site = Site . objects . get_current ( ) <EOL> sizes = OptionGroup . objects . create ( name = "<STR_LIT>" , sort_order = <NUM_LIT:1> , site = self . site ) <EOL> option_small = Option . objects . create ( option_group = sizes , name = "<STR_LIT>" , value = "<STR_LIT>" , sort_order = <NUM_LIT:1> ) <EOL> option_large = Option . objects . create ( option_group = sizes , name = "<STR_LIT>" , value = "<STR_LIT>" , sort_order = <NUM_LIT:2> , price_change = <NUM_LIT:1> ) <EOL> colors = OptionGroup . objects . create ( name = "<STR_LIT>" , sort_order = <NUM_LIT:2> , site = self . site ) <EOL> option_black = Option . objects . create ( option_group = colors , name = "<STR_LIT>" , value = "<STR_LIT>" , sort_order = <NUM_LIT:1> ) <EOL> option_white = Option . objects . create ( option_group = colors , name = "<STR_LIT>" , value = "<STR_LIT>" , sort_order = <NUM_LIT:2> , price_change = <NUM_LIT:3> ) <EOL> option_white . price_change = <NUM_LIT:5> <EOL> option_white . sort_order = <NUM_LIT:2> <EOL> option_white . save ( ) <EOL> self . sizes = sizes <EOL> self . option_small = option_small <EOL> self . option_large = option_large <EOL> self . colors = colors <EOL> self . option_black = option_black <EOL> self . option_white = option_white <EOL> def testConfigurable ( self ) : <EOL> """<STR_LIT>""" <EOL> django_shirt = Product . objects . create ( slug = "<STR_LIT>" , name = "<STR_LIT>" , site = self . site ) <EOL> shirt_price = Price . objects . create ( product = django_shirt , price = "<STR_LIT>" ) <EOL> django_config = ConfigurableProduct . objects . create ( product = django_shirt ) <EOL> django_config . option_group . add ( self . sizes , self . colors ) <EOL> ordering = django_config . option_group . order_by ( '<STR_LIT:name>' ) <EOL> self . assertEqual ( ordering [ <NUM_LIT:0> ] , self . colors ) <EOL> self . assertEqual ( ordering [ <NUM_LIT:1> ] , self . sizes ) <EOL> django_config . save ( ) <EOL> white_shirt = Product . objects . create ( slug = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , site = self . site ) <EOL> pv_white = ProductVariation . objects . create ( product = white_shirt , parent = django_config ) <EOL> pv_white . options . add ( self . option_white , self . option_small ) <EOL> self . assertEqual ( pv_white . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> def testConfigurableSlugs ( self ) : <EOL> """<STR_LIT>""" <EOL> django_shirt = Product . objects . create ( slug = "<STR_LIT>" , name = "<STR_LIT>" , site = self . site ) <EOL> shirt_price = Price . objects . create ( product = django_shirt , price = "<STR_LIT>" ) <EOL> django_config = ConfigurableProduct . objects . create ( product = django_shirt ) <EOL> django_config . option_group . add ( self . sizes , self . colors ) <EOL> django_config . save ( ) <EOL> clash_shirt = Product . objects . create ( slug = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , site = self . site ) <EOL> django_config . create_subs = True <EOL> django_config . save ( ) <EOL> self . assertEqual ( ProductVariation . objects . filter ( parent = django_config ) . count ( ) , <NUM_LIT:4> ) <EOL> class ProductTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def tearDown ( self ) : <EOL> keyedcache . cache_delete ( ) <EOL> def test_quantity_price_productvariation ( self ) : <EOL> """<STR_LIT>""" <EOL> product = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( product . unit_price , product . get_qty_price ( Decimal ( '<STR_LIT:1>' ) ) ) <EOL> product = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( product . unit_price , product . get_qty_price ( Decimal ( '<STR_LIT:1>' ) ) ) <EOL> product = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( product . unit_price , product . get_qty_price ( Decimal ( '<STR_LIT:1>' ) ) ) <EOL> def test_quantity_price_productvariation_expiring ( self ) : <EOL> """<STR_LIT>""" <EOL> product = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( product . unit_price , product . get_qty_price ( Decimal ( '<STR_LIT:1>' ) ) ) <EOL> today = datetime . datetime . now ( ) <EOL> aweek = datetime . timedelta ( days = <NUM_LIT:7> ) <EOL> nextwk = today + aweek <EOL> price = Price . objects . create ( product = product , quantity = Decimal ( '<STR_LIT:1>' ) , price = Decimal ( "<STR_LIT>" ) , expires = nextwk ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> product = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> product = Product . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> pvprice = Price . objects . create ( product = product , quantity = Decimal ( '<STR_LIT:1>' ) , price = Decimal ( "<STR_LIT>" ) , expires = nextwk ) <EOL> self . assertEqual ( product . unit_price , Decimal ( "<STR_LIT>" ) ) <EOL> class ConfigurableProductTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def tearDown ( self ) : <EOL> keyedcache . cache_delete ( ) <EOL> def test_get_variations_for_options ( self ) : <EOL> dj_rocks = ConfigurableProduct . objects . get ( product__slug = "<STR_LIT>" ) <EOL> option_small = Option . objects . get ( pk = <NUM_LIT:1> ) <EOL> option_black = Option . objects . get ( pk = <NUM_LIT:4> ) <EOL> option_hard_cover = Option . objects . get ( pk = <NUM_LIT:7> ) <EOL> self . assertEqual ( [ variation . pk for variation in <EOL> dj_rocks . get_variations_for_options ( [ option_small ] ) ] , [ <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( [ variation . pk for variation in <EOL> dj_rocks . get_variations_for_options ( [ option_small , option_black ] ) ] , <EOL> [ <NUM_LIT:6> ] ) <EOL> self . assertEqual ( <EOL> len ( dj_rocks . get_variations_for_options ( [ option_hard_cover ] ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( [ variation . pk for variation in <EOL> dj_rocks . get_variations_for_options ( [ ] ) ] , <EOL> [ <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import doctest <EOL> doctest . testmod ( ) </s>
