コード例 #1
0
ファイル: test_checkout.py プロジェクト: rtets/katas
 def test_simple(self):
     with open('prices.txt','r') as fin:
         prices = [row[:-1] for row in fin]
     c = Checkout(Prices(prices[1:]))
     for i in 'ABBA':
         c.scan(i)
     self.assertEqual(c.total(),145)
コード例 #2
0
def checkout_instance(products):
    discounts = Discounts(settings.DISCOUNTS, settings.AVAILABLE_PRODUCTS_MAP)
    checkout = Checkout(discounts)
    for product in products:
        checkout.add_product(product)

    return checkout
コード例 #3
0
ファイル: test_checkout.py プロジェクト: rtets/katas
 def price(self,goods):
   with open('prices.txt','r') as fin:
       prices = [row[:-1] for row in fin]
   co = Checkout(Prices(prices[1:]))
   for item in goods:
       co.scan(item)
   return co.total()
コード例 #4
0
def offsite(request):
    # Create a Contact object (Optional)
    contact = Contact(
        first_name='Matti',
        last_name='Meikäläinen',
        email='*****@*****.**',
        address='Esimerkkikatu 123',
        postcode='01234',
        postoffice='Helsinki',
        country='FIN',
        phone='020123456',
        )
    # Create a Payment object
    payment = Payment(
        order_number=str(int(time.time())),
        reference_number='9999999',
        amount='200',
        delivery_date='20140606',
        message='Esimerkkimaksun kuvaus',
        currency='EUR',
        language='FI',
        content='1',
        return_url='https://www.esimerkkikauppa.fi/sv/return',
        cancel_url='https://www.esimerkkikauppa.fi/sv/cancel',
        delayed_url='https://www.esimerkkikauppa.fi/sv/delayed',
        reject_url='https://www.esimerkkikauppa.fi/sv/reject',
        contact=contact
    )
    # Create a Checkout object
    checkout = Checkout()
    # Fetch data for different payment providers for created payment
    data = checkout.get_offsite_button_data(payment)
    # Render with template
    return render(request, "offsite.html", { 'formfields': data})
コード例 #5
0
 def test_validate_payment_invalid_return(self):
     checkout = Checkout()
     assert not checkout.validate_payment_return(
         mac="2657BA96CC7879C79192547EB6C9D4082EA39CA52FE1DAD09CB1C632ECFDAE68",
         version="0001",
         order_number="1388998411",
         order_reference="474738238",
         payment="1221238575",
         status="3",
         algorithm="3"
     )
コード例 #6
0
ファイル: views.py プロジェクト: D0han/saleor
def details(request, step):
    if not request.cart:
        return redirect('cart:index')
    checkout = Checkout(request)
    if not step:
        return redirect(checkout.get_next_step())
    try:
        step = checkout[step]
    except KeyError:
        raise Http404()
    response = step.process()
    return response or redirect(checkout.get_next_step())
コード例 #7
0
ファイル: tests.py プロジェクト: epigos/saleor
 def test_address_save_without_address(self, mock_save):
     self.request.POST = NEW_ADDRESS_POST
     self.request.POST['method'] = 0
     group = MagicMock()
     group.address = None
     checkout = Checkout(self.request)
     group.get_delivery_methods.return_value = [DummyShipping(group)]
     step = ShippingStep(checkout, self.request, group)
     self.assertTrue(step.forms_are_valid(), 'Forms don\'t validate.')
     step.save()
     self.assertEqual(mock_save.call_count, 0)
     grup_storage = checkout.get_group(str(step))
     self.assertEqual(type(grup_storage['address']), Address,
                      'Address instance expected')
コード例 #8
0
def returnpayment(request):
    # Create a Checkout object
    checkout = Checkout()
    params = request.GET
    if not checkout.validate_payment_return(params['MAC'], params['VERSION'], params['STAMP'], params['REFERENCE'], params['PAYMENT'], params['STATUS'], params['ALGORITHM']):
        return HttpResponse("MAC check failed")
    else:
        if params['STATUS'] in ["2", "5", "6", "8", "9", "10"]:
            return HttpResponse("Payment complete, status code: " + params['STATUS'])
        elif params['STATUS'] == "3":
            return HttpResponse("Payer chose delayed payment, status code: " + params['STATUS'])
        elif params['STATUS'] == "-1":
            return HttpResponse("Payment cancelled, status code: " + params['STATUS'])
        elif params['STATUS'] == "7":
            return HttpResponse("Manual activation requeired, status code: " + params['STATUS'])
        else:
            return HttpResponse("Unknown status code: " + params['STATUS'])
