Exemplo n.º 1
0
    def test_make_purchase(self):
        Ecommerce.get_instance().register('ofek', 'secret', 20)
        Ecommerce.get_instance().login('ofek', 'secret')

        store_number = Ecommerce.get_instance().open_new_store(
            'mystore', 'ofek', 123456, 1, 100, 12).val[0][0]

        Ecommerce.get_instance().add_new_product('ofek', 'mystery book', 50,
                                                 17, 'reading', store_number,
                                                 ['mystery', 'leisure'], 1, 70,
                                                 13)
        Ecommerce.get_instance().add_new_product('ofek', 'mystery book2', 10,
                                                 10, 'reading', store_number,
                                                 ['mystery', 'leisure'], 1, 70,
                                                 13)

        catalog_number = (Ecommerce.get_instance().search_product(
            'Name', 'mystery book')).val[0][0]
        catalog_number2 = (Ecommerce.get_instance().search_product(
            'Name', 'mystery book2')).val[0][0]

        Ecommerce.get_instance().add_to_cart('ofek', catalog_number, None)
        Ecommerce.get_instance().add_to_cart('ofek', catalog_number2, None)

        address = DeliveryAddress(100, 'Israel', 'Beer Sheva', 'Rager',
                                  '12345')
        print(
            'is',
            str(Ecommerce.get_instance().make_purchase(
                'ofek', 'paypal', ['1234', 'ofek ash', '356', '4', '2022'],
                address, None, None).val[0]))
Exemplo n.º 2
0
 def test_make_purchase(self):
     Ecommerce.get_instance().register("client1", "123456789", 24)
     Ecommerce.get_instance().register("admin", "123456789", 24)
     self.assertTrue(Ecommerce.get_instance().make_admin("admin",24))
     store_number = Ecommerce.get_instance().open_new_store("ramiLevi", "amirdimri2", "12344", 0, 15, 14).val
     catalog_number = Ecommerce.get_instance().add_new_product("seller", 'chocholate', 10, 13, 'Food',
                                                               store_number,
                                              ['food','sweet'], 0, 100, 16).val
     Ecommerce.get_instance().add_to_cart("client", catalog_number, None)
     Ecommerce.get_instance().make_purchase("client", "paypal", "23886", DeliveryAddress(12, "israel",
                                                                                        "ashkelon",
                                                                                        "ben yehuda",
                                                                                         "78899"), 22, None)
 def test_get_transactions_by_identifier(self):
     discount_service = DiscountService()
     buying_policy = BuyingPolicyService()
     store = Store('effect', 123, 123, discount_service, buying_policy)
     cart = ShoppingCart(store)
     product_a = Product('france schnitzel', 'schnitzel', ['hot', 'krispy'],
                         35)
     store.add_new_product(product_a)
     store.inc_product_amount(product_a.catalog_number, 5)
     cart.add_product(product_a)
     delivery_address = DeliveryAddress(123, 'Israel')
     trans = (self.transaction_management.execute_transaction(
         123, cart, 'paypal',
         ['ofek', '4580160114431651', '7', '20', '458'], delivery_address,
         123)).val
     self.assertEqual(
         self.transaction_management.get_transactions_by_identifier(123),
         [trans])
     self.assertEqual(
         self.transaction_management.get_transactions_by_store(12), [])
