def sync_all_users_operations(self): from app.entities.user import User # update all the user's pre calculate permissions for user_id in self._users: user = User.get(user_id) user.sync_accessible_ops()
def test_add_user_throws_exception(session_with_user): session = session_with_user new_user = User("OtroID") for i in range(0, Session.MAX_USERS_PER_SESSION - 1): session.add_user(new_user) with pytest.raises(NotMoreUsersAllowedException): session.add_user(new_user)
def test_is_match_negative(session_with_vote_yes): session = session_with_vote_yes new_user = User("Nuevo_user") session.add_user(new_user) session.vote(new_user.id, 0, False) assert not session.is_match()
def test_is_match_positive(session_with_vote_yes): session = session_with_vote_yes new_user = User("Nuevo_user") session.add_user(new_user) session.vote(new_user.id, 0, True) assert session.is_match()
def test_add_user(watchables): session = Session("OtroID", watchables) new_user = User("Nuevo_user") session.add_user(new_user) users = session.get_users() assert len(users) == 1 assert users[0].id == new_user.id
def test_save_and_read(self): with self.app_context(): user = User(username=USER_NAME, password=PASSWORD) UserRepository.create(user=user) user_by_id = UserRepository.find_by_id(USER_ID) user_by_name = UserRepository.find_by_username(USER_NAME) self.assertEqual(USER_ID, user_by_id.id_) self.assertEqual(USER_NAME, user_by_name.username)
def test_count_yes(user, session_with_vote_yes): session = session_with_vote_yes new_user = User("Nuevo_user") session.add_user(new_user) session.vote(new_user.id, 0, False) yes_votes, total_votes = session.get_votes_of_watchable(0) assert yes_votes == 1 assert total_votes == 2
def remove_allowed_operations(self, resource, action_type): """ Removes a particular operations from a Role :param resource: Resource entity :param action_type: ActionType entity :return: """ operation_id = get_operation_identifier(resource, action_type) self.allowed_operations.remove( get_operation_identifier(resource, action_type)) from app.entities.user import User # update all the user's pre calculate permissions for user_id in self._users: user = User.get(user_id) user.remove_accessible_ops(operation_id)
def add_allowed_operations(self, resource, action_type): """ Adds one operations at a time to the particular role ~ Post that updates those operation's permission to Users :param resource: Resource entity :param action_type: ActionType entity :return: """ operation_id = get_operation_identifier(resource, action_type) self.allowed_operations.add(operation_id) from app.entities.user import User # update all the user's pre calculate permissions for user_id in self._users: user = User.get(user_id) user.add_accessible_ops(operation_id)
def existing_session_and_user(existing_session): existing_user = User('yo-también') existing_session.add_user(existing_user) yield existing_session, existing_user
def user(): user = User('username', 'password') user.id = 1 return user
from dotenv import load_dotenv from pathlib import Path import os from lib.math import calc from app.entities.user import User # Read .env file load_dotenv(verbose=True) env_path = Path('.') / '.env' load_dotenv(dotenv_path=env_path) # does it work? print("Hallo lieber ", os.getenv('USERNAME')) # awesome calculation! print("3 plus 5 ist {}!".format(calc.sum(3, 5))) # does it also find the Python class? u = User("Gustav") u.print_info()
def _make_entity(cls, user: UserModel) -> Union[User, None]: if not user: return None return User(id_=user.id, username=user.username, password=user.password)
def user(): return User('admin', md5_hash('secret_key').encode())
def make_user_entity(self, data: dict) -> User: return User(username=data['username'], password=data['password'])
def user(): return User("UnID")