Exemplo n.º 1
0
    def test_add_get_policy(self):
        status = ShoppingPolicyLogic.add_shopping_policy_on_shop('ShaharBenS2', 'eBay', "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_shop('ShaharBenS2', 'eBay', "", "UT", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_identity('Ultimate_ShaharShahar', "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_identity('Ultimate_ShaharShahar', "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_category('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_category('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_items('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        status = ShoppingPolicyLogic.add_shopping_policy_on_items('Ultimate_ShaharShahar', "", "", "N", 0)
        self.assertTrue(StoB(status))

        IP = ShoppingPolicyLogic.get_all_shopping_policy_on_identity()
        CP = ShoppingPolicyLogic.get_all_shopping_policy_on_category()
        ITP = ShoppingPolicyLogic.get_all_shopping_policy_on_items()
        SP = ShoppingPolicyLogic.get_all_shopping_policy_on_shop('eBay')
        self.assertEqual(len(IP), 2)
        self.assertEqual(len(CP), 2)
        self.assertEqual(len(ITP), 2)
        self.assertEqual(len(SP), 2)
Exemplo n.º 2
0
def check_category_shopping_policies(username, cart_items):
    category_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_category(
    )
    for category_policy in category_policies:
        if username is not "guest":
            if is_meet_conditions(username,
                                  category_policy.conditions) is False:
                continue
        if category_policy.restriction is 'N':
            continue
        num_of_items = 0
        cart_item_category = None
        for cart_item in cart_items:
            cart_item_category = ItemsLogic.get_item(
                cart_item.item_id).category
            if category_policy.category == cart_item_category:
                num_of_items = num_of_items + cart_item.item_quantity
        if category_policy.restriction is 'AL':
            if num_of_items < category_policy.quantity:
                return "FAILED: Not enough " + cart_item_category + " items in cart; You allowed at least " + category_policy.quantity
        elif category_policy.restriction is 'E':
            if num_of_items != category_policy.quantity:
                return "FAILED: Not exact num of " + cart_item_category + " items in cart; You allowed exactly " + category_policy.quantity
        elif category_policy.restriction is 'UT':
            if num_of_items > category_policy.quantity:
                return "FAILED: Too much " + cart_item_category + " items in cart; You allowed at most " + category_policy.quantity
    return True
Exemplo n.º 3
0
def getCategoryShoppingPolicyConditions(request):
    if request.method == 'GET':
        policy_id = request.GET.get('policy_id')
        category_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_category()
        for CP in category_policies:
            if CP.policy_id == int(policy_id):
                if CP.conditions == "1=1":
                    return HttpResponse("")
                return HttpResponse(CP.conditions.replace("'", "''"))
        return HttpResponse("FAILED: Can't find that policy")
Exemplo n.º 4
0
    def test_update_policy(self):
        status = True
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_shop('ShaharBenS2', 'eBay', "", "N", 0))
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_identity('Ultimate_ShaharShahar', "", "N", 0))
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_category('Ultimate_ShaharShahar', "", "", "N", 0))
        status &= StoB(ShoppingPolicyLogic.add_shopping_policy_on_items('Ultimate_ShaharShahar', "", "", "N", 0))

        status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_shop('ShaharBenS2', 1, "restriction", "N", 'eBay'))
        status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_shop('ShaharBenS2', 1, "quantity", 10, 'eBay'))

        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_identity('Ultimate_ShaharShahar', 1, "restriction", "AL"))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_identity('Ultimate_ShaharShahar', 1, "quantity", 4))

        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_category('Ultimate_ShaharShahar', 1, "restriction", "E"))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_category('Ultimate_ShaharShahar', 1, "quantity", 3))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_category('Ultimate_ShaharShahar', 1, "category", "books"))

        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_items('Ultimate_ShaharShahar', 1, "restriction", "UT"))
        status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_items('Ultimate_ShaharShahar', 1, "quantity", 10))
        status &= StoB(
            ShoppingPolicyLogic.update_shopping_policy_on_items('Ultimate_ShaharShahar', 1, "item_name", "DP by GoF"))
        self.assertTrue(status)

        IP = ShoppingPolicyLogic.get_all_shopping_policy_on_identity()
        CP = ShoppingPolicyLogic.get_all_shopping_policy_on_category()
        ITP = ShoppingPolicyLogic.get_all_shopping_policy_on_items()
        SP = ShoppingPolicyLogic.get_all_shopping_policy_on_shop('eBay')

        self.assertEqual(IP[0].restriction, "AL")
        self.assertEqual(IP[0].quantity, 4)

        self.assertEqual(CP[0].restriction, "E")
        self.assertEqual(CP[0].quantity, 3)
        self.assertEqual(CP[0].category, "books")

        self.assertEqual(ITP[0].restriction, "UT")
        self.assertEqual(ITP[0].quantity, 10)
        self.assertEqual(ITP[0].item_name, "DP by GoF")

        self.assertEqual(SP[0].restriction, "N")
        self.assertEqual(SP[0].quantity, 10)