コード例 #9
0
 def test_other_discount_disqualifies(self):
     threshold_discount = ThresholdDiscount(40, 10)
     checkout = Checkout((STUB_ITEM_PERCENT_DISCOUNT, ), threshold_discount)
     discounted_item_id = STUB_ITEM_PERCENT_DISCOUNT.id
     eq_(36, checkout.total((discounted_item_id, discounted_item_id)))
コード例 #10
0
class TestCheckout(unittest.TestCase):
    def setUp(self):
        super().setUp()
        self.checkout = Checkout(pricing_rules=[BogofRule, BulkDiscount])

    def test_without_discount(self):
        self.checkout.scan('FR1')
        self.assertEqual(self.checkout.total(), 3.11)

    def test_buy_one_get_one_free_fruit_tea(self):
        self.checkout.scan('FR1')
        self.checkout.scan('FR1')
        self.assertEqual(self.checkout.total(), 3.11)

    def test_buy_one_get_one_free_discount(self):
        self.checkout.scan('FR1')
        self.checkout.scan('SR1')
        self.checkout.scan('FR1')
        self.checkout.scan('FR1')
        self.checkout.scan('CF1')

        self.assertEqual(self.checkout.total(), 22.45)

    def test_bulk_discount(self):
        self.checkout.scan('SR1')
        self.checkout.scan('SR1')
        self.checkout.scan('FR1')
        self.checkout.scan('SR1')

        self.assertEqual(self.checkout.total(), 16.61)
コード例 #11
0
 def test_single_item(self):
     checkout = Checkout()
     checkout.scan("A")
     print(checkout.receipt_text())
     self.assertIn("A: 50\nTotal: 50", checkout.receipt_text())
コード例 #12
0
 def __init__(self):
     self.checkout = Checkout(self.rules)
コード例 #13
0
ファイル: test.py プロジェクト: Mause/PerthCodeDojo
class TestCheckout(unittest.TestCase):
    def setUp(self):
        self.register = Checkout()

    def assertTotal(self, price):
        self.assertEqual(self.register.calculate_total(), price)

    def test_empty_cart(self):
        self.assertTotal(0)

    def test_basic_checkout(self):
        self.register.add_to_cart(Apple(1))
        self.assertTotal(.5)

    def test_third_free_checkout(self):
        self.register.add_to_cart(Apple(5))
        self.assertTotal(4 * 0.5)

    def test_seven_apples(self):
        self.register.add_to_cart(Apple(7))
        self.assertTotal(2.5)

    def test_multiple_fruit(self):
        self.register.add_multiple([
            Apple(2),
            Mango(4),
            Cherry(10)
        ])
        self.assertTotal(
            50 - (7.5 * 3) +  # cherries
            12 +  # mangoes 3 * 4
            1     # apples 2 * 0.5
        )

    def test_cheaper_cherries(self):
        self.register.add_to_cart(Cherry(3))
        self.assertTotal(15 - 7.5)

    def test_cheaper_cherries_assumption(self):
        self.register.add_to_cart(Cherry(6))
        self.assertTotal(15)

    def test_very_basic(self):
        self.register.add_multiple([
            Apple(2),
            Cherry(3)
        ])
        self.assertTotal(7.5 + 1)

    # def test_split_apples(self):
    #     self.register.add_multiple([
    #         Apple(2),
    #         Apple(1)
    #     ])
    #     self.assertTotal(2 * .5)

    def test_discounted_cherry(self):
        self.register.add_to_cart(RottenCherry(5))
        self.assertTotal(25 * .8)

    def test_total_discount(self):
        self.register.add_multiple([
            Cherry(2),
            Apple(6),
            Mango(1)
        ])
        self.register.apply_discount(.2)

        self.assertTotal(3)
