def create_account(db_session, email, password): provider = provider_from_address(email) auth_handler = handler_from_email(email) # Special-case Gmail and Outlook, because we need to provide an oauth token # and not merely a password. if provider == 'gmail': token = google_auth(email, password) account = create_gmail_account(db_session, email, token, False) elif provider == 'outlook': token = outlook_auth(email, password) account = create_outlook_account(db_session, email, token, False) else: response = {"email": email, "password": password} account = auth_handler.create_account(db_session, email, response) auth_handler.verify_account(account) db_session.add(account) db_session.commit()
def create_account(db_session, email, password): provider = provider_from_address(email) auth_handler = handler_from_email(email) # Special-case Gmail and Outlook, because we need to provide an oauth token # and not merely a password. if provider == 'gmail': token = google_auth(email, password) account = create_gmail_account(db_session, email, token, False) elif provider == 'outlook': token = outlook_auth(email, password) account = create_outlook_account(db_session, email, token, False) else: response = {"email": email, "password": password} account = auth_handler.create_account(db_session, email, response) auth_handler.verify_account(account) db_session.add(account) db_session.commit() return account
def test_password_auth(email, password): response = {"email": email, "password": password} with session_scope() as db_session: auth_handler = handler_from_email(email) account = create_account(db_session, email, response) if auth_handler.verify_account(account): db_session.add(account) db_session.commit() db_session.commit() start_time = time.time() # Check that the account exists while time.time() - start_time < TEST_MAX_DURATION_SECS: client = APIClient.from_email(email) if client is not None: break time.sleep(TEST_GRANULARITY_CHECK_SECS) if client is None: assert False, "Account namespace should have been created" # Now, compute how much time it takes to start syncing the account start_time = time.time() got_messages = False while time.time() - start_time < TEST_MAX_DURATION_SECS: messages = client.get_messages() if len(messages) != 0: got_messages = True break time.sleep(TEST_GRANULARITY_CHECK_SECS) assert got_messages, "Messages should have been found" print "test_password_auth %s %f" % (email, time.time() - start_time) # remove the account with session_scope() as db_session: # remove_account(db_session, email) pass
def test_password_auth(email, password): with session_scope() as db_session: auth_handler = handler_from_email(email) account = create_account(db_session, email, password) if auth_handler.verify_account(account): db_session.add(account) db_session.commit() start_time = time.time() # Check that the account exists while time.time() - start_time < TEST_MAX_DURATION_SECS: client = APIClient.from_email(email)[0] if client is not None: break time.sleep(TEST_GRANULARITY_CHECK_SECS) if client is None: assert False, "Account namespace should have been created" # Now, compute how much time it takes to start syncing the account start_time = time.time() got_messages = False while time.time() - start_time < TEST_MAX_DURATION_SECS: messages = client.get_messages() if len(messages) != 0: got_messages = True break time.sleep(TEST_GRANULARITY_CHECK_SECS) assert got_messages, "Messages should have been found" print "test_password_auth %s %f" % (email, time.time() - start_time) # remove the account with session_scope() as db_session: delete_account(db_session, email)