Esempio n. 1
0
def test_user():
    test_user_email = "test_" + str(int(time.time())) + "@example.com"
    test_user_pass = "******"

    test_user = User.register_new_user(email=test_user_email,
                                       password=test_user_pass)

    yield (test_user_email, test_user_pass, test_user.generate_auth_token(),
           test_user.meta.id)

    # After this test user has been used, delete him
    test_user.delete()
Esempio n. 2
0
def user_register():
    """
    This route handles user registration.

    Pre-conditions:
    - The POST request should contain the user's (valid) email and password.

    Post-conditions:
    - This route will create the user's account & return an authentication token
      that the front-end should include in all future requests
      (in order to authenticate the user in the backend).

    Sample responses:

    success (HTTP status 200):
    {
        "success" : true,
        "auth_token" : "<some auth token>"
    }

    failure (HTTP status 400):
    {
        "success" : false,
        "error" : "<some error message>"
    }

    :return:    A JSON response with the user's auth token
    """
    data = request.get_json(force=True)
    email = data['email']
    password = data['password']

    # Check if the email is valid.
    if not is_email_valid(email=email):
        return jsonify(success=False, error="Invalid email."), 400

    # Check if the password is valid.
    if not is_password_valid(password=password):
        return jsonify(success=False, error="Invalid password."), 400

    # We have a valid email & password, so let's register a new user.
    try:
        new_user = User.register_new_user(email=email, password=password)

        # Generate an auth token for this new user
        auth_token = new_user.generate_auth_token()

        return jsonify(success=True, auth_token=auth_token)
    except ValueError as e:
        return jsonify(success=False, error=str(e)), 400
Esempio n. 3
0
test_user1_pass = "******"

# Populated test user
test_user2_email = "*****@*****.**"
test_user2_pass = "******"

# Delete any existing test users
print("Deleting any existing test users...")
User.delete_by_email(test_user1_email)
User.delete_by_email(test_user2_email)

time.sleep(2)

# Register these 2 test users
print("Registering 2 test users...")
test_user1 = User.register_new_user(email=test_user1_email,
                                    password=test_user1_pass)
test_user2 = User.register_new_user(email=test_user2_email,
                                    password=test_user2_pass)

random_transcription_blobs = [
    transcription_blob
    for transcription_blob in PodcastTranscriptionBlob.search().query(
        "match_all").extra(collapse={"field": "podcast_id"})[:20]
]

# Add favorites for test user 2
print("Adding favorites for test user 2...")
favorite_podcast_blobs = random_transcription_blobs[:3]
test_favorite_podcasts = [{
    "podcast_id": transcription_blob.podcast_id,
    "blob_id": transcription_blob.meta.id