コード例 #14
0
class TestCheckout(unittest.TestCase):
    '''
    Unit tests for checkout module
    '''
    def init_pricingrules(self):
        '''
        This function initialises PricingRules, Checkout objects from real files
        TODO: turn it into decorator.
        '''

        self.pricing_rules = PricingRules(
            '/code/tests/config/catalog.yaml',
            '/code/tests/config/pricingrules.yaml')
        self.checkout = Checkout(self.pricing_rules)

    def teardown_pricingrules_and_catalog(self):
        '''
        Tear down Checkout object.

        Execute this after each unit test.

        TODO: turn it into decorator.
        '''
        self.checkout = None

    def test_constructor(self):
        '''
        Testing constructor
        '''

        self.init_pricingrules()

        # Make sure selected_items is an empty dict
        self.assertEqual(self.checkout.selected_items, {})
        # Make sure we have set zero total_sum
        self.assertEqual(self.checkout.total_sum, 0)
        # Make sure that pricing_rules is set to the mocked PricingRules object
        self.assertEqual(True,
                         isinstance(self.checkout.pricing_rules, PricingRules))

        self.teardown_pricingrules_and_catalog()

    def test_scan_throws_exception(self):
        '''
        Test that scan() throws exception if someone scans SKU which is not in catalog
        '''

        self.init_pricingrules()

        with self.assertRaises(Exception):
            self.checkout.scan('no-such-SKU')

        self.teardown_pricingrules_and_catalog()

    def test_scan_quantity_increments(self):
        '''
        Make sure that quantity is set to 1 if Apple TV SKU is scanned first time.
        Make sure that quantity is incremented if Apple TV SKU is scanned second time.
        '''
        self.init_pricingrules()

        # First scan
        self.checkout.scan('atv')
        self.assertEqual(1, self.checkout.selected_items['atv']['quantity'])

        # Second scan
        self.checkout.scan('atv')
        self.assertEqual(2, self.checkout.selected_items['atv']['quantity'])

        self.teardown_pricingrules_and_catalog()

    def test_total_no_discount(self):
        '''
        SKUs Scanned: atv, atv, atv, vga Total expected: 358.5 (no discounts)
        '''

        self.init_pricingrules()

        for sku in ['atv', 'atv', 'atv', 'vga']:
            self.checkout.scan(sku)

        actual = self.checkout.total()
        expected = float(249.00)
        # expected = float(358.5)

        self.assertEqual(actual, expected)

        self.teardown_pricingrules_and_catalog()
コード例 #15
0
def checkout_total(goods):
    checkout = Checkout(RULES)
    for item in goods:
        checkout.scan(item)
    return checkout.total()
コード例 #16
0
 def test_works_on_empty(self):
     """**Scenario** Works for an empty cart"""
     checkout = Checkout()
     total = checkout.total()
     self.assertEqual(total, 0)
コード例 #17
0
 def test_scan_works(self):
     """**Scenario** User scans a product"""
     checkout = Checkout()
     product = checkout.scan('vga')
     self.assertIsNotNone(product)
     self.assertEqual(len(checkout.items), 1)
コード例 #18
0
 def test_scan_raises_exception_for_not_in_catalog(self):
     """**Scenario** User scans a sku which doesn't exist in the catalog"""
     checkout = Checkout()
     product = checkout.scan('vga')
     self.assertIsNotNone(product)
     self.assertEqual(len(checkout.items), 1)
コード例 #19
0
 def test_raises_error_on_exception(self):
     """**Scenario** User scans product which doesn't exist in the system"""
     checkout = Checkout()
     with self.assertRaises(ProductDoesntExist):
         checkout.scan('long-sku')
コード例 #20
0
 def create_checkout(self, sku_list):
     """Helper method to create a checkout populated with skus"""
     checkout = Checkout(self.price_rules)
     for sku in sku_list:
         checkout.scan(sku)
     return checkout
コード例 #21
0
def checkout():
    checkout = Checkout()
    checkout.addItemPrice('a', 1)
    checkout.addItemPrice('b', 2)

    return checkout
コード例 #22
0
ファイル: test.py プロジェクト: Mause/PerthCodeDojo
 def setUp(self):
     self.register = Checkout()
コード例 #23
0
 def checkout(self) -> Checkout:
     checkout = Checkout()
     checkout.addItemPrice("a", 1)
     checkout.addItemPrice("b", 2)
     yield checkout
コード例 #24
0
ファイル: test_checkout.py プロジェクト: Isaac-Edwards/PyTest
def checkout():
    checkout = Checkout()
    checkout.add_item_price("banana", 0.20)
    checkout.add_item_price("milk", 1)
    checkout.add_item_price("TV", 999)
    return checkout
コード例 #25
0
def checkout():
    c1 = Checkout()
    return c1
コード例 #26
0
def checkout():
    checkout = Checkout()
    checkout.addItemPrice("Apple", 1.25)
    checkout.addItemPrice("Carrot", 2.25)
    checkout.addItemPrice("Figs", 3.50)
    return checkout
