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)
def update_shopping_policy_on_items(request): if request.method == 'POST': login = request.COOKIES.get('login_hash') if login is not None: username = Consumer.loggedInUsers.get(login) if username is None: return HttpResponse('FAILED: username is None') policy_id = request.POST.get('policy_id') field_name = request.POST.get('field_name') new_value = request.POST.get('new_value') status = ShoppingPolicyLogic.update_shopping_policy_on_items(username, policy_id, field_name, new_value) if status is not True: return HttpResponse(status) return HttpResponse('SUCCESS') return HttpResponse('FAILED: you are not logged in!') return HttpResponse('FAILED: not a POST request')
def test_condition_syntax(self): ShoppingPolicyLogic.add_shopping_policy_on_shop('ShaharBenS2', 'eBay', "", "N", 0) ShoppingPolicyLogic.add_shopping_policy_on_identity('Ultimate_ShaharShahar', "", "N", 0) ShoppingPolicyLogic.add_shopping_policy_on_category('Ultimate_ShaharShahar', "", "", "N", 0) ShoppingPolicyLogic.add_shopping_policy_on_items('Ultimate_ShaharShahar', "", "", "N", 0) status = True status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_shop('ShaharBenS2', 1, 'conditions', "age > 18 AND sex = ''Male''", 'eBay')) status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_items('Ultimate_ShaharShahar', 1, 'conditions', "state = ''AFG'' AND sex = ''Male''")) status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_category('Ultimate_ShaharShahar', 1, 'conditions', "(age > 18 AND sex = ''Male'') OR (NOT state != ''ZMB'')", )) status &= StoB(ShoppingPolicyLogic.update_shopping_policy_on_identity('Ultimate_ShaharShahar', 1, 'conditions', "NOT sex != ''Female''")) self.assertTrue(status)