Beispiel #1
0
def test_get_authors(conn):
    user1 = user.User(0, "user1", "*****@*****.**", "")
    user2 = user.User(0, "user2", "*****@*****.**", "")
    user3 = user.User(0, "user3", "*****@*****.**", "")

    try:
        user.create(conn, user1.username, user1.email, "password", "")
        user.create(conn, user2.username, user2.email, "password", "")
        user.create(conn, user3.username, user3.email, "password", "")

        user1 = user.get_by_email(conn, user1.email)
        user2 = user.get_by_email(conn, user2.email)
        user3 = user.get_by_email(conn, user3.email)

        subscription.subscribe(conn, user1.id, user2.id)
        subscription.subscribe(conn, user1.id, user3.id)
        conn.commit()

        authors = subscription.get_authors(conn, user1.id)
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)

    assert "user2" in authors
    assert "user3" in authors
    assert "user1" not in authors
Beispiel #2
0
def test_get_authors_and_posts(conn):
    user1 = user.User(0, "user1", "*****@*****.**", "")
    user2 = user.User(0, "user2", "*****@*****.**", "")

    try:
        user.create(conn, user1.username, user1.email, "password", "")
        user.create(conn, user2.username, user2.email, "password", "")

        user1 = user.get_by_email(conn, user1.email)
        user2 = user.get_by_email(conn, user2.email)

        post_service.create(conn, user2.id, "first post", "content")
        post_service.create(conn, user2.id, "second post", "content")

        subscription.subscribe(conn, user1.id, user2.id)
        conn.commit()

        subscriptions = subscription.get_authors_and_posts(conn, user1.id)
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)

    for sub in subscriptions:
        assert sub.author == user2.username
        for p in sub.posts:
            assert p.author == user2.username
            assert p.title in ["first post", "second post"]
            assert p.content == "content"
Beispiel #3
0
def test_subscribe_to_author(conn):
    email1 = "*****@*****.**"
    email2 = "*****@*****.**"

    try:
        user.create(conn, email1, email1, "password", "")
        user.create(conn, email2, email2, "password", "")

        user1 = user.get_by_email(conn, email1)
        user2 = user.get_by_email(conn, email2)

        conn.commit()
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)

    subscription.subscribe(conn, user1.id, user2.id)
Beispiel #4
0
def test_get_user_by_email(conn):
    email = "*****@*****.**"

    cursor = conn.cursor()
    try:
        cursor.execute("INSERT INTO users (email) VALUES (%s)", (email, ))
        conn.commit()
        cursor.close()
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)

    u = user.get_by_email(conn, email)

    assert u.email == email
Beispiel #5
0
def test_create_new_account(conn):
    username = "******"
    email = "*****@*****.**"
    password = "******"
    profile_text = "lorem ipsum"

    try:
        user.create(conn, username, email, password, profile_text)
        conn.commit()
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)

    u = user.get_by_email(conn, email)

    assert u.username == username
    assert u.email == email
    assert u.profile_text == profile_text
Beispiel #6
0
def test_create_user(conn):
    username = "******"
    email = "*****@*****.**"
    password = "******"
    password_repeat = password
    profile_text = "lorem ipsum"

    try:
        user_service.create(conn, username, email, password, password_repeat,
                            profile_text)
        conn.commit()
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)
    except PasswordsDoNotMatch as e:
        pytest.fail(e)

    u = user_postgres.get_by_email(conn, email)

    assert u.username == username
    assert u.email == email
    assert u.profile_text == profile_text
Beispiel #7
0
def test_get_nonexisting_user_by_email(conn):
    email = "*****@*****.**"

    with pytest.raises(UserNotFoundError):
        user.get_by_email(conn, email)