def testCreate(self): c = Carrier(key="test", active=True) c.save() t = ShippingTier(carrier=c, min_total=Decimal("0.00"), price=Decimal("10.00"), ) t.save() self.assertEqual(c.price(Decimal("0.00")), Decimal("10.00"))
def testCreate(self): c = Carrier(key="test", active=True) c.save() product = Product.objects.get(slug='dj-rocks') p = ProductShippingPrice(carrier=c, product=product, price=Decimal("10.00"), ) p.save() self.assertEqual(c.price(product), Decimal("10.00"))
def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() base_prices = ( (0, 10), (20, 15), (30, 16), (40, 17) ) make_tiers(self.carrier, base_prices)
def test2Prices(self): c2 = Carrier(name="test2", active=True) c2.save() t = ProductShippingPrice(carrier=c2, product=self.product, price=Decimal("20.00"), ) t.save() self.assertEqual(self.carrier.price(self.product), Decimal("10.00")) self.assertEqual(c2.price(self.product), Decimal("20.00"))
def testCreate(self): c = Carrier(key="test", active=True) c.save() t = ShippingTier( carrier=c, min_total=Decimal("0.00"), price=Decimal("10.00"), ) t.save() self.assertEqual(c.price(Decimal("0.00")), Decimal("10.00"))
def testCreate(self): c = Carrier(key="test", active=True) c.save() t = QuantityTier(carrier=c, quantity=Decimal('1'), handling=Decimal("10.00"), price=Decimal("0.00"), ) t.save() self.assertEqual(c.price(1), Decimal("10.00")) self.assertEqual(c.price(4), Decimal("10.00"))
def test2Prices(self): c2 = Carrier(name="test2", active=True) c2.save() t = ProductShippingPrice( carrier=c2, product=self.product, price=Decimal("20.00"), ) t.save() self.assertEqual(self.carrier.price(self.product), Decimal("10.00")) self.assertEqual(c2.price(self.product), Decimal("20.00"))
def testCreate(self): c = Carrier(key="test", active=True) c.save() product = Product.objects.get(slug='dj-rocks') p = ProductShippingPrice( carrier=c, product=product, price=Decimal("10.00"), ) p.save() self.assertEqual(c.price(product), Decimal("10.00"))
def testCreate(self): c = Carrier(key="test", active=True) c.save() t = QuantityTier( carrier=c, quantity=Decimal('1'), handling=Decimal("10.00"), price=Decimal("0.00"), ) t.save() self.assertEqual(c.price(1), Decimal("10.00")) self.assertEqual(c.price(4), Decimal("10.00"))
class TieredCarrierPricingTest(TestCase): fixtures = [] def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() t = QuantityTier(carrier=self.carrier, quantity=Decimal('1'), handling=Decimal("10.00"), price=Decimal("0.00"), ) t.save() def testBase(self): self.assertEqual(self.carrier.price(1), Decimal("10.00")) self.assertEqual(self.carrier.price(10), Decimal("10.00")) self.assertEqual(self.carrier.price(100), Decimal("10.00")) def test2Prices(self): t = QuantityTier(carrier=self.carrier, quantity=Decimal('10'), handling=Decimal("100.00"), price=Decimal("1.00"), ) t.save() self.assertEqual(self.carrier.price(1), Decimal("10.00")) self.assertEqual(self.carrier.price(9), Decimal("10.00")) self.assertEqual(self.carrier.price(10), Decimal("110.00")) self.assertEqual(self.carrier.price(100), Decimal("200.00"))
class TieredCarrierPricingTest(TestCase): fixtures = [] def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() t = QuantityTier( carrier=self.carrier, quantity=Decimal('1'), handling=Decimal("10.00"), price=Decimal("0.00"), ) t.save() def testBase(self): self.assertEqual(self.carrier.price(1), Decimal("10.00")) self.assertEqual(self.carrier.price(10), Decimal("10.00")) self.assertEqual(self.carrier.price(100), Decimal("10.00")) def test2Prices(self): t = QuantityTier( carrier=self.carrier, quantity=Decimal('10'), handling=Decimal("100.00"), price=Decimal("1.00"), ) t.save() self.assertEqual(self.carrier.price(1), Decimal("10.00")) self.assertEqual(self.carrier.price(9), Decimal("10.00")) self.assertEqual(self.carrier.price(10), Decimal("110.00")) self.assertEqual(self.carrier.price(100), Decimal("200.00"))
def make_ship(self, ship_type): if ship_type == Constant.SHIP_TYPE_CARRIER: make_ship = Carrier() elif ship_type == Constant.SHIP_TYPE_BATTLE_SHIP: make_ship = Battleship() elif ship_type == Constant.SHIP_TYPE_CRUISER: make_ship = Cruiser() elif ship_type == Constant.SHIP_TYPE_DESTROYER: make_ship = Destroyer() elif ship_type == Constant.SHIP_TYPE_OIL_RIG: make_ship = Oilrig() else: make_ship = Carrier() return make_ship
def get_user_carriers(): '''Creates a tuple per user to create a selectfield with WTForms''' carriers = Carrier.get_carrier_by_user(user_id=session['user_id']) tup_carriers = [] for carrier in carriers: tup_carriers.append((carrier.id, carrier.name)) return tup_carriers
def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() t = ShippingTier(carrier=self.carrier, min_total=Decimal("0.00"), price=Decimal("10.00"), ) t.save()
class TieredCarrierExpiringTest(TestCase): fixtures = [] def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() base_prices = ( (1, 10, 0), (20, 20, 1), (30, 30, 2), (40, 40, 1) ) make_tiers(self.carrier, base_prices) def testExpired(self): dt = datetime(2000, 1, 1) sale_prices = ( (1, 1, 0), (20, 2, 1), (30, 3, 1), (40, 4, 1) ) make_tiers(self.carrier, sale_prices, expires=dt) self.assertEqual(self.carrier.price(1), Decimal("10.00")) self.assertEqual(self.carrier.price(20), Decimal("40.00")) self.assertEqual(self.carrier.price(30), Decimal("90.00")) self.assertEqual(self.carrier.price(100), Decimal("140.00")) def testNotExpired(self): now = timezone.now() nextyear = datetime(now.year+1, now.month, now.day) sale_prices = ( (1, 1, 0), (20, 2, 1), (30, 3, 1), (40, 4, 1) ) make_tiers(self.carrier, sale_prices, expires=nextyear) self.assertEqual(self.carrier.price(1), Decimal("1.00")) self.assertEqual(self.carrier.price(10), Decimal("1.00")) self.assertEqual(self.carrier.price(20), Decimal("22.00")) self.assertEqual(self.carrier.price(30), Decimal("33.00")) self.assertEqual(self.carrier.price(100), Decimal("104.00"))
def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() self.product = Product.objects.get(slug='dj-rocks') t = ProductShippingPrice(carrier=self.carrier, product=self.product, price=Decimal("10.00"), ) t.save()
def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() t = QuantityTier(carrier=self.carrier, quantity=Decimal('1'), handling=Decimal("10.00"), price=Decimal("0.00"), ) t.save()
class TieredCarrierExpiringTest(TestCase): fixtures = [] def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() base_prices = ( (0, 10), (20, 15), (30, 16), (40, 17) ) make_tiers(self.carrier, base_prices) def testExpired(self): dt = datetime(2000, 1, 1) sale_prices = ( (0, 1), (20, 2), (30, 3), (40, 4) ) make_tiers(self.carrier, sale_prices, expires=dt) self.assertEqual(self.carrier.price(Decimal("0.00")), Decimal("10.00")) self.assertEqual(self.carrier.price(Decimal("20.00")), Decimal("15.00")) self.assertEqual(self.carrier.price(Decimal("30.00")), Decimal("16.00")) self.assertEqual(self.carrier.price(Decimal("40.01")), Decimal("17.00")) def testNotExpired(self): now = datetime.now() nextyear = datetime(now.year+1, now.month, now.day) sale_prices = ( (0, 1), (20, 2), (30, 3), (40, 4) ) make_tiers(self.carrier, sale_prices, expires=nextyear) self.assertEqual(self.carrier.price(Decimal("0.00")), Decimal("1.00")) self.assertEqual(self.carrier.price(Decimal("20.00")), Decimal("2.00")) self.assertEqual(self.carrier.price(Decimal("30.00")), Decimal("3.00")) self.assertEqual(self.carrier.price(Decimal("40.01")), Decimal("4.00"))
def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() base_prices = ( (1, 10, 0), (20, 20, 1), (30, 30, 2), (40, 40, 1) ) make_tiers(self.carrier, base_prices)
class TieredCarrierPricingTest(TestCase): fixtures = [] def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() t = ShippingTier(carrier=self.carrier, min_total=Decimal("0.00"), price=Decimal("10.00"), ) t.save() def testBase(self): self.assertEqual(self.carrier.price(Decimal("0.00")), Decimal("10.00")) def test2Prices(self): t = ShippingTier(carrier=self.carrier, min_total=Decimal("20.00"), price=Decimal("15.00"), ) t.save() self.assertEqual(self.carrier.price(Decimal("0.00")), Decimal("10.00")) self.assertEqual(self.carrier.price(Decimal("20.00")), Decimal("15.00")) def test4Prices(self): prices = ( (20, 15), (30, 16), (40, 17) ) make_tiers(self.carrier, prices) self.assertEqual(self.carrier.price(Decimal("0.00")), Decimal("10.00")) self.assertEqual(self.carrier.price(Decimal("20.00")), Decimal("15.00")) self.assertEqual(self.carrier.price(Decimal("25.00")), Decimal("15.00")) self.assertEqual(self.carrier.price(Decimal("30.00")), Decimal("16.00")) self.assertEqual(self.carrier.price(Decimal("39.99")), Decimal("16.00")) self.assertEqual(self.carrier.price(Decimal("40.01")), Decimal("17.00"))
def create(app): with app.app_context(): db.create_all() print 'tables created' db.session.add(Carrier('at&t', 'txt.att.net')) db.session.add(Carrier('Verizon', 'vtext.com')) db.session.add(Carrier('T-Mobile', 'tmomail.net')) db.session.add(Carrier('Sprint', 'messaging.sprintpcs.com')) db.session.add(Carrier('US Cellular', 'email.uscc.net')) db.session.add(Carrier('Metro PCS', 'mymetropcs.com')) print 'default carriers added' db.session.commit()
class ProductShippingPricingTest(TestCase): fixtures = ['products.yaml'] def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() self.product = Product.objects.get(slug='dj-rocks') t = ProductShippingPrice( carrier=self.carrier, product=self.product, price=Decimal("10.00"), ) t.save() def testBase(self): self.assertEqual(self.carrier.price(self.product), Decimal("10.00")) def test2Prices(self): c2 = Carrier(name="test2", active=True) c2.save() t = ProductShippingPrice( carrier=c2, product=self.product, price=Decimal("20.00"), ) t.save() self.assertEqual(self.carrier.price(self.product), Decimal("10.00")) self.assertEqual(c2.price(self.product), Decimal("20.00")) def testVariantPrices(self): """price for shipping a variant is the same as the master, except when it is explicitly set""" variant = Product.objects.get(slug='dj-rocks-s-b') self.assertEqual(self.carrier.price(variant), Decimal("10.00")) t = ProductShippingPrice( carrier=self.carrier, product=variant, price=Decimal("20.00"), ) t.save() self.assertEqual(self.carrier.price(variant), Decimal("20.00"))
class ProductShippingPricingTest(TestCase): fixtures = ['products.yaml'] def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() self.product = Product.objects.get(slug='dj-rocks') t = ProductShippingPrice(carrier=self.carrier, product=self.product, price=Decimal("10.00"), ) t.save() def testBase(self): self.assertEqual(self.carrier.price(self.product), Decimal("10.00")) def test2Prices(self): c2 = Carrier(name="test2", active=True) c2.save() t = ProductShippingPrice(carrier=c2, product=self.product, price=Decimal("20.00"), ) t.save() self.assertEqual(self.carrier.price(self.product), Decimal("10.00")) self.assertEqual(c2.price(self.product), Decimal("20.00")) def testVariantPrices(self): """price for shipping a variant is the same as the master, except when it is explicitly set""" variant = Product.objects.get(slug='dj-rocks-s-b') self.assertEqual(self.carrier.price(variant), Decimal("10.00")) t = ProductShippingPrice(carrier=self.carrier, product=variant, price=Decimal("20.00"), ) t.save() self.assertEqual(self.carrier.price(variant), Decimal("20.00"))
def _create_carrier(self, carrier_id: str, name: str) -> 'Carrier': """Создает экземпляр Carrier.""" carrier = Carrier(carrier_id=carrier_id, name=name) self._carriers[carrier_id] = carrier return carrier
def setUp(self): self.carrier = Carrier(name="pricing", active=True) self.carrier.save() base_prices = ((1, 10, 0), (20, 20, 1), (30, 30, 2), (40, 40, 1)) make_tiers(self.carrier, base_prices)