Exemplo n.º 5
0
def get_all_shopping_policy_on_category(request):
    if request.method == 'GET':
        return ShoppingPolicyLogic.get_all_shopping_policy_on_category()
    return HttpResponse('FAILED')
Exemplo n.º 6
0
def get_system_policies(request):
    if request.method == 'GET':
        login = request.COOKIES.get('login_hash')

        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is not None:
                if UsersLogic.is_system_manager(username):
                    item_policies_html = ""
                    item_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_items(
                    )
                    for item_policy in item_policies:
                        is_none = ""
                        selectors = {}
                        if item_policy.restriction is 'N':
                            is_none = "disabled"
                        selectors['N'] = ""
                        selectors['UT'] = ""
                        selectors['AL'] = ""
                        selectors['E'] = ""
                        selectors[
                            item_policy.restriction] = 'selected="selected"'

                        item_policies_html += loader.render_to_string(
                            'components/shopping_item_policy.html',
                            context={
                                'id': item_policy.policy_id,
                                'item_name': item_policy.item_name,
                                'selector_value': item_policy.restriction,
                                'quantity': item_policy.quantity,
                                'is_none': is_none,
                                'N_S': selectors.get('N'),
                                'UT_S': selectors.get('UT'),
                                'AL_S': selectors.get('AL'),
                                'E_S': selectors.get('E'),
                            })

                    category_policies_html = ""
                    category_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_category(
                    )
                    for category_policy in category_policies:
                        is_none = ""
                        selectors = {}
                        if category_policy.restriction is 'N':
                            is_none = "disabled"
                        selectors['N'] = ""
                        selectors['UT'] = ""
                        selectors['AL'] = ""
                        selectors['E'] = ""
                        selectors[category_policy.
                                  restriction] = 'selected="selected"'

                        category_policies_html += loader.render_to_string(
                            'components/shopping_category_policy.html',
                            context={
                                'id': category_policy.policy_id,
                                'category_name': category_policy.category,
                                'selector_value': category_policy.restriction,
                                'quantity': category_policy.quantity,
                                'is_none': is_none,
                                'N_S': selectors.get('N'),
                                'UT_S': selectors.get('UT'),
                                'AL_S': selectors.get('AL'),
                                'E_S': selectors.get('E'),
                            })

                    global_policies_html = ""
                    global_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_identity(
                    )
                    for global_policy in global_policies:
                        is_none = ""
                        selectors = {}
                        if global_policy.restriction is 'N':
                            is_none = "disabled"
                        selectors['N'] = ""
                        selectors['UT'] = ""
                        selectors['AL'] = ""
                        selectors['E'] = ""
                        selectors[
                            global_policy.restriction] = 'selected="selected"'

                        global_policies_html += loader.render_to_string(
                            'components/shopping_global_policy.html',
                            context={
                                'id': global_policy.policy_id,
                                'selector_value': global_policy.restriction,
                                'quantity': global_policy.quantity,
                                'is_none': is_none,
                                'N_S': selectors.get('N'),
                                'UT_S': selectors.get('UT'),
                                'AL_S': selectors.get('AL'),
                                'E_S': selectors.get('E'),
                            })

                    topbar = loader.render_to_string(
                        'components/TopbarLoggedIn.html',
                        context={'username': username})
                    cart_count = len(ShoppingLogic.get_cart_items(username))
                    navbar = loader.render_to_string(
                        'components/NavbarButtons.html',
                        context={'cart_items': cart_count})
                    return render(request,
                                  'system-policies.html',
                                  context={
                                      'topbar': topbar,
                                      'navbar': navbar,
                                      'item_policies': item_policies_html,
                                      'category_policies':
                                      category_policies_html,
                                      'global_policies': global_policies_html
                                  })

        return HttpResponse("You don't have the privilege to be here")