def test_policies_torture(self): UsersLogic.register(RegisteredUser('ShaharBenS', "SsS0897SsS")) UsersLogic.update_details('ShaharBenS', 'AFG', 20, 'Male') UsersLogic.register(RegisteredUser('ShaharBenS2', "SsS0897SsS")) ShopLogic.create_shop(Shop('eBay', "Active"), 'ShaharBenS2') ShopLogic.create_shop(Shop('Amazon', "Active"), 'ShaharBenS2') item1 = Item(1, 'eBay', 'apple', 'vegas', 'good', 10, 500, 'regular', None, 0, 0, 0) item2 = Item(2, 'Amazon', 'apple', 'fruits', 'good', 10, 500, 'regular', None, 0, 0, 0) ItemsLogic.add_item_to_shop(item1, 'ShaharBenS2') ItemsLogic.add_item_to_shop(item2, 'ShaharBenS2') ShoppingPolicyLogic.add_shopping_policy_on_shop( 'ShaharBenS2', 'eBay', "age = ''20''", "AL", 3) ShoppingPolicyLogic.add_shopping_policy_on_shop( 'ShaharBenS2', 'Amazon', "age > ''15''", "UT", 5) ShoppingPolicyLogic.add_shopping_policy_on_identity( 'Ultimate_ShaharShahar', "sex = ''Male''", "AL", 9) ShoppingPolicyLogic.add_shopping_policy_on_category( 'Ultimate_ShaharShahar', "vegas", "state = ''AFG''", "UT", 5) ShoppingPolicyLogic.add_shopping_policy_on_items( 'Ultimate_ShaharShahar', "apple", "state != ''AFG''", "E", 2) access_token = hashlib.md5('ShaharBenS'.encode()).hexdigest() Consumer.loggedInUsers[access_token] = 'ShaharBenS' Consumer.loggedInUsersShoppingCart[access_token] = [] UserShoppingCartLogic.add_item_shopping_cart( access_token, ShoppingCartItem('ShaharBenS', 2, 3, None)) UserShoppingCartLogic.add_item_shopping_cart( access_token, ShoppingCartItem('ShaharBenS', 1, 7, None)) status = UserShoppingCartLogic.pay_all(access_token) self.assertFalse(StoB(status))
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)
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)
def add_shopping_policy_on_identity(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') conditions = request.POST.get('conditions') restriction = request.POST.get('restriction') quantity = request.POST.get('quantity') status = ShoppingPolicyLogic.add_shopping_policy_on_identity(username, conditions, restriction, quantity) 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_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)