Exemplo n.º 4
0
 def test_make_purchase(self):
     user = User('ofek', 18)
     discount_service = DiscountService()
     buying_policy = BuyingPolicyService()
     address = DeliveryAddress(13, 'Israel')
     store = Store('effect', 123, 123, discount_service, buying_policy)
     Ecommerce.get_instance().stores.append(store)
     cart = ShoppingCart(store)
     product = Product('israeli schnitzel', 'schnitzel', ['hot', 'casher'],
                       15)
     store.products.append({'product': product, 'amount': 5})
     cart.products[product.catalog_number] = {
         'product': product,
         'amount': 4
     }
     user.shopping_basket.shopping_carts.append(cart)
     all_transactions_been_made = user.make_purchase(
         'paypal', ['ofek', '4580160114431651', '7', '20', '458'], address)
     self.assertEqual(len(all_transactions_been_made), 1)
     self.assertEqual(store.products[0]['amount'], 1)
 def test_execute_transaction(self):
     discount_service = DiscountService()
     buying_policy = BuyingPolicyService()
     store = Store('effect', 123, 123, discount_service, buying_policy)
     cart = ShoppingCart(store)
     product_a = Product('france schnitzel', 'schnitzel', ['hot', 'krispy'],
                         35)
     cart.add_product(product_a)
     delivery_address = DeliveryAddress(123, 'Israel')
     store.add_new_product(product_a)
     store.inc_product_amount(product_a.catalog_number, 5)
     trans = (self.transaction_management.execute_transaction(
         123, cart, 'paypal',
         ['ofek', '4580160114431651', '7', '20', '458'], delivery_address,
         123)).val
     self.assertEqual(trans.total_price, 35)
     self.assertEqual(trans.buyer_identifier, 123)
     self.assertEqual(trans.products[product_a.catalog_number]['product'],
                      product_a)
     self.assertEqual(trans.store_number, store.store_number)
     self.assertEqual(trans.store_account, store.account_number)
     self.assertEqual(len(self.transaction_management.get_transactions()),
                      1)
     product_b = Product('israeli schnitzel', 'schnitzel',
                         ['hot', 'casher'], 15)
     store.add_new_product(product_b)
     store.inc_product_amount(product_b.catalog_number, 5)
     cart.add_product(product_b)
     trans = (self.transaction_management.execute_transaction(
         12, cart, 'paypal', ['ofek', '4580160114431651', '7', '20', '458'],
         delivery_address, 123)).val
     self.assertEqual(trans.total_price, 50)
     self.assertEqual(trans.buyer_identifier, 12)
     self.assertEqual(trans.products[product_a.catalog_number]['product'],
                      product_a)
     self.assertEqual(trans.products[product_b.catalog_number]['product'],
                      product_b)
     self.assertEqual(trans.store_number, store.store_number)
     self.assertEqual(trans.store_account, store.account_number)
     self.assertEqual(len(self.transaction_management.get_transactions()),
                      2)
Exemplo n.º 6
0
import datetime
from src.ecommerce import Ecommerce
from src.delivery_system import DeliveryAddress
# from src.db.db_functions import *

# x = Ecommerce.get_instance().open_new_store('check', 'ofek', 123, 0, 10, 0) 27
# x = Ecommerce.get_instance().add_new_product('ofek', 'banana', 10, 10, 'fruit', 27, [], 0, 10, 0)
x = Ecommerce.get_instance().add_reg_discount('ofek', 25, 32, 1, '2018-06-20',
                                              '2019-06-21')
# x = Ecommerce.get_instance().add_cond_discount('ofek', 21, 30, 1, '2018-07-25', '2028-07-25', 'or', 27)
# x = Ecommerce.get_instance().change_details_of_product('ofek', 27, 'maximum_products', 1000)
x = Ecommerce.get_instance().change_details_of_store('ofek', 9,
                                                     'maximum_products', 1000)
x = Ecommerce.get_instance().change_details_of_product('ofek', 25,
                                                       'maximum_products',
                                                       1000)
x = Ecommerce.get_instance().change_details_of_product('ofek', 25, 'Amount',
                                                       100)
x = Ecommerce.get_instance().add_to_cart('ofek', 25, None)
# x = Ecommerce.get_instance().change_details_of_product('ofek', 18, 'maximum_products', 1000)
# x = Ecommerce.get_instance().change_details_of_product('ofek', 18, 'Amount', 100)
# x = Ecommerce.get_instance().add_to_cart('ofek', 18, None)
# x = Ecommerce.get_instance().add_to_cart('ofek', 18, None)
x = Ecommerce.get_instance().make_purchase(
    'ofek', '124', ['12345676543', 'ofek', '333', '07', '12'],
    DeliveryAddress(5, 'Israel'), None, None)

# # x = get_price_db(12)
print('x:', x.val[0].__dict__)