Beispiel #1
0
    def test_price(self):
        customer = factory.create_customer(self.app)
        customer.individual_income = 20000
        gprice = price(customer, self.vendor, MAX_PRICE)
        self.assertEqual(gprice, 85)

        customer = factory.create_customer(self.app)
        customer.individual_income = 30000
        gprice = price(customer, self.vendor, MAX_PRICE)
        self.assertEqual(gprice, 90)
 def test_customer(self):
     customer = factory.create_customer(self.app)
     transaction = Transaction(customer=customer)
     self.db.session.add(transaction)
     self.db.session.commit()
     self.assertEqual(transaction.customer, customer)
     self.assertEqual(customer.transactions, [transaction])
 def test_price(self):
     customer = factory.create_customer(self.app)
     product1 = Product(sku='A')
     product2 = Product(sku='B')
     transaction = Transaction(customer=customer)
     transaction.add_product(product1, 2, 20)
     transaction.add_product(product2, 3, 20)
     self.assertEqual(transaction.total, 5)
    def test_status(self):
        customer = factory.create_customer(self.app)

        for status in Transaction.Status:
            transaction = Transaction(customer=customer, status=status)
            self.db.session.add(transaction)
            self.db.session.commit()

        transaction = Transaction.query.all()
        self.assertEqual(transaction[0].status.name, 'OPEN')
        self.assertEqual(transaction[1].status.name, 'SUCCESS')
        self.assertEqual(transaction[2].status.name, 'FAILURE')
 def test_add_products(self):
     customer = factory.create_customer(self.app)
     transaction = Transaction(customer=customer)
     product1 = Product(sku='A')
     product2 = Product(sku='B')
     transaction.add_product(product1, 10, 20)
     transaction.add_product(product2, 10, 20)
     self.db.session.add(transaction)
     self.db.session.commit()
     self.assertEqual(transaction.products, [product1, product2])
     self.assertEqual(product1.transactions, [transaction])
     self.assertEqual(product2.transactions, [transaction])
Beispiel #6
0
 def setUp(self):
     self.customer = factory.create_customer(self.app)
     self.user = self.customer.user
     self.vendor = Vendor(slug='test_vendor',
                          redirect_url='https://google.com')
     self.transaction = Transaction(customer=self.customer,
                                    status=Transaction.Status.OPEN)
     product1 = Product(sku='A', vendor=self.vendor)
     product2 = Product(sku='B', vendor=self.vendor)
     self.transaction.add_product(product1, 50, 100)
     self.transaction.add_product(product2, 80, 200)
     self.db.session.add(self.transaction)
     self.db.session.add(self.vendor)
     self.db.session.commit()
Beispiel #7
0
    def test_payment_not_owner(self):
        diff_customer = factory.create_customer(self.app)
        diff_user = diff_customer.user
        self.client.post('/login',
                         data={
                             'email': diff_user.email,
                             'password': diff_user.password
                         },
                         follow_redirects=True)

        data = {'txid': str(self.transaction.uuid), 'token': 'tok_visa'}
        resp = self.client.post('/checkout/pay', data=data)
        self.assertEqual(resp.status_code, 401)
        self.assertEqual(self.transaction.status, Transaction.Status.OPEN)
    def test_multiple_transactions_per_product(self):
        customer = factory.create_customer(self.app)
        product1 = Product(sku='A')
        product2 = Product(sku='B')

        for _ in range(2):
            transaction = Transaction(customer=customer)
            transaction.add_product(product1, 10, 20)
            transaction.add_product(product2, 10, 20)
            self.db.session.add(transaction)
            self.db.session.commit()

        transactions = Transaction.query.all()
        self.assertEqual(product1.transactions, transactions)
        self.assertEqual(product2.transactions, transactions)
Beispiel #9
0
    username_prefix = args.username
    password = args.password

    # override username_prefix with a random string (if -r flag is used)
    if args.randomize_username:
        username_prefix = ''.join(
            random.sample('abcdefghijklmnopqrstuvwxyz', 10))
        print(username_prefix)

    app = create_app()
    with app.app_context():

        # create customer account
        email = username_prefix + '*****@*****.**'
        customer = factory.create_customer(app, email=email, password=password)
        print('created customer: {}/{}'.format(email, password))

        # create vendor account
        email = username_prefix + '*****@*****.**'
        vendor = factory.create_vendor(app, email=email, password=password)
        print('created vendor: {}/{}'.format(email, password))

        products = [
            factory.create_product(app, vendor, sku=str(i)) for i in range(5)
        ]

        transaction = factory.create_transaction(app, customer)

        for p in products:
            transaction.add_product(p, 20, 10)