コード例 #1
0
    def test_view_personal_purchase_history(self):
        # Empty purchases
        self.assertListEqual(
            [],
            self.__subscriber.view_personal_purchase_history()['response'])

        (TradeControl.get_instance()
         ).get_curr_user().get_purchase_history().append(
             Purchase([{
                 "product_name": "eytan",
                 "product_price": 12,
                 "amount": 1
             }], 12, self.__store.get_name(), self.__user.get_nickname()))

        # Not empty
        self.assertEqual(
            1,
            len(self.__subscriber.view_personal_purchase_history()
                ['response']))
        purchases_lst = [
            jsonpickle.decode(e).get_products() for e in
            self.__subscriber.view_personal_purchase_history()['response']
        ]
        self.assertListEqual([{
            "product_name": "eytan",
            "product_price": 12,
            "amount": 1
        }], purchases_lst[0])

        (TradeControl.get_instance()).get_managers().remove(self.__user)
コード例 #2
0
    def test_new_init_system(self):

        # TODO: For v3
        # result = TradeControlService.init_system()
        # print(result['msg'])
        # self.assertTrue(result['response'])
        # self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("u1"))
        # self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("u2"))
        # self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("u3"))
        # self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("u4"))
        # self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("u5"))
        # self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("u6"))
        # self.assertEqual(len((TradeControl.get_instance()).get_managers()), 1)
        # self.assertIn((TradeControl.get_instance()).get_subscriber("u1"), (TradeControl.get_instance()).get_managers())
        # self.assertIsNotNone((TradeControl.get_instance()).get_store("s1"))
        # self.assertIsNotNone((TradeControl.get_instance()).get_store("s1").get_inventory().get_product("diapers"))
        # self.assertIn((TradeControl.get_instance()).get_subscriber("u3"),
        #               (TradeControl.get_instance()).get_store("s1").get_managers())
        # self.assertIn((TradeControl.get_instance()).get_subscriber("u5"),
        #               (TradeControl.get_instance()).get_store("s1").get_managers())
        # self.assertIn((TradeControl.get_instance()).get_subscriber("u6"),
        #               (TradeControl.get_instance()).get_store("s1").get_managers())

        # TODO: For v4
        self.assertTrue(TradeControlService.init_system()['response'])
        self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("A1"))
        self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("U1"))
        self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("U2"))
        self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("U11"))
        self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("U12"))
        self.assertIsNotNone((TradeControl.get_instance()).get_subscriber("U13"))
        self.assertIn((TradeControl.get_instance()).get_subscriber("A1"), (TradeControl.get_instance()).get_managers())
        self.assertIsNotNone((TradeControl.get_instance()).get_store("S2"))
コード例 #3
0
 def confirm_payment(delivery_details: {'name': str, 'address': str, 'city': str, 'country': str, 'zip': str},
                     payment_details: {'card_number': str, 'month': str, 'year': str, 'holder': str,
                                       'ccv': str, 'id': str},
                     purchase_ls: []) \
         -> {'response': bool, 'msg': str}:
     """
         purchase confirmation and addition to user & store purchases
     :param payment_details: dict of payment details
     :param delivery_details: dict of delivery details
     :param purchase_ls: dict
             [{"store_name": str, "basket_price": float, "products": [{"product_name", "product_price", "amount"}]}]
     :return: dict = {'response': bool, 'msg': str}
              response = true if successful, otherwise false
     """
     pay_success = PaymentProxy.get_instance().commit_payment(
         payment_details)
     if pay_success['response']:
         # pay_success['msg'] = transaction_id for payment
         deliver_success = DeliveryProxy.get_instance().deliver_products(
             delivery_details)
         if not deliver_success['response']:
             PaymentProxy.get_instance().cancel_pay(pay_success['tid'])
             return {
                 'response': False,
                 'msg': deliver_success['msg'] + " Payment was canceled."
             }
         else:
             return TradeControl.get_instance().accept_purchases(
                 purchase_ls)
     return pay_success