コード例 #27
0
from checkout import Checkout
import json

# DISCOUNT_TYPES:
#                1. Buy N, get an item free ("buyN")
#                2. Group Discount ("groupD")

# * We're going to have a 3 for 2 deal on Apple TVs. For example, if you buy 3 Apple TVs, you will pay the price of 2 only
# * The brand new Super iPad will have a bulk discount applied, where the price will drop to $499.99 each, if someone buys more than 4
# * We will bundle in a free VGA adapter free of charge with every MacBook Pro sold

if __name__ == '__main__':
    pricingRules = json.load(open("pricingRules.json"))
    co = Checkout(pricingRules)
    co.scan("mbp")
    co.scan("vga")
    co.scan("ipd")
    co.total()
コード例 #28
0
def checkout():

    checkout = Checkout()
    checkout.add_item_price('a', 1)
    checkout.add_item_price('b', 2)
    return checkout
コード例 #29
0
    def test_incremental(self):
        checkout = Checkout(RULES)

        def assert_total(expected):
            self.assertEqual(expected, checkout.total())

        assert_total(0)
        checkout.scan('A')
        assert_total(50)
        checkout.scan('B')
        assert_total(80)
        checkout.scan('A')
        assert_total(130)
        checkout.scan('A')
        assert_total(160)
        checkout.scan('B')
        assert_total(175)
コード例 #30
0
 def setUp(self):
     super().setUp()
     self.checkout = Checkout(pricing_rules=[BogofRule, BulkDiscount])
コード例 #31
0
 def clear_checkout(self):
     self.checkout = Checkout(self.rules)
コード例 #32
0
##conn = sqlite3.connect('C:/Users/Henrik/test.db')
##c=conn.cursor()

if __name__ == '__main__':

    config = {
        '/': {
            'tools.encode.debug': True,
            'tools.encode.text_only': False,
            'tools.encode.encoding': 'utf8'
        },
    }

    cherrypy.tree.mount(
        Checkout(), '/api/checkout',
        {'/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher()
        }})

    cherrypy.tree.mount(
        Book(), '/api/book',
        {'/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher()
        }})

    cherrypy.tree.mount(
        Index(), '/api',
        {'/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher()
        }})
コード例 #33
0
 def price(self, goods):
     co = Checkout(RULES)
     for item in list(goods):
         co.scan(item)
     return co.total
コード例 #34
0
 def test_simple_total(self):
     checkout = Checkout((STUB_ITEM_NO_DISCOUNT, ))
     eq_(
         20,
         checkout.total(
             (STUB_ITEM_NO_DISCOUNT.id, STUB_ITEM_NO_DISCOUNT.id)))
コード例 #35
0
class TestPricingRules(unittest.TestCase):
    '''
    Unit tests for checkout module
    '''
    def init_pricingrules(self):
        '''
        This function initialises PricingRules, Checkout objects from real files
        TODO: turn it into decorator.
        '''

        self.pricing_rules = PricingRules(
            '/code/tests/config/catalog.yaml',
            '/code/tests/config/pricingrules.yaml')
        self.checkout = Checkout(self.pricing_rules)

    def teardown_pricingrules_and_catalog(self):
        '''
        Tear down Checkout object.
        Execute this after each unit test.
        TODO: turn it into decorator.
        '''
        self.checkout = None

    def test_discount_every_third_apple_tv_bought_3(self):
        '''
        Testing pricing rule discount_every_third when buying 3 Apple TVs and one VGA.
        SKUs Scanned: atv, atv, atv, vga
        Total expected: $249.00
        '''

        self.init_pricingrules()

        for sku in ['atv', 'atv', 'atv', 'vga']:
            self.checkout.scan(sku)

        #
        self.assertEqual(249.00, self.checkout.total())

        self.teardown_pricingrules_and_catalog()

    def test_discount_every_third_apple_tv_bought_4(self):
        '''
        Testing pricing rule discount_every_third when buying 4 Apple TVs and one VGA.
        Make sure that discount_every_third pricing rule works fine on Apple TV.
        SKUs Scanned: atv, atv, atv, atv, vga
        Total expected: 109.50 * 4 - 109.50 + 30.00 = $358.5
        '''

        self.init_pricingrules()

        for sku in ['atv', 'atv', 'atv', 'atv', 'vga']:
            self.checkout.scan(sku)

        #
        self.assertEqual(109.50 * 4 - 109.50 + 30.00, self.checkout.total())

        self.teardown_pricingrules_and_catalog()

    def test_discount_every_third_apple_tv_bought_5(self):
        '''
        Testing pricing rule discount_every_third when buying 5 Apple TVs and one VGA.
        Make sure that discount_every_third pricing rule works fine on Apple TV.
        SKUs Scanned: atv, atv, atv, atv, atv, vga
        Total expected: 109.50 * 5 - 109.50 + 30.00 = $468.0
        '''

        self.init_pricingrules()

        for sku in ['atv', 'atv', 'atv', 'atv', 'atv', 'vga']:
            self.checkout.scan(sku)

        #
        self.assertEqual(109.50 * 5 - 109.50 + 30.00, self.checkout.total())

        self.teardown_pricingrules_and_catalog()

    def test_discount_every_third_apple_tv_bought_7(self):
        '''
        Testing pricing rule discount_every_third when buying 5 Apple TVs and one VGA.
        Make sure that discount_every_third pricing rule works fine on Apple TV.
        SKUs Scanned: atv, atv, atv, atv, atv, atv, atv, vga
        Total expected: 109.50 * 7 - 109.50 * 2 + 30.00 = $687.0
        '''

        self.init_pricingrules()

        for sku in ['atv', 'atv', 'atv', 'atv', 'atv', 'atv', 'atv', 'vga']:
            self.checkout.scan(sku)

        self.assertEqual(109.50 * 7 - 109.50 * 2 + 30.00,
                         self.checkout.total())

        self.teardown_pricingrules_and_catalog()
