def test_cant_unblock_user_because_doesnt_exist(postgresql_db): session = postgresql_db.session create_all(session) insert_test_user(session) sut = UserPersistence(postgresql_db) user = sut.get_user_by_email('*****@*****.**') assert user.email == '*****@*****.**' with pytest.raises(UserNotFoundException): sut.unblock_user('*****@*****.**')
def test_cant_unblock_user_because_user_is_already_unblocked(postgresql_db): session = postgresql_db.session create_all(session) insert_test_user(session) sut = UserPersistence(postgresql_db) user = sut.get_user_by_email('*****@*****.**') assert user.email == '*****@*****.**' sut.block_user('*****@*****.**') sut.unblock_user('*****@*****.**') with pytest.raises(UserlAlreadyUnblockedException): sut.unblock_user('*****@*****.**')
def test_unblock_existent_user_successfully(postgresql_db): session = postgresql_db.session create_all(session) insert_test_user(session) sut = UserPersistence(postgresql_db) user = sut.get_user_by_email('*****@*****.**') assert user.email == '*****@*****.**' assert user.full_name == 'Test User' assert user.phone_number == '444-4444' assert user.blocked_user == '0' sut.block_user('*****@*****.**') sut.unblock_user('*****@*****.**') user = sut.get_user_by_email('*****@*****.**') assert user.email == '*****@*****.**' assert user.blocked_user == '0'
def _delete_user(user_email): logger.debug('Requested to delete user: '******'Successfully deleted user') logger.debug('Requesting to delete user from app server') delete_user_app_server_url = os.environ.get( 'APP_SERVER_URL') + '/api/users/' + user_email logger.debug('Url: ' + delete_user_app_server_url) response_app_server = requests.delete(url=delete_user_app_server_url) if response_app_server.status_code == HTTPStatus.OK: result, status_code = { 'Delete': 'successfully deleted user with email {0}'.format(user_email) }, HTTPStatus.OK logger.debug('User deleted') else: result, status_code = { 'Error': 'Couldnt delete user {0} in app server'.format(user_email) }, HTTPStatus.INTERNAL_SERVER_ERROR logger.debug('Couldnt delete user from app server') try: user_persistence.unblock_user(user_email) except UserNotFoundException: logger.critical('Couldnt find user to unblock') except UserlAlreadyUnblockedException: logger.critical('User was never blocked') except UserNotFoundException: result, status_code = { 'Error': 'User {0} doesnt exist'.format(user_email) }, HTTPStatus.NOT_FOUND logger.debug('User doesnt exist') except UserlAlreadyBlockedException: result, status_code = { 'Error': 'User {0} was already deleted'.format(user_email) }, HTTPStatus.NOT_FOUND logger.debug('User was already deleted') return result, status_code