<s> from decimal import Decimal as D <EOL> import factory <EOL> from django . conf import settings <EOL> from oscar . core . loading import get_model <EOL> from oscar . core . utils import slugify <EOL> from oscar . test . factories . utils import tax_add , tax_subtract <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> class BillingAddressFactory ( factory . DjangoModelFactory ) : <EOL> country = factory . SubFactory ( '<STR_LIT>' ) <EOL> first_name = '<STR_LIT>' <EOL> last_name = '<STR_LIT>' <EOL> line1 = '<STR_LIT>' <EOL> line2 = '<STR_LIT>' <EOL> line4 = '<STR_LIT>' <EOL> postcode = '<STR_LIT>' <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class ShippingAddressFactory ( factory . DjangoModelFactory ) : <EOL> country = factory . SubFactory ( '<STR_LIT>' ) <EOL> first_name = '<STR_LIT>' <EOL> last_name = '<STR_LIT>' <EOL> line1 = '<STR_LIT>' <EOL> line2 = '<STR_LIT>' <EOL> line4 = '<STR_LIT>' <EOL> postcode = '<STR_LIT>' <EOL> phone_number = '<STR_LIT>' <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class OrderDiscountFactory ( factory . DjangoModelFactory ) : <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class OrderFactory ( factory . DjangoModelFactory ) : <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exclude = ( '<STR_LIT>' , ) <EOL> if hasattr ( settings , '<STR_LIT>' ) : <EOL> status = settings . OSCAR_INITIAL_ORDER_STATUS <EOL> site_id = settings . SITE_ID <EOL> number = factory . LazyAttribute ( lambda o : '<STR_LIT>' % ( <NUM_LIT> + o . basket . pk ) ) <EOL> basket = factory . SubFactory ( <EOL> '<STR_LIT>' ) <EOL> shipping_code = '<STR_LIT>' <EOL> shipping_incl_tax = D ( '<STR_LIT>' ) <EOL> shipping_excl_tax = factory . LazyAttribute ( <EOL> lambda o : tax_subtract ( o . shipping_incl_tax ) ) <EOL> total_incl_tax = factory . LazyAttribute ( lambda o : o . basket . total_incl_tax ) <EOL> total_excl_tax = factory . LazyAttribute ( lambda o : o . basket . total_excl_tax ) <EOL> guest_email = factory . LazyAttribute ( <EOL> lambda o : ( <EOL> '<STR_LIT>' % ( <EOL> o . billing_address . first_name [ <NUM_LIT:0> ] , <EOL> o . billing_address . last_name <EOL> ) ) . lower ( ) ) <EOL> shipping_address = factory . SubFactory ( ShippingAddressFactory ) <EOL> billing_address = factory . SubFactory ( BillingAddressFactory ) <EOL> @ classmethod <EOL> def _create ( cls , target_class , * args , ** kwargs ) : <EOL> date_placed = kwargs . pop ( '<STR_LIT>' , None ) <EOL> instance = super ( OrderFactory , cls ) . _create ( <EOL> target_class , * args , ** kwargs ) <EOL> if date_placed : <EOL> instance . date_placed = date_placed <EOL> return instance <EOL> class OrderLineFactory ( factory . DjangoModelFactory ) : <EOL> order = factory . SubFactory ( OrderFactory ) <EOL> product = factory . SubFactory ( <EOL> '<STR_LIT>' ) <EOL> partner_sku = factory . LazyAttribute ( lambda l : l . product . upc ) <EOL> stockrecord = factory . LazyAttribute ( <EOL> lambda l : l . product . stockrecords . first ( ) ) <EOL> quantity = <NUM_LIT:1> <EOL> line_price_incl_tax = factory . LazyAttribute ( <EOL> lambda obj : tax_add ( obj . stockrecord . price_excl_tax ) * obj . quantity ) <EOL> line_price_excl_tax = factory . LazyAttribute ( <EOL> lambda obj : obj . stockrecord . price_excl_tax * obj . quantity ) <EOL> line_price_before_discounts_incl_tax = ( <EOL> factory . SelfAttribute ( '<STR_LIT>' ) ) <EOL> line_price_before_discounts_excl_tax = ( <EOL> factory . SelfAttribute ( '<STR_LIT>' ) ) <EOL> unit_price_incl_tax = factory . LazyAttribute ( <EOL> lambda obj : tax_add ( obj . stockrecord . price_excl_tax ) ) <EOL> unit_cost_price = factory . LazyAttribute ( <EOL> lambda obj : obj . stockrecord . cost_price ) <EOL> unit_price_excl_tax = factory . LazyAttribute ( <EOL> lambda obj : obj . stockrecord . price_excl_tax ) <EOL> unit_retail_price = factory . LazyAttribute ( <EOL> lambda obj : obj . stockrecord . price_retail ) <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class ShippingEventTypeFactory ( factory . DjangoModelFactory ) : <EOL> name = '<STR_LIT>' <EOL> code = factory . LazyAttribute ( lambda o : slugify ( o . name ) . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) ) <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> django_get_or_create = ( '<STR_LIT:code>' , ) <EOL> class ShippingEventFactory ( factory . DjangoModelFactory ) : <EOL> order = factory . SubFactory ( OrderFactory ) <EOL> event_type = factory . SubFactory ( ShippingEventTypeFactory ) <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) </s>
