Beispiel #1
0
def generate_fake_email(mailbox=None):
    insert_position = mailbox.find('@')
    fake_mail = mailbox[:
                        insert_position] + f'+{generate_random_string()}' + mailbox[
                            insert_position:]
    logger.info(f'Email generated: {fake_mail}')
    return fake_mail
Beispiel #2
0
def driver(worker_id, request):
    logger.info(f'Starting driver for {worker_id}')
    ui_driver = driver_setup.Driver().start()
    factory.set_shared_driver(ui_driver)
    logger.info(f'Driver started for {worker_id}')

    yield ui_driver

    try:
        logger.info(f'Close driver for {worker_id}')
        ui_driver.quit()
        logger.info(f'Driver closed for {worker_id}')
    except WebDriverException:
        logger.info(f'Driver is already closed by exception interact hook')
Beispiel #3
0
def pytest_exception_interact(node, call, report):
    """Attach screenshot if test failed"""
    if report.failed:
        shutil.rmtree(TEST_REPORTS_DIR, ignore_errors=True)
        shutil.rmtree(os.path.join(TEST_REPORTS_DIR, 'screenshots'),
                      ignore_errors=True)
        os.makedirs(TEST_REPORTS_DIR)
        try:
            check_if_browser_log_has_errors()
            factory.get_shared_driver().save_screenshot(SCREEN_PATH)
            with open(SCREEN_PATH, 'rb') as screen:
                allure.attach(screen.read(), 'screen',
                              allure.attachment_type.PNG)

            factory.get_shared_driver().quit()
        except Exception:
            logger.info(
                f'failed to make screenshot for exception:\n{report.longrepr}')
Beispiel #4
0
def search_email_imap(user, fake_mail, func, **kwargs):
    tries = 0
    logger.info(f'Looking for mail in mailbox {user.login}')
    while True:
        with IMAPConnector(user) as connector:
            result, data = connector.search(None, "ALL")
            mails = data[0].split()
            id_list = mails[-20:] if len(mails) > 1 else [mails[-1]]
            for _id in id_list:
                result, data = connector.fetch(_id, "(RFC822)")
                received_email = email.message_from_string(data[0][1].decode("utf-8"))
                funk_res = func(fake_mail, received_email, **kwargs)
                if funk_res:
                    return funk_res
            if tries >= 5:
                raise AssertionError('Email was not received')
            else:
                tries += 1
                logger.info(f'Message was not received after {tries} attempt(s) for {func.__name__}')
                time.sleep(1)
Beispiel #5
0
 def wrapper(*args, **kwargs):
     result = func(*args, **kwargs)
     logger.info(f'REQUEST: {result.request.method}: {result.request.url}')
     if result.request.method == 'POST' or result.request.method == 'PUT':
         logger.info(f'REQUEST_DATA: {result.request.body}')
     if not result.ok:
         raise Exception(
             f'Error while api request: {result.status_code}":" {result.content}'
         )
     logger.info(f'CONTENT: {result.status_code}":" {result.content}')
     return result
Beispiel #6
0
def db_query_executor(db, queries, message):
    if isinstance(queries, str):
        queries = (queries, )
    with DbConnector(db) as conn:
        logger.info(f'{message} {db} started')
        for _query in queries:
            conn.cursor.execute(_query)
            try:
                result = conn.cursor.fetchone()
            except pyodbc.ProgrammingError as ex:
                logger.info(ex)
                result = None
            while conn.cursor.nextset():
                pass
            conn.cursor.commit()
        logger.info(f'{message} {db} finished')
        return result