コード例 #36
0
 def test_empty(self):
     checkout = Checkout((STUB_ITEM_NO_DISCOUNT, ))
     eq_(0, checkout.total([]))
コード例 #37
0
ファイル: main.py プロジェクト: patialashahi31/Assignment3
    n = int(input())
    a = [1, 2]
    while (n in a):
        if (n == 1):
            payment()
            break
        elif (n == 2):
            menu()
            break
        else:
            print("Please enter valid number")
            n = int(input())


check = Checkout()


def payment():
    transactionId = 0
    print("Enter credit card details: ")
    print("Enter name(As on credit card) : ")
    name = input()
    check.setName(name)
    print("Enter credit card number")
    card_number = int(input())
    if (check.isValid(card_number)):
        print("Enter expiry month")
        month = int(input())
        print("Enter expiry year")
        year = int(input())
コード例 #38
0
 def test_percentage_discount_not_qualifed(self):
     checkout = Checkout((STUB_ITEM_PERCENT_DISCOUNT, ))
     eq_(20, checkout.total((STUB_ITEM_PERCENT_DISCOUNT.id, )))
コード例 #39
0
ファイル: test_checkout.py プロジェクト: rtets/katas
 def test_incremental(self):
   with open('prices.txt','r') as fin:
       prices = [row[:-1] for row in fin]
   co = Checkout(Prices(prices[1:]))
   self.assertEqual(  0, co.total())
   co.scan("A")
   self.assertEqual( 50, co.total())
   co.scan("B")
   self.assertEqual( 80, co.total())
   co.scan("A")
   self.assertEqual(130, co.total())
   co.scan("A")
   self.assertEqual(160, co.total())
   co.scan("B")
   self.assertEqual(175, co.total())
コード例 #40
0
 def test_threshold_save_at_threshold(self):
     threshold_discount = ThresholdDiscount(10, 10)
     checkout = Checkout((STUB_ITEM_NO_DISCOUNT, ), threshold_discount)
     eq_(9, checkout.total((STUB_ITEM_NO_DISCOUNT.id, )))
コード例 #41
0
 def test_percentage_discount_qualified(self):
     checkout = Checkout((STUB_ITEM_PERCENT_DISCOUNT, ))
     discounted_item_id = STUB_ITEM_PERCENT_DISCOUNT.id
     eq_(36, checkout.total((discounted_item_id, discounted_item_id)))
コード例 #42
0
def test_offers(self):
    checkout = Checkout()
    checkout.scan("A")
    checkout.scan("A")
    checkout.scan("B")
    checkout.scan("A")
    checkout.scan("C")
    checkout.scan("D")
    checkout.scan("B")
    self.assertEqual(checkout.total, 2)
    self.assertEqual(
        checkout.receipt_text(),
        "A: 50\nA: 50\nB: 30\nA: 50 - 20 (3 for 130)\nC: 20\nD: 15\nB: 30 - 15 (2 for 45)\nTotal: 210"
    )