def test_change_details_of_product(self): user1 = User("amir", 1) user1.identifier = 0 user1.username = "******" user1.password = "******" user1.state = State.STORE_OWNER user1.is_logged_in = True store1 = Store("mega", 1, "123123", None, None) store1.store_number = 1 product1 = Product('chocholate', 'Food', ['Food', 'Sweet'], 10) product1.catalog_number = 1 store1.owners = [0] store1.add_new_product(product1) Ecommerce.get_instance().subscribers = [user1] Ecommerce.get_instance().stores = [store1] self.assertTrue( user1.change_details_of_product(1, "name", "whiteChocholate").val, "need return True") self.assertFalse( user1.change_details_of_product(2, "name", "whiteChocholate").val, "need return False")
def get_user_by_username(self, username: str) -> User: """ Get user by username. :param username: username of the user to be fetched :rtype: User """ UserRecord = namedtuple('UserRecord', 'username, password_salt, password') query = f'''SELECT username, password_salt, password from passwords WHERE username = '******' ''' try: self.cur.execute(query) user = User() for user_fetched in map(UserRecord._make, self.cur.fetchall()): user.username = user_fetched.username user.password_salt = user_fetched.password_salt user.password_hash = user_fetched.password self.con.commit() except Exception as e: raise self.con.DatabaseError(f'User does not exist: {str(e)}') return user