<s> import sys <EOL> import pytest <EOL> from decimal import Decimal <EOL> from datetime import datetime <EOL> pytestmark = pytest . mark . skipif ( <EOL> sys . version_info > ( <NUM_LIT:2> , <NUM_LIT:8> ) , reason = '<STR_LIT>' ) <EOL> try : <EOL> from pony . orm import * <EOL> db = Database ( "<STR_LIT>" , "<STR_LIT>" , create_db = True ) <EOL> class Customer ( db . Entity ) : <EOL> address = Required ( unicode ) <EOL> country = Required ( unicode ) <EOL> email = Required ( unicode , unique = True ) <EOL> name = Required ( unicode ) <EOL> password = Required ( unicode ) <EOL> cart_items = Set ( "<STR_LIT>" ) <EOL> orders = Set ( "<STR_LIT>" ) <EOL> class Product ( db . Entity ) : <EOL> id = PrimaryKey ( int , auto = True ) <EOL> name = Required ( unicode ) <EOL> categories = Set ( "<STR_LIT>" ) <EOL> description = Optional ( unicode ) <EOL> picture = Optional ( buffer ) <EOL> price = Required ( Decimal ) <EOL> quantity = Required ( int ) <EOL> cart_items = Set ( "<STR_LIT>" ) <EOL> order_items = Set ( "<STR_LIT>" ) <EOL> class CartItem ( db . Entity ) : <EOL> quantity = Required ( int ) <EOL> customer = Required ( Customer ) <EOL> product = Required ( Product ) <EOL> class OrderItem ( db . Entity ) : <EOL> quantity = Required ( int , default = <NUM_LIT:1> ) <EOL> price = Required ( Decimal ) <EOL> order = Required ( "<STR_LIT>" ) <EOL> product = Required ( Product ) <EOL> PrimaryKey ( order , product ) <EOL> class Order ( db . Entity ) : <EOL> id = PrimaryKey ( int , auto = True ) <EOL> state = Required ( unicode ) <EOL> date_created = Required ( datetime ) <EOL> date_shipped = Optional ( datetime ) <EOL> date_delivered = Optional ( datetime ) <EOL> total_price = Required ( Decimal ) <EOL> customer = Required ( Customer ) <EOL> items = Set ( OrderItem ) <EOL> class Category ( db . Entity ) : <EOL> name = Required ( unicode , unique = True ) <EOL> products = Set ( Product ) <EOL> db . generate_mapping ( create_tables = True ) <EOL> def test_backend ( ) : <EOL> from mixer . backend . pony import mixer <EOL> assert mixer <EOL> @ db_session <EOL> def test_mixer ( ) : <EOL> from mixer . backend . pony import mixer <EOL> customer = mixer . blend ( Customer ) <EOL> assert customer . name <EOL> assert customer . email <EOL> product = mixer . blend ( Product ) <EOL> assert product . price <EOL> order = mixer . blend ( Order ) <EOL> assert order . customer <EOL> orderitem = mixer . blend ( OrderItem , product = product ) <EOL> assert orderitem . quantity == <NUM_LIT:1> <EOL> assert orderitem . order <EOL> order = mixer . blend ( Order , customer__name = '<STR_LIT>' ) <EOL> assert order . customer . name == '<STR_LIT>' <EOL> with mixer . ctx ( commit = True ) : <EOL> order = mixer . blend ( Order ) <EOL> assert order . id <EOL> except ImportError : <EOL> pass </s>