コード例 #4
0
    def define_discount_policy(store_name: str,
                               percentage: float,
                               valid_until: datetime,
                               discount_details: {'name': str,
                                                  'product': str},
                               discount_precondition: {'product': str,
                                                       'min_amount': int or None,
                                                       'min_basket_price': str or None} or None = None
                               ) \
            -> {'response': bool, 'msg': str}:
        """
        Define SIMPLE discount policy, either visible or conditional.
        The key word "all" will flag that the policy or constraint are on the entire basket.

        :param valid_until: the last date the policy is valid.
        :param store_name.
        :param percentage: the percentage of the discount.
        :param discount_details:  the name and the product of the policy.
        :param discount_precondition: ONLY AVAILABLE FOR CONDITIONAL POLICY.
                        have a constraint either on the entire basket, or a specific product.
        :return: True if successful, else false.
        """
        return TradeControl.get_instance().define_discount_policy(
            store_name, percentage, valid_until, discount_details,
            discount_precondition)
コード例 #5
0
 def view_personal_purchase_history() -> {'response': list, 'msg': str}:
     """
     View the subscriber's purchase history
     :return: list of json objects containing the subscriber's purchase history or None if none exist
     """
     loggerStaticMethod("SubscriberRole.view_personal_purchase_history", [])
     return TradeControl.get_instance().view_personal_purchase_history()
コード例 #6
0
    def update_discount_policy(store_name: str, policy_name: str,
                               percentage: float = -999,
                               valid_until: datetime = None,
                               discount_details: {'name': str,
                                                  'product': str} = None,
                               discount_precondition: {'product': str,
                                                       'min_amount': int or None,
                                                       'min_basket_price': str or None} or None = None) \
            -> {'response': bool, 'msg': str}:
        """
        Updating an existing policy, either visible, conditional or composite.
        The key word "all" will flag that the policy is on the entire basket.

        :param valid_until: the last date the policy is valid.
        :param store_name.
        :param policy_name: the policy to update.
        :param percentage: for updating the percentage attribute.
        :param discount_details: for updating the name or product of the policy.
        :param discount_precondition: ONLY AVAILABLE FOR CONDITIONAL POLICY.
                for updating the precondition.
                DOES NOT AVAILABLE FOR COMPOSITE AND VISIBLE POLICIES.
        :return: true if successful, else false.
        """
        return TradeControl.get_instance().update_discount_policy(
            store_name, policy_name, percentage, valid_until, discount_details,
            discount_precondition)
コード例 #7
0
 def get_appointment_status(appointee_nickname: str, store_name: str):
     """
     :param appointee_nickname: nickname of the new owner that is being appointed
     :param store_name: store the owner should be added to
     :return: AppointmentStatus - DECLINED = 1,APPROVED = 2, PENDING = 3
     """
     return TradeControl.get_instance().get_appointment_status(
         appointee_nickname, store_name)
コード例 #8
0
 def setUp(self):
     if not ("testing" in rel_path):
         raise ReferenceError("The Data Base is not the testing data base.\n"
                              "\t\t\t\tPlease go to src.main.DataAccessLayer.ConnectionProxy.RealDb.rel_path\n"
                              "\t\t\t\t and change rel_path to test_rel_path.\n"
                              "\t\t\t\tThanks :D")
     self.__subscriber: SubscriberRole = SubscriberRole()
     self.__trade_control_mock: TradeControl = TradeControl.get_instance()
コード例 #9
0
 def logout() -> {'response': bool, 'msg': str}:
     """
     logs the subscriber out of the system
     :return: dict = {'response': bool, 'msg': str}
              response = True if succeeded, otherwise False
     """
     loggerStaticMethod("SubscriberRole.logout", [])
     return TradeControl.get_instance().logout_subscriber()
コード例 #10
0
 def remove_products(store_name: str, products_names: list) -> bool:
     """
     :param store_name: store's name
     :param products_names: list of products name to remove
     :return: True if all products were removed, else return False
     """
     return TradeControl.get_instance().remove_products(
         store_name, products_names)
