예제 #1
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"
예제 #2
0
def test_get_authors_without_subscriptions(conn):
    user1 = user.User(0, "user1", "*****@*****.**", "")

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

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

    assert len(authors) == 0
예제 #3
0
def test_update_user_password(conn):
    email = "*****@*****.**"
    new_password = "******"

    try:
        user_postgres.create(conn, "x", email, "x", "x")
        user_service.update_password(conn, email, new_password)
        conn.commit()
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)

    assert user_postgres.check_password(conn, email, new_password)
예제 #4
0
def test_create_new_account_and_password_is_encrypted(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)

    assert user.check_password(conn, email, password)
예제 #5
0
def test_view_profile(conn):
    username = "******"
    email = "*****@*****.**"
    profile_text = "lorem ipsum ::"
    try:
        user_postgres.create(conn, username, email, "x", profile_text)
        conn.commit()
    except DataError as e:
        pytest.fail(e)
    except DatabaseError as e:
        pytest.fail(e)

    u = user_service.get_profile(conn, username)

    assert u.username == username
    assert u.email == email
    assert u.profile_text == profile_text
예제 #6
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)
예제 #7
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
예제 #8
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
예제 #9
0
def create(conn, username, email, password, password_repeat, profile_text):
    if password != password_repeat:
        raise PasswordsDoNotMatch
    if not email_is_valid(email):
        raise InvalidEmail
    user.create(conn, username, email, password, profile_text)