def test_get_nickname(self): guest = User() self.__user.logout() # All valid - user is registered self.assertEqual(self.__user.get_nickname(), self.__valid_name) # All valid - user isn't registered self.assertIsNone(guest.get_nickname())
def test_is_registered(self): guest = User() self.__user.logout() # All valid - user is registered self.assertTrue(self.__user.is_registered()) # All valid - user isn't registered self.assertFalse(guest.is_registered())
def test_check_nickname(self): # All valid self.assertTrue(self.__user.check_nickname(self.__valid_name)) # Invalid password doesn't exist self.assertFalse(self.__user.check_nickname("self.__valid_password")) registered = User() registered.register("Eytan", "Eytan's password") # Invalid - password exist but isn't corresponding with the username self.assertFalse(registered.check_nickname(self.__valid_name))
def setUp(self): self.store: Store = Store("myStore") self.owner = User() self.owner.register("shani", "passwordd45646") self.store.get_owners_appointments().append( StoreAppointment(None, self.owner, [])) self.manager = User() self.manager.register("dani", "passwordd45646") self.store.get_store_manager_appointments().append( StoreAppointment(self.owner, self.manager, [ManagerPermission.EDIT_INV])) self.purchase_policy_mock = PurchasePolicy()
def test_get_appointment_status(self): self.appointer_mock = User() self.appointee_mock = User() self.participant_owner = User() self.participants = [self.appointer_mock, self.participant_owner] self.appointee_mock.get_nickname = MagicMock( return_value="appointee-nickname") self.store.get_appointment_agreements().append( AppointmentAgreement(self.appointer_mock, self.appointee_mock, [self.appointer_mock])) res = self.store.get_appointment_status("appointee-nickname") self.assertEqual(res, AppointmentStatus.APPROVED)
def test_check_appointment_exist(self): self.appointer_mock = User() self.appointee_mock = User() self.participant_owner = User() self.participants = [self.appointer_mock, self.participant_owner] self.appointee_mock.get_nickname = MagicMock( return_value="appointee-nickname") self.store.get_appointment_agreements().append( AppointmentAgreement(self.appointer_mock, self.appointee_mock, self.participants)) self.assertTrue( self.store.check_appointment_exist("appointee-nickname")) self.assertFalse( self.store.check_appointment_exist("appointee-wrong-nickname"))
def test_remove_products(self): product1: Product = Product("Chair", 100, "Furniture") product3: Product = Product("Sofa", 1, "Furniture") self.store.add_product("Eytan", "Chair", 100, "Furniture", 5, 0) # All Valid - one product self.assertTrue(self.store.remove_products("Eytan", ["Chair"])) self.assertEqual(self.store.get_inventory().len(), 0) self.store.add_product("Eytan", "Chair", 100, "Furniture", 5,0) self.store.add_product("Eytan", "Chair", 100, "Furniture", 5, 0) self.store.add_product("Eytan", "Sofa", 1, "Furniture", 3, 0) # All valid - two products self.assertEqual(self.store.get_inventory().len(), 2) self.assertTrue(self.store.remove_products("Eytan", ["Chair", "Sofa"])) self.assertEqual(self.store.get_inventory().len(), 0) self.store.add_product("Eytan", "Chair", 100, "Furniture", 5, 0) self.store.add_product("Eytan", "Chair", 100, "Furniture", 5, 0) self.store.add_product("Eytan", "Sofa", 1, "Furniture", 3, 0) # All valid - not all inventory removed self.assertTrue(self.store.remove_products("Eytan", ["Chair"])) self.assertEqual(self.store.get_inventory().len(), 1) self.assertTrue(product3 in self.store.get_products_by(2, "")) # All valid - Manager self.assertTrue(self.store.remove_products("Not Eytan", ["Sofa"])) self.assertEqual(self.store.get_inventory().len(), 0) # Invalid product self.assertFalse(self.store.remove_products("Not Eytan", ["Eytan's Toy"])) # Invalid - Manager/Owner self.assertFalse(self.store.remove_products("", ["Chair", "Sofa"])) bad_manager = User() bad_manager.register("Half Eytan, half not Eytan", "Definitely Password") self.store.get_store_manager_appointments().append( StoreAppointment(self.owner, bad_manager, [ManagerPermission.WATCH_PURCHASE_HISTORY])) # Invalid - Manager permissions self.store.add_product("Eytan", "Chair", 100, "Furniture", 5, 0) self.store.add_product("Eytan", "Chair", 100, "Furniture", 5, 0) self.assertFalse(self.store.remove_products(bad_manager.get_nickname(), ["Chair"])) self.assertEqual(self.store.get_inventory().len(), 1) self.assertTrue(product1 in self.store.get_products_by(2, "")) self.assertEqual(self.store.get_inventory().get_amount("Chair"), 10)
def test_is_logged_out(self): guest = User() subscriber = User() subscriber.register("Sub", "scriber") subscriber.login("Sub", "scriber") self.__user.logout() # All valid self.assertTrue(self.__user.is_logged_out()) # Not valid - user is logged out self.assertFalse(subscriber.is_logged_out()) # Not valid - user isn't registered self.assertTrue(guest.is_logged_out())
def setUp(self): self.__valid_name = "anna9218" self.__valid_password = "******" self.__user = User() self.__user.register(self.__valid_name, self.__valid_password) self.__product = Product("Eytan's product", 12, "Eytan's category") self.__store: Store = Store("myStore") self.__products_to_add = [{ "product": self.__product, "store_name": self.__store.get_name(), "amount": 1, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }] # products_stores_quantity_ls
def setUp(self): # self.user.logoutState = StubLogout() # self.__valid_name = "anna9218" # self.__valid_pass = "******" # self.__invalid_input = "" # self.__product = StubProduct() # self.__store = StubStore() # self.__product_ls_to_add = [[self.__product, self.__store, 1]] # products_stores_quantity_ls self.__user = User() self.__registration_state_mock = Registration() self.__login_state_mock = Login() self.__shopping_cart_mock = ShoppingCart() self.__purchase_history_mock = [] self.__purchase_mock = Purchase([], 10.0, "store_name", "username") self.__shopping_basket_mock = ShoppingBasket()
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'])
def test_update_agreement_participants(self): self.appointer_mock = User() self.appointee_mock = User() self.participant_owner = User() self.participants = [self.appointer_mock, self.participant_owner] self.appointee_mock.get_nickname = MagicMock( return_value="appointee-nickname") self.appointer_mock.get_nickname = MagicMock( return_value="appointer-nickname") self.participant_owner.get_nickname = MagicMock( return_value="participant-nickname") self.store.get_appointment_agreements().append( AppointmentAgreement(self.appointer_mock, self.appointee_mock, self.participants)) res = self.store.update_agreement_participants( "appointee-nickname", "appointer-nickname", AppointmentStatus.APPROVED) self.assertTrue(res)
def setUp(self): self.__appointer_mock = User() self.__appointee_mock = User() self.__participant_owner = User() self.__participants = [self.__appointer_mock, self.__participant_owner] self.__appointer_mock.get_nickname = MagicMock( return_value="appointer-nickname") self.__appointee_mock.get_nickname = MagicMock( return_value="appointee-nickname") self.__participant_owner.get_nickname = MagicMock( return_value="participant-nickname") self.__trade_control_mock = TradeControl.get_instance() self.__appointment_agreement_1 = AppointmentAgreement( self.__appointer_mock, self.__appointee_mock, self.__participants) self.__appointment_agreement_2 = AppointmentAgreement( self.__appointer_mock, self.__appointee_mock, [self.__appointer_mock])
def test_logout(self): self.__user.login(self.__valid_name, self.__valid_password) # All valid self.assertTrue(self.__user.logout()) self.assertTrue(self.__user.is_logged_out()) self.assertFalse(self.__user.is_logged_in()) # Invalid - user is already logged out self.assertFalse(self.__user.logout()) self.assertTrue(self.__user.is_logged_out()) self.assertFalse(self.__user.is_logged_in()) guest = User() # Invalid - user isn't register self.assertFalse(guest.logout()) self.assertTrue(guest.is_logged_out()) self.assertFalse(guest.is_logged_in())
def setUp(self): self.store: Store = Store("myStore") self.owner = User() self.owner.register("Eytan", "password") self.store.get_owners_appointments().append(StoreAppointment(None, self.owner, [])) self.manager = User() self.manager.register("Not Eytan", "Yes Password") self.store.get_store_manager_appointments().append(StoreAppointment(self.owner, self.manager, [ManagerPermission.EDIT_INV])) dis_details = {'name': "p1", 'product': "Eytan"} later_date = datetime(2021, 8, 21) pre_con__details = {'product': "Eytan", 'min_amount': 2, 'min_basket_price': None} leaf_pol1 = ConditionalDiscountPolicy(2.5, later_date, dis_details, pre_con__details) dis_details = {'name': "p2", 'product': "Eytan"} pre_con__details = {'product': "all", 'min_amount': None, 'min_basket_price': 1} leaf_pol2 = ConditionalDiscountPolicy(5, later_date, dis_details, pre_con__details) self.__policy = DiscountPolicy(jsonpickle.encode(leaf_pol1), jsonpickle.encode(leaf_pol2), CompositeFlag.XOR, 10, "Comp_Pol", later_date) self.store.get_discount_policies().insert(0, self.__policy)
def test_is_manger(self): user = User() user.register("eden", "password") # All Valid self.store.add_manager(self.owner, user, [ManagerPermission.USERS_QUESTIONS]) self.assertTrue(self.store.is_manager("eden")) # Invalid - Not an existing user self.assertFalse(self.store.is_manager("not eden")) user2 = User() user2.register("Maybe Eden", "Definitely password") # Invalid - Existing user, not an owner self.assertFalse(self.store.is_manager("Maybe Eden")) # Invalid - Existing manager self.assertFalse(self.store.is_manager(self.owner.get_nickname()))
def test_is_owner(self): user = User() user.register("eden", "password") # All Valid self.store.add_owner("Eytan", user) self.assertTrue(self.store.is_owner("eden")) # Invalid - Not an existing user self.assertFalse(self.store.is_owner("not eden")) user2 = User() user2.register("Maybe Eden", "Definitely password") # Invalid - Existing user, not an owner self.assertFalse(self.store.is_owner("Maybe Eden")) self.store.add_manager(user, user2, [ManagerPermission.WATCH_PURCHASE_HISTORY]) # Invalid - Existing manager self.assertFalse(self.store.is_owner("Maybe Eden"))
def test_get_purchases(self): self.store.edit_manager_permissions(self.owner, self.manager.get_nickname(), [ManagerPermission.WATCH_PURCHASE_HISTORY]) purchase: Purchase = Purchase([{"product_name": "Chair", "product_price": 100, "amount": 5}, {"product_name": "Sofa", "product_price": 1, "amount": 1}], 501, self.store.get_name(), self.owner.get_nickname()) self.store.add_purchase(purchase) # All valid - owner self.assertListEqual(self.store.get_purchases(self.owner.get_nickname()), [purchase]) # All valid - manager self.assertListEqual(self.store.get_purchases(self.manager.get_nickname()), [purchase]) user = User() user.register("just a user", "but a special password") # Invalid - not an owner/manager self.assertListEqual(self.store.get_purchases(user.get_nickname()), []) self.store.add_manager(self.owner, user, [ManagerPermission.DEL_MANAGER]) # Invalid - not the right permissions self.assertListEqual(self.store.get_purchases(user.get_nickname()), [])
def test_add_owner(self): user = User() user.register("eden", "password") self.assertTrue(self.store.add_owner("shani", user)) self.assertEqual(len(self.store.get_owners()), 2)
def test_edit_manager_permissions(self): manager1 = User() manager1.register("probably eden", "password") self.store.add_manager(self.owner, manager1, [ManagerPermission.EDIT_MANAGER_PER, ManagerPermission.APPOINT_MANAGER]) manager2 = User() manager2.register("almost definitely eden", "password") self.store.add_manager(manager1, manager2, [ManagerPermission.EDIT_POLICIES]) # All valid - owner self.assertTrue(self.store.edit_manager_permissions(self.owner, self.manager.get_nickname(), [ManagerPermission.EDIT_POLICIES])) self.assertTrue(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.EDIT_POLICIES)) self.assertFalse(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.EDIT_INV)) # All valid - manager self.assertTrue(self.store.edit_manager_permissions(manager1, manager2.get_nickname(), [ManagerPermission.EDIT_INV])) self.assertTrue(self.store.has_permission(manager2.get_nickname(), ManagerPermission.EDIT_INV)) self.assertFalse(self.store.has_permission(manager2.get_nickname(), ManagerPermission.EDIT_POLICIES)) # All valid - owner, two permissions self.assertTrue(self.store.edit_manager_permissions(self.owner, self.manager.get_nickname(), [ManagerPermission.WATCH_PURCHASE_HISTORY, ManagerPermission.DEL_OWNER])) self.assertTrue(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.WATCH_PURCHASE_HISTORY)) self.assertTrue(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.DEL_OWNER)) self.assertFalse(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.EDIT_POLICIES)) # All valid - owner, two permissions self.assertTrue(self.store.edit_manager_permissions(self.owner, self.manager.get_nickname(), [ManagerPermission.WATCH_PURCHASE_HISTORY, ManagerPermission.DEL_OWNER])) self.assertTrue( self.store.has_permission(self.manager.get_nickname(), ManagerPermission.WATCH_PURCHASE_HISTORY)) self.assertTrue(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.DEL_OWNER)) self.assertFalse(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.EDIT_POLICIES)) # All valid - empty permissions self.assertTrue(self.store.edit_manager_permissions(self.owner, manager1.get_nickname(), [])) for i in range(1, 11): self.assertFalse(self.store.has_permission(manager1.get_nickname(), ManagerPermission(i))) user = User() user.register("not an owner", "not a password") # Invalid - not an owner self.assertFalse(self.store.edit_manager_permissions(user, self.manager.get_nickname(), [ManagerPermission.EDIT_POLICIES])) self.assertTrue( self.store.has_permission(self.manager.get_nickname(), ManagerPermission.WATCH_PURCHASE_HISTORY)) self.assertTrue(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.DEL_OWNER)) self.assertFalse(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.EDIT_POLICIES)) self.store.add_owner(self.owner.get_nickname(), user) # Invalid - not a manager self.assertFalse(self.store.edit_manager_permissions(self.owner, user, [ManagerPermission.EDIT_POLICIES])) for appointment in self.store.get_store_manager_appointments(): self.assertFalse(appointment.get_appointee().get_nickname() == user.get_nickname()) self.store.add_owner(self.owner.get_nickname(), user) # Invalid - not the owner which appoint the manager self.assertFalse(self.store.edit_manager_permissions(user, self.manager.get_nickname(), [ManagerPermission.EDIT_POLICIES])) self.assertTrue( self.store.has_permission(self.manager.get_nickname(), ManagerPermission.WATCH_PURCHASE_HISTORY)) self.assertTrue(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.DEL_OWNER)) self.assertFalse(self.store.has_permission(self.manager.get_nickname(), ManagerPermission.EDIT_POLICIES)) # Invalid - try change permissions to an owner self.assertFalse(self.store.edit_manager_permissions(self.owner, user, [ManagerPermission.EDIT_POLICIES])) for appointment in self.store.get_store_manager_appointments(): self.assertFalse(appointment.get_appointee().get_nickname() == user.get_nickname())
def test_login(self): # All Valid self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() # Invalid - username + whitespaces, valid password self.assertFalse( self.__user.login(self.__valid_name + " ", self.__valid_password)['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # Invalid - valid username, password + whitespaces self.assertFalse( self.__user.login(self.__valid_name, self.__valid_password + " ")['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # Invalid -username doesn't exist self.assertFalse( self.__user.login("self.__valid_name", self.__valid_password)['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # Invalid - incorrect password self.assertFalse( self.__user.login(self.__valid_name, "self.__valid_password")['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # All Valid - second and third try self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() registered = User() registered.register("Eytan", "Eytan's password") # Invalid - password of different registered user self.assertFalse( self.__user.login(self.__valid_name, "Eytan's password")['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) self.__user.login(self.__valid_name, self.__valid_password) # Invalid - user already logged in self.assertFalse( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() # Register and login other users and than try to login again self.assertTrue( registered.login("Eytan", "Eytan's password")['response']) registered.logout() other_user = User() other_user.register("yarin", "100") self.assertTrue(other_user.login("yarin", "100")['response']) other_user.logout() self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response'])
def test_register(self): # All valid guest1 = User() self.assertTrue(guest1.register("valid", "valid")) self.assertTrue(guest1.is_registered()) self.assertTrue(guest1.is_logged_out()) self.assertFalse(guest1.is_logged_in()) # All valid -username has white spaces but not empty guest11 = User() self.assertTrue( guest11.register("valid validovich", "valid")['response']) self.assertTrue(guest11.is_registered()) self.assertTrue(guest11.is_logged_out()) self.assertFalse(guest11.is_logged_in()) # Invalid - username is empty guest2 = User() self.assertFalse(guest2.register("", "valid")['response']) self.assertFalse(guest2.is_registered()) self.assertTrue(guest2.is_logged_out()) self.assertFalse(guest2.is_logged_in()) # Invalid - password is empty self.assertFalse(guest2.register("valid", "")['response']) self.assertFalse(guest2.is_registered()) self.assertTrue(guest2.is_logged_out()) self.assertFalse(guest2.is_logged_in()) # Invalid - user already exist self.assertFalse(guest1.register("not valid", "not valid")['response']) self.assertEqual(guest1.get_nickname(), "valid")
def test_save_products_to_basket(self): guest = User() # All valid- guest self.assertTrue( guest.save_products_to_basket(self.__products_to_add)['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Valid - empty products self.assertTrue(guest.save_products_to_basket([])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Invalid - product is None self.assertFalse( guest.save_products_to_basket([{ "product": None, "store_name": self.__store.get_name(), "amount": 1, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Invalid - Edge case - quantity is zero self.assertFalse( guest.save_products_to_basket([{ "product": self.__product, "store_name": self.__store.get_name(), "amount": 0, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Invalid - Negative quantity self.assertFalse( guest.save_products_to_basket([{ "product": self.__product, "store_name": self.__store.get_name(), "amount": -11, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products)
def test_remove_manager(self): # def remove_manager(self, appointer_nickname: str, appointee_nickname: str) -> bool: manager1 = User() manager1.register("probably eden", "password") self.store.add_manager(self.owner, manager1, [ManagerPermission.DEL_MANAGER, ManagerPermission.APPOINT_MANAGER]) manager2 = User() manager2.register("almost definitely eden", "password") self.store.add_manager(manager1, manager2, [ManagerPermission.EDIT_POLICIES]) # Invalid - not the right permissions self.assertFalse(self.store.remove_manager(manager2.get_nickname(), self.manager.get_nickname())) self.assertTrue(self.manager in self.store.get_managers()) # All valid - manager as appointer self.assertTrue(self.store.remove_manager(manager1.get_nickname(), manager2.get_nickname())) self.assertFalse(manager2 in self.store.get_managers()) # All valid - owner as appointer self.assertTrue(self.store.remove_manager(self.owner.get_nickname(), manager1.get_nickname())) self.assertFalse(manager1 in self.store.get_managers()) managers = self.store.get_managers() # Invalid - not an existing manager self.assertFalse(self.store.remove_manager(self.owner.get_nickname(), manager1.get_nickname())) self.assertEqual(len(managers), len(self.store.get_managers())) for m in managers: self.assertTrue(m in self.store.get_managers()) # Invalid - not an existing appointer self.assertFalse(self.store.remove_manager(manager2.get_nickname(), self.manager.get_nickname())) self.assertEqual(len(managers), len(self.store.get_managers())) for m in managers: self.assertTrue(m in self.store.get_managers()) user = User() user.register("not an owner", "not a password") self.store.add_owner(self.owner.get_nickname(), user) # Invalid - not the owner that appoint the manager self.assertFalse(self.store.remove_manager(user.get_nickname(), self.manager.get_nickname())) self.assertEqual(len(managers), len(self.store.get_managers())) for m in managers: self.assertTrue(m in self.store.get_managers())
def test_remove_owner(self): store: Store = Store("store1") store.get_owners_appointments().append(StoreAppointment(None, self.owner, [])) owner1 = User() owner1.register("owner1", "password") store.add_owner(self.owner.get_nickname(), owner1) owner2 = User() owner2.register("owner2", "password") store.add_owner("owner1", owner2) owner3 = User() owner3.register("owner3", "password") store.add_owner("owner2", owner3) manager1 = User() manager1.register("manager1", "password") store.add_manager(owner3, manager1, []) manager2 = User() manager2.register("manager2", "password") store.add_manager(self.owner, manager2, []) # failed owner2 didn't appoint owner 2 as owner res = store.remove_owner("owner2", "owner1") self.assertEqual(res['response'], []) self.assertEqual(res['msg'], "Error! remove store owner failed.") # failed res = store.remove_owner("owner", "owner1") self.assertEqual(res['response'], []) self.assertEqual(res['msg'], "Error! remove store owner failed.") # success res = store.remove_owner(self.owner.get_nickname(), "owner1") self.assertEqual(res['response'], ['owner1 removed as owner', 'owner2 removed as owner', 'owner3 removed as owner', 'manager1 removed as manager']) self.assertEqual(res['msg'], "Store owner owner1 and his appointees were removed successfully.") self.assertFalse(store.is_owner('owner1')) self.assertFalse(store.is_owner('owner2')) self.assertFalse(store.is_owner('owner3')) self.assertFalse(store.is_manager('manager1')) self.assertTrue(store.is_manager('manager2'))
def test_is_owner(self): user = User() user.register("eden", "password") self.assertFalse(self.store.is_owner("eden")) self.store.add_owner("shani", user) self.assertTrue(self.store.is_owner("eden"))
class UserTests(unittest.TestCase): def setUp(self): self.__valid_name = "anna9218" self.__valid_password = "******" self.__user = User() self.__user.register(self.__valid_name, self.__valid_password) self.__product = Product("Eytan's product", 12, "Eytan's category") self.__store: Store = Store("myStore") self.__products_to_add = [{ "product": self.__product, "store_name": self.__store.get_name(), "amount": 1, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }] # products_stores_quantity_ls def test_register(self): # All valid guest1 = User() self.assertTrue(guest1.register("valid", "valid")) self.assertTrue(guest1.is_registered()) self.assertTrue(guest1.is_logged_out()) self.assertFalse(guest1.is_logged_in()) # All valid -username has white spaces but not empty guest11 = User() self.assertTrue( guest11.register("valid validovich", "valid")['response']) self.assertTrue(guest11.is_registered()) self.assertTrue(guest11.is_logged_out()) self.assertFalse(guest11.is_logged_in()) # Invalid - username is empty guest2 = User() self.assertFalse(guest2.register("", "valid")['response']) self.assertFalse(guest2.is_registered()) self.assertTrue(guest2.is_logged_out()) self.assertFalse(guest2.is_logged_in()) # Invalid - password is empty self.assertFalse(guest2.register("valid", "")['response']) self.assertFalse(guest2.is_registered()) self.assertTrue(guest2.is_logged_out()) self.assertFalse(guest2.is_logged_in()) # Invalid - user already exist self.assertFalse(guest1.register("not valid", "not valid")['response']) self.assertEqual(guest1.get_nickname(), "valid") def test_login(self): # All Valid self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() # Invalid - username + whitespaces, valid password self.assertFalse( self.__user.login(self.__valid_name + " ", self.__valid_password)['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # Invalid - valid username, password + whitespaces self.assertFalse( self.__user.login(self.__valid_name, self.__valid_password + " ")['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # Invalid -username doesn't exist self.assertFalse( self.__user.login("self.__valid_name", self.__valid_password)['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # Invalid - incorrect password self.assertFalse( self.__user.login(self.__valid_name, "self.__valid_password")['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) # All Valid - second and third try self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() registered = User() registered.register("Eytan", "Eytan's password") # Invalid - password of different registered user self.assertFalse( self.__user.login(self.__valid_name, "Eytan's password")['response']) self.assertFalse(self.__user.is_logged_in()) self.assertTrue(self.__user.is_logged_out()) self.__user.login(self.__valid_name, self.__valid_password) # Invalid - user already logged in self.assertFalse( self.__user.login(self.__valid_name, self.__valid_password)['response']) self.assertTrue(self.__user.is_logged_in()) self.assertFalse(self.__user.is_logged_out()) self.__user.logout() # Register and login other users and than try to login again self.assertTrue( registered.login("Eytan", "Eytan's password")['response']) registered.logout() other_user = User() other_user.register("yarin", "100") self.assertTrue(other_user.login("yarin", "100")['response']) other_user.logout() self.assertTrue( self.__user.login(self.__valid_name, self.__valid_password)['response']) def test_logout(self): self.__user.login(self.__valid_name, self.__valid_password) # All valid self.assertTrue(self.__user.logout()) self.assertTrue(self.__user.is_logged_out()) self.assertFalse(self.__user.is_logged_in()) # Invalid - user is already logged out self.assertFalse(self.__user.logout()) self.assertTrue(self.__user.is_logged_out()) self.assertFalse(self.__user.is_logged_in()) guest = User() # Invalid - user isn't register self.assertFalse(guest.logout()) self.assertTrue(guest.is_logged_out()) self.assertFalse(guest.is_logged_in()) def test_check_password(self): # All valid self.assertTrue(self.__user.check_password(self.__valid_password)) # Invalid password doesn't exist self.assertFalse(self.__user.check_password("self.__valid_password")) registered = User() registered.register("Eytan", "Eytan's password") # Invalid - password exist but isn't corresponding with the username self.assertFalse(registered.check_password(self.__valid_password)) def test_check_nickname(self): # All valid self.assertTrue(self.__user.check_nickname(self.__valid_name)) # Invalid password doesn't exist self.assertFalse(self.__user.check_nickname("self.__valid_password")) registered = User() registered.register("Eytan", "Eytan's password") # Invalid - password exist but isn't corresponding with the username self.assertFalse(registered.check_nickname(self.__valid_name)) def test_is_logged_in(self): guest = User() subscriber = User() subscriber.register("Sub", "scriber") self.__user.login(self.__valid_name, self.__valid_password) # All valid self.assertTrue(self.__user.is_logged_in()) # Not valid - user is logged out self.assertFalse(subscriber.is_logged_in()) # Not valid - user isn't registered self.assertFalse(guest.is_logged_in()) def test_is_logged_out(self): guest = User() subscriber = User() subscriber.register("Sub", "scriber") subscriber.login("Sub", "scriber") self.__user.logout() # All valid self.assertTrue(self.__user.is_logged_out()) # Not valid - user is logged out self.assertFalse(subscriber.is_logged_out()) # Not valid - user isn't registered self.assertTrue(guest.is_logged_out()) def test_is_registered(self): guest = User() self.__user.logout() # All valid - user is registered self.assertTrue(self.__user.is_registered()) # All valid - user isn't registered self.assertFalse(guest.is_registered()) def test_get_nickname(self): guest = User() self.__user.logout() # All valid - user is registered self.assertEqual(self.__user.get_nickname(), self.__valid_name) # All valid - user isn't registered self.assertIsNone(guest.get_nickname()) def test_save_products_to_basket(self): guest = User() # All valid- guest self.assertTrue( guest.save_products_to_basket(self.__products_to_add)['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Valid - empty products self.assertTrue(guest.save_products_to_basket([])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Invalid - product is None self.assertFalse( guest.save_products_to_basket([{ "product": None, "store_name": self.__store.get_name(), "amount": 1, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Invalid - Edge case - quantity is zero self.assertFalse( guest.save_products_to_basket([{ "product": self.__product, "store_name": self.__store.get_name(), "amount": 0, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # Invalid - Negative quantity self.assertFalse( guest.save_products_to_basket([{ "product": self.__product, "store_name": self.__store.get_name(), "amount": -11, "discount_type": DiscountType.DEFAULT, "purchase_type": PurchaseType.DEFAULT }])['response']) self.assertEqual( 1, len(guest.get_shopping_cart().get_store_basket( self.__store.get_name()).get_products())) products = [ product_as_dictionary['product'] for product_as_dictionary in guest.get_shopping_cart(). get_store_basket(self.__store.get_name()).get_products() ] self.assertIn(self.__product, products) # @logger def tearDown(self): # maybe delete the registered user resulted from this test pass def __repr__(self): return repr("UserTests") if __name__ == '__main__': unittest.main()
class StoreTests(unittest.TestCase): def setUp(self): self.store: Store = Store("myStore") self.owner = User() self.owner.register("shani", "passwordd45646") self.store.get_owners_appointments().append( StoreAppointment(None, self.owner, [])) self.manager = User() self.manager.register("dani", "passwordd45646") self.store.get_store_manager_appointments().append( StoreAppointment(self.owner, self.manager, [ManagerPermission.EDIT_INV])) self.purchase_policy_mock = PurchasePolicy() def test_get_products_by(self): self.assertTrue( self.store.add_products("shani", [{ "name": "Chair", "price": 100, "category": "Furniture", "amount": 5, "purchase_type": 0 }, { "name": "TV", "price": 100, "category": "Electric", "amount": 5, "purchase_type": 0 }, { "name": "Sofa", "price": 100, "category": "Furniture", "amount": 5, "purchase_type": 0 }])) ls = self.store.get_products_by(1, "Chaer") self.assertEqual(ls, []) ls = self.store.get_products_by(1, "Chair") self.assertEqual(len(ls), 1) ls = self.store.get_products_by(2, "a") self.assertEqual(len(ls), 2) ls = self.store.get_products_by(3, "Furniture") self.assertEqual(len(ls), 2) ls = self.store.get_products_by(3, "Electric") self.assertEqual(len(ls), 1) def test_add_products(self): # self.product3 = Product("Guitar", 100, "Musical Instruments") res = self.store.add_products("shani", [{ "name": "Chair", "price": 100, "category": "Furniture", "amount": 5, "purchase_type": 0 }, { "name": "Sofa", "price": 100, "category": "Furniture", "amount": 5, "purchase_type": 0 }]) self.assertTrue(res['response']) res = self.store.add_products("shani", [{ "name": "Chair", "price": 100, "category": "Furniture", "amount": 5, "purchase_type": 0 }]) self.assertTrue(res['response']) res = self.store.add_products("shani", [{ "name": "Chair", "price": -99, "category": "Furniture", "amount": 5, "purchase_type": 0 }, { "name": "Sofa", "price": 100, "category": "Furniture", "amount": 5, "purchase_type": 0 }]) self.assertFalse(res['response']) def test_add_product(self): # self.product3 = Product("Guitar", 100, "Musical Instruments") self.assertTrue( self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0)) self.assertTrue( self.store.add_product("shani", "Sofa", 100, "Furniture", 5, 0)) self.assertTrue( self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0)) self.assertEqual(self.store.get_inventory().get_amount("Chair"), 10) def test_remove_products(self): self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0) self.assertFalse(self.store.remove_products("", ["Chair", "Sofa"])) self.assertEqual(self.store.get_inventory().len(), 1) self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0) self.store.add_product("shani", "Sofa", 100, "Furniture", 3, 0) self.assertEqual(self.store.get_inventory().len(), 2) self.assertFalse(self.store.remove_products("", ["Chair", "Sofa"])) self.assertTrue(self.store.remove_products("shani", ["Chair", "Sofa"])) self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0) self.assertTrue(self.store.remove_products("dani", ["Chair"])) self.assertEqual(self.store.get_inventory().len(), 0) def test_remove_product(self): self.assertFalse(self.store.remove_product("Chair")) self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0) self.assertEqual(self.store.get_inventory().len(), 1) self.assertTrue(self.store.remove_product("Chair")) self.assertEqual(self.store.get_inventory().len(), 0) def test_change_price(self): self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0) self.assertTrue(self.store.change_price("Chair", 13)) self.assertEqual(self.store.get_product("Chair").get_price(), 13) self.assertTrue(self.store.change_price("Chair", 8)) self.assertEqual(self.store.get_product("Chair").get_price(), 8) self.assertFalse(self.store.change_price("NNNN", 8)) self.assertFalse(self.store.change_price("Chair", -8)) self.assertEqual(self.store.get_product("NNNN"), None) def test_change_name(self): self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0) self.assertTrue(self.store.change_name("Chair", "Chair222")) self.assertNotEqual(self.store.get_product("Chair222"), None) self.assertEqual(self.store.get_product("Chair"), None) self.assertTrue(self.store.change_name("Chair222", "Blaaaa")) self.assertNotEqual(self.store.get_product("Blaaaa"), None) self.assertEqual(self.store.get_product("Chair222"), None) self.assertFalse(self.store.change_name("NNNN", "blaaa")) self.assertEqual(self.store.get_product("NNNN"), None) self.assertEqual(self.store.get_product("blaaa"), None) def test_change_amount(self): self.store.add_product("shani", "Chair", 100, "Furniture", 5, 0) self.assertTrue(self.store.change_amount("Chair", 3)) self.assertEqual(self.store.get_inventory().get_amount("Chair"), 3) self.assertTrue(self.store.change_amount("Chair", 8)) self.assertFalse(self.store.change_amount("Chair", -8)) self.assertEqual(self.store.get_inventory().get_amount("Chair"), 8) def test_add_owner(self): user = User() user.register("eden", "password") self.assertTrue(self.store.add_owner("shani", user)) self.assertEqual(len(self.store.get_owners()), 2) def test_check_appointment_exist(self): self.appointer_mock = User() self.appointee_mock = User() self.participant_owner = User() self.participants = [self.appointer_mock, self.participant_owner] self.appointee_mock.get_nickname = MagicMock( return_value="appointee-nickname") self.store.get_appointment_agreements().append( AppointmentAgreement(self.appointer_mock, self.appointee_mock, self.participants)) self.assertTrue( self.store.check_appointment_exist("appointee-nickname")) self.assertFalse( self.store.check_appointment_exist("appointee-wrong-nickname")) def test_update_agreement_participants(self): self.appointer_mock = User() self.appointee_mock = User() self.participant_owner = User() self.participants = [self.appointer_mock, self.participant_owner] self.appointee_mock.get_nickname = MagicMock( return_value="appointee-nickname") self.appointer_mock.get_nickname = MagicMock( return_value="appointer-nickname") self.participant_owner.get_nickname = MagicMock( return_value="participant-nickname") self.store.get_appointment_agreements().append( AppointmentAgreement(self.appointer_mock, self.appointee_mock, self.participants)) res = self.store.update_agreement_participants( "appointee-nickname", "appointer-nickname", AppointmentStatus.APPROVED) self.assertTrue(res) def test_get_appointment_status(self): self.appointer_mock = User() self.appointee_mock = User() self.participant_owner = User() self.participants = [self.appointer_mock, self.participant_owner] self.appointee_mock.get_nickname = MagicMock( return_value="appointee-nickname") self.store.get_appointment_agreements().append( AppointmentAgreement(self.appointer_mock, self.appointee_mock, [self.appointer_mock])) res = self.store.get_appointment_status("appointee-nickname") self.assertEqual(res, AppointmentStatus.APPROVED) # @logger def test_is_owner(self): user = User() user.register("eden", "password") self.assertFalse(self.store.is_owner("eden")) self.store.add_owner("shani", user) self.assertTrue(self.store.is_owner("eden")) def test_is_in_store_inventory(self): self.store.add_product("shani", "product1", 100, "some category", 5, 0) self.store.add_product("shani", "product2", 10, "some category", 2, 0) # All valid one product amount_per_product = [["product1", 4]] result = self.store.is_in_store_inventory(amount_per_product) self.assertTrue(result) # All valid two products amount_per_product = [["product1", 4], ["product2", 1]] result = self.store.is_in_store_inventory(amount_per_product) self.assertTrue(result) # Exactly the same as in stock amount_per_product = [["product1", 5], ["product2", 2]] result = self.store.is_in_store_inventory(amount_per_product) self.assertTrue(result) # One product not enough in stock amount_per_product = [["product1", 6], ["product2", 1]] result = self.store.is_in_store_inventory(amount_per_product) self.assertFalse(result) # Two product not enough in stock amount_per_product = [["product1", 6], ["product2", 10]] result = self.store.is_in_store_inventory(amount_per_product) self.assertFalse(result) # One product doesn't exist amount_per_product = [["wrong product1", 5], ["product2", 1]] result = self.store.is_in_store_inventory(amount_per_product) self.assertFalse(result) # Two product doesn't exist amount_per_product = [["wrong product1", 5], ["wrong product2", 1]] result = self.store.is_in_store_inventory(amount_per_product) self.assertFalse(result) # 4.2 def test_purchase_policy_exists(self): # policy exists self.purchase_policy_mock.equals = MagicMock(return_value=True) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.purchase_policy_exists({ "name": "policy1", "products": ["product1"], "min_amount": 3 }) self.assertTrue(res) # policy doesn't exists self.purchase_policy_mock.equals = MagicMock(return_value=False) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.purchase_policy_exists({ "name": "policy1", "products": ["product1"], "min_amount": 3 }) self.assertFalse(res) def test_add_purchase_policy(self): # all valid details for new policy self.purchase_policy_mock.add_purchase_policy = MagicMock( return_value={ "response": True, "msg": "ok" }) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.define_purchase_policy({ "name": "policy1", "products": ["product1"], "min_amount": 3 }) self.assertTrue(res["response"]) # invalid details self.purchase_policy_mock.add_purchase_policy = MagicMock( return_value={ "response": False, "msg": "fail" }) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.define_purchase_policy({ "name": "policy1", "products": ["product1"] }) self.assertFalse(res["response"]) def test_update_purchase_policy(self): # valid details self.purchase_policy_mock.update = MagicMock(return_value={ "response": True, "msg": "ok" }) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.define_purchase_policy({ "name": "policy1", "products": ["product1"], "min_amount": 3 }) self.assertTrue(res["response"]) # invalid details self.purchase_policy_mock.update = MagicMock(return_value={ "response": False, "msg": "fail" }) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.define_purchase_policy({ "name": "policy1", "products": ["product1"] }) self.assertFalse(res["response"]) def test_get_purchase_policies(self): # some policy exist self.purchase_policy_mock.get_details = MagicMock( return_value={"name": "policy1"}) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.get_purchase_policies() self.assertTrue(len(res) > 0) # no policies set yet # self.purchase_policy_mock.get_details = MagicMock(return_value={}) self.purchase_policy_mock.get_details = MagicMock(return_value={}) self.store.set_purchase_policies(self.purchase_policy_mock) res = self.store.get_purchase_policies() self.assertTrue(len(res) == 0) def test_remove_owner(self): owner1 = StubUser() owner1.register("owner1", "password") self.store.add_owner("shani", owner1) owner2 = StubUser() owner2.register("owner2", "password") self.store.add_owner("owner1", owner2) owner3 = StubUser() owner3.register("owner3", "password") self.store.add_owner("owner2", owner3) manager1 = StubUser() manager1.register("manager1", "password") self.store.add_manager(owner3, manager1, []) manager2 = StubUser() manager2.register("manager2", "password") self.store.add_manager(self.owner, manager2, []) # failed owner2 didn't appoint owner 2 as owner res = self.store.remove_owner("owner2", "owner1") self.assertEqual(res['response'], []) self.assertEqual(res['msg'], "Error! remove store owner failed.") # failed res = self.store.remove_owner("owner", "owner1") self.assertEqual(res['response'], []) self.assertEqual(res['msg'], "Error! remove store owner failed.") # success res = self.store.remove_owner("shani", "owner1") self.assertEqual(res['response'], [ 'owner1 removed as owner', 'owner2 removed as owner', 'owner3 removed as owner', 'manager1 removed as manager' ]) self.assertEqual( res['msg'], "Store owner owner1 and his appointees were removed successfully.") self.assertFalse(self.store.is_owner('owner1')) self.assertFalse(self.store.is_owner('owner2')) self.assertFalse(self.store.is_owner('owner3')) self.assertFalse(self.store.is_manager('manager1')) self.assertTrue(self.store.is_manager('manager2')) def test_remove_owner_appointees(self): owner1 = StubUser() owner1.register("owner1", "password") self.store.add_owner("shani", owner1) owner2 = StubUser() owner2.register("owner2", "password") self.store.add_owner("owner1", owner2) owner3 = StubUser() owner3.register("owner3", "password") self.store.add_owner("owner2", owner3) manager1 = StubUser() manager1.register("manager1", "password") self.store.add_manager(owner3, manager1, []) manager2 = StubUser() manager2.register("manager2", "password") self.store.add_manager(self.owner, manager2, []) res = self.store.remove_owner_appointees("owner1") self.assertEqual(res, [ 'owner2 removed as owner', 'owner3 removed as owner', 'manager1 removed as manager' ]) self.assertTrue(self.store.is_owner('owner1')) self.assertFalse(self.store.is_owner('owner2')) self.assertFalse(self.store.is_owner('owner3')) self.assertFalse(self.store.is_manager('manager1')) self.assertTrue(self.store.is_manager('manager2')) def tearDown(self) -> None: self.store = None def __repr__(self): return repr("StoreTests")
def test_open_store(self): user = User() user_nickname = "Eytan" user_password = "******" user.register(user_nickname, user_password) stores_num = len(TradeControl.get_instance().get_stores()) (TradeControl.get_instance()).register_guest(user_nickname, user_password) (TradeControl.get_instance()).login_subscriber(user_nickname, user_password) # All valid self.assertTrue( self.__subscriber.open_store("myFirstStore")['response']) self.assertEqual(stores_num + 1, len((TradeControl.get_instance()).get_stores())) store: Store = (TradeControl.get_instance()).get_store("myFirstStore") self.assertIsNotNone(store) self.assertIn((TradeControl.get_instance()).get_curr_user(), store.get_owners()) stores_num = stores_num + 1 # Invalid - store already exist self.assertFalse( self.__subscriber.open_store("myFirstStore")['response']) self.assertEqual(stores_num, len((TradeControl.get_instance()).get_stores())) self.assertIsNotNone( (TradeControl.get_instance()).get_store("myFirstStore")) bad_user = User() (TradeControl.get_instance()).set_curr_user(bad_user) # Invalid - curr_user doesn't register self.assertFalse( self.__subscriber.open_store("not myFirstStore")['response']) self.assertEqual(stores_num, len((TradeControl.get_instance()).get_stores())) self.assertIsNone( (TradeControl.get_instance()).get_store("not myFirstStore")) not_logged_in_user = User() not_logged_in_user.register("I am", "Logged out") (TradeControl.get_instance()).set_curr_user(not_logged_in_user) # Invalid - curr_user doesn't register self.assertFalse( self.__subscriber.open_store("not myFirstStore")['response']) self.assertEqual(stores_num, len((TradeControl.get_instance()).get_stores())) self.assertIsNone( (TradeControl.get_instance()).get_store("not myFirstStore")) (TradeControl.get_instance()).set_curr_user(user) # Invalid - store name is empty self.assertFalse( self.__subscriber.open_store(" ")['response']) self.assertEqual(stores_num, len((TradeControl.get_instance()).get_stores())) self.assertIsNone( (TradeControl.get_instance()).get_store(" "))
def test_remove_owner_appointees(self): store: Store = Store("store") store.get_owners_appointments().append(StoreAppointment(None, self.owner, [])) owner1 = User() owner1.register("owner1", "password") store.add_owner(self.owner.get_nickname(), owner1) owner2 = User() owner2.register("owner2", "password") store.add_owner("owner1", owner2) owner3 = User() owner3.register("owner3", "password") store.add_owner("owner2", owner3) manager1 = User() manager1.register("manager1", "password") store.add_manager(owner3, manager1, []) manager2 = User() manager2.register("manager2", "password") store.add_manager(self.owner, manager2, []) res = store.remove_owner_appointees("owner1") self.assertEqual(res, ['owner2 removed as owner', 'owner3 removed as owner', 'manager1 removed as manager']) self.assertTrue(store.is_owner('owner1')) self.assertFalse(store.is_owner('owner2')) self.assertFalse(store.is_owner('owner3')) self.assertFalse(store.is_manager('manager1')) self.assertTrue(store.is_manager('manager2'))