コード例 #11
0
 def remove_manager(store_name: str, appointee_nickname: str) -> bool:
     """
     :param store_name: store's name
     :param appointee_nickname: manager's nickname who's will be removed
     :return: True on success, else False
     """
     return TradeControl.get_instance().remove_manager(
         store_name, appointee_nickname)
コード例 #12
0
 def save_products_to_basket(products_stores_quantity_ls: [{"product_name": str, "store_name": str,
                                                                  "amount": int}]) \
         -> {'response': bool, 'msg': str}:
     """
     :param products_stores_quantity_ls: [ {"product_name": str, "amount": int, "store_name": str}, .... ]
     :return: dict = {'response': bool, 'msg': str}
     """
     return TradeControl.get_instance().save_products_to_basket(
         products_stores_quantity_ls)
コード例 #13
0
    def test_logout(self):
        user = User()
        user_nickname = "Eytan"
        user_password = "******"
        user.register(user_nickname, user_password)

        (TradeControl.get_instance()).register_guest(user_nickname,
                                                     user_password)
        (TradeControl.get_instance()).login_subscriber(user_nickname,
                                                       user_password)

        # All valid
        self.assertTrue(self.__subscriber.logout()['response'])
        self.assertTrue(
            (TradeControl.get_instance()).get_curr_user().is_logged_out())

        # Invalid - user already logged out
        self.assertFalse(self.__subscriber.logout()['response'])
コード例 #14
0
 def open_store(store_name: str) -> {'response': bool, 'msg': str}:
     """
     Opens a new store with the given store name
     :param store_name: String
     :return: dict = {'response': bool, 'msg': str}
              response = true if the store is created, else false
     """
     loggerStaticMethod("SubscriberRole.open_store",["store_name"])
     return TradeControl.get_instance().open_store(store_name)
コード例 #15
0
 def view_shopping_cart() -> {'response': list, 'msg': str}:
     """
     :return: dict: {'response': [{"store_name": str,
                                  "basket": [{"product_name": str
                                              "amount": int}, ...]
                                 }, ...],
                     'msg': str}
     """
     return TradeControl.get_instance().view_shopping_cart()
コード例 #16
0
 def get_appointees(store_name, managers_or_owners: str) -> list:
     """
     returns for the current manager/owner all the managers he appointed
     :param store_name: name of the store
     :param managers_or_owners: "MANAGERS" or "OWNERS" to get a list of the managers or owners that appointer_nickname appointed
     :return: list of the managers nicknames
     """
     return TradeControl.get_instance().get_appointees(
         store_name, managers_or_owners)
コード例 #17
0
    def delete_purchase_policy(store_name: str, policy_name: str):
        """
        Delete purchase policy with the name @policy_name, if exist.

        :param store_name.
        :param policy_name.
        :return: True if successful, else false.
        """
        return (TradeControl.get_instance()).delete_purchase_policy(
            store_name, policy_name)
コード例 #18
0
 def edit_manager_permissions(store_name: str, appointee_nickname: str,
                              permissions: list) -> bool:
     """
     :param store_name: store's name
     :param appointee_nickname: manager's nickname who's permissions will be edited
     :param permissions: ManagerPermission[] ->list of permissions (list of Enum)
     :return: True on success, else False
     """
     return TradeControl.get_instance().edit_manager_permissions(
         store_name, appointee_nickname, permissions)
コード例 #19
0
    def get_discount_policy(store_name: str, policy_name: str) -> {}:
        """
        return the policy.

        :param store_name.
        :param policy_name.
        :return: the policy if exist. None else.
        """
        return (TradeControl.get_instance()).get_discount_policy(
            store_name, policy_name)
コード例 #20
0
    def add_system_manager(username: str, password: str):
        """
        Add new system manager(a.k.a admin)

        :param username: new admin's username
        :param password: new admin's password
        :return: True if successful, False else.
        """
        return (TradeControl.get_instance()).add_system_manager(
            username, password)
コード例 #21
0
 def update_agreement_participants(appointee_nickname: str, store_name: str,
                                   owner_response: AppointmentStatus):
     """
     :param appointee_nickname: nickname of the new owner that will be appointed
     :param store_name: store the owner will be added to
     :param owner_response: the owners response - declined/approved
     :return: dict =  {'response': bool, 'msg': str}
              response = True on success, else False
     """
     return TradeControl.get_instance().update_agreement_participants(
         appointee_nickname, store_name, owner_response)
