def test_password_validation(): # Test min length for password __check_fails(lambda: create_new_account(gen_random_chars(10), gen_random_chars(10) + '@test.nu', gen_random_chars(3))) # Test max length for password __check_fails(lambda: create_new_account(gen_random_chars(10), gen_random_chars(10) + '@test.nu', 'a' * 500))
def test_reset_password(user, env): reset_password_request(user) sent_time = int(time.time()) time_epsilon = 15 # Encapsulate in an Email class if env == 'local': # Initial wait for email to get sent time.sleep(1) attempts = 0 email_found = None while True: attempts += 1 assert attempts <= 3, \ 'No reset password email found with correct content' emails = get_emails_from_local_inbox(user.username, 'reset_password') # No emails with correct type and user if not emails: time.sleep(3) continue latest_email = emails[0] ts = int(latest_email.split('_')[0]) # Too old email to be considered if ts > (sent_time + time_epsilon) or \ ts < (sent_time - time_epsilon): time.sleep(3) continue parsed = read_local_email(latest_email) if user.username in parsed: email_found = parsed break # Wait a bit for results to come in time.sleep(3) user_id, token = get_verification_token(email_found) new_password = gen_random_chars(20) verify_password_reset(user, token, new_password) user.password = new_password user.login() else: # TODO: Check cloud database for email # each 'test' email is copied to a DB in GCP pass
def test_username_validation(): # Check too long username __check_fails(lambda: create_new_account(gen_random_chars(100), gen_random_chars(10) + '@test.nu', gen_random_chars(30))) # Test max length for password __check_fails(lambda: create_new_account('[][]-()2312dsaz...>>>//', gen_random_chars(10) + '@test.nu', gen_random_chars(30))) # Test profanity filter doing basic validation __check_fails(lambda: create_new_account('penis', gen_random_chars(10) + '@test.nu', gen_random_chars(30)))
def test_check_username(user): assert check_username_available(user.username, user.url) is False # Make sure validation is happening assert check_username_available('asd', user.url) is False assert check_username_available(gen_random_chars(20), user.url)
def test_email_validation(user): __check_fails(lambda: create_new_account(gen_random_chars(20), user.email, gen_random_chars(12)))
def test_username_duplication_validation(user): __check_fails(lambda: create_new_account(user.username, gen_random_chars(10) + '@test.nu', gen_random_chars(12)))
def test_password() -> Text: return gen_random_chars(30)
def test_email() -> Text: return 'test_user_' + gen_random_chars(14) + '@test.nu'
def test_username() -> Text: return 'test_user_' + gen_random_chars(14)