コード例 #22
0
 def display_store_purchases(
         store_name: str) -> {
             'response': list,
             'msg': str
         }:
     """
     :param store_name: store's name
     :return: dict = {'response': list, 'msg': str}
              response = purchases list
     """
     return TradeControl.get_instance().display_store_purchases(store_name)
コード例 #23
0
    def close_store(self, store_name: str) -> bool:
        """
        This function check if the curr_user logged in and own the store with the name (:param store_name).
        If the above condition is true, the function delete the store.
        Else, return False

        :param store_name: the store name to delete. Curr_user Have to own the store.
        :return: True if deleted successfully
                 False else.
        """
        return TradeControl.get_instance().close_store(store_name)
コード例 #24
0
 def view_store_purchases_history(
         store_name: str) -> {
             'response': list,
             'msg': str
         }:
     """
     :param store_name: the store to view
     :return: list of purchases
     """
     return TradeControl.get_instance().view_store_purchases_history(
         store_name)
コード例 #25
0
 def tearDown(self):
     (DataAccessFacade.get_instance()).delete_purchases()
     # (DataAccessFacade.get_instance()).delete_discount_policies()
     (DataAccessFacade.get_instance()).delete_statistics()
     (DataAccessFacade.get_instance()).delete_store_owner_appointments()
     (DataAccessFacade.get_instance()).delete_products_in_baskets()
     (DataAccessFacade.get_instance()).delete_products()
     (DataAccessFacade.get_instance()).delete_store_manager_appointments()
     (DataAccessFacade.get_instance()).delete_stores()
     (DataAccessFacade.get_instance()).delete_users()
     (TradeControl.get_instance()).__delete__()
コード例 #26
0
 def purchase_products():
     """
         purchase all products in the guest shopping cart, according to purchase policy and discount policy
     :return: dict = {'response': dict, 'msg': str}
         response is None if purchases failed, else dict
         {"total_price": float, "baskets": [{"store_name": str, "basket_price": float, "products":
                                                                     [{"product_name", "product_price", "amount"}]
                                           }]
         }
     """
     return TradeControl.get_instance().purchase_products()
コード例 #27
0
 def view_user_purchase_history(
         viewed_user: str) -> {
             'response': list,
             'msg': str
         }:
     """
     This function returns all the purchases that are done by a specific user.
     :param viewed_user: the user to view.
     :return: list of json objects containing the users' purchases or None if none exist
     """
     return TradeControl.get_instance().view_user_purchase_history(
         viewed_user)
コード例 #28
0
    def purchase_basket(store_name: str):
        """
            single basket purchase by given store name, according to purchase policy and discount policy
        :param store_name:
        :return: None if purchase failed, else dict

            {"total_price": float, "baskets": [{"store_name": str, "basket_price": float, "products":
                                                                        [{"product_name", "product_price", "amount"}]
                                              }]
            }
        """
        return TradeControl.get_instance().purchase_basket(store_name)
コード例 #29
0
 def get_policies(
         policy_type: str, store_name: str) -> {
             'response': [dict] or None,
             'msg': str
         }:
     """
         according to the given type, displays a list of policies for the store
     :param purchase_type: can be "purchase" or "discount"
     :param store_name:
     :return: list of policies or empty list, returns None if user is not owner of the store or store doesn't exist
     """
     return TradeControl.get_instance().get_policies(
         policy_type, store_name)
コード例 #30
0
 def appoint_additional_owner(
         appointee_nickname: str, store_name: str) -> {
             'response': bool,
             'msg': str
         }:
     """
     :param appointee_nickname: nickname of the new owner that will be appointed
     :param store_name: store the owner will be added to
     :return: dict =  {'response': bool, 'msg': str}
              response = True on success, else False
     """
     return TradeControl.get_instance().appoint_additional_owner(
         appointee_nickname, store_name)