Пример #1
0
def test_archdev_navbar_authenticated_tu(client: TestClient,
                                         trusted_user: User):
    expected = [
        "Dashboard", "Packages", "Requests", "Accounts", "My Account",
        "Trusted User", "Logout"
    ]
    cookies = {"AURSID": trusted_user.login(Request(), "testPassword")}
    with client as request:
        resp = request.get("/", cookies=cookies)
    assert resp.status_code == int(HTTPStatus.OK)

    root = parse_root(resp.text)
    items = root.xpath('//div[@id="archdev-navbar"]/ul/li/a')
    for i, item in enumerate(items):
        assert item.text.strip() == expected[i]
Пример #2
0
def test_user_language(client: TestClient, user: User):
    """ Test the language post route as an authenticated user. """
    post_data = {
        "set_lang": "de",
        "next": "/"
    }

    sid = user.login(Request(), "testPassword")
    assert sid is not None

    with client as req:
        response = req.post("/language", data=post_data,
                            cookies={"AURSID": sid})
    assert response.status_code == int(HTTPStatus.SEE_OTHER)
    assert user.LangPreference == "de"
def test_tu_addvote_post_cant_duplicate_username(client: TestClient,
                                                 tu_user: User, user: User):
    cookies = {"AURSID": tu_user.login(Request(), "testPassword")}

    data = {"user": user.Username, "type": "add_tu", "agenda": "Blah"}

    with client as request:
        response = request.post("/addvote", cookies=cookies, data=data)
    assert response.status_code == int(HTTPStatus.SEE_OTHER)

    voteinfo = db.query(TUVoteInfo, TUVoteInfo.Agenda == "Blah").first()
    assert voteinfo is not None

    with client as request:
        response = request.post("/addvote", cookies=cookies, data=data)
    assert response.status_code == int(HTTPStatus.BAD_REQUEST)
def test_tu_addvote_unauthorized(client: TestClient, user: User,
                                 proposal: Tuple[User, User, TUVoteInfo]):
    cookies = {"AURSID": user.login(Request(), "testPassword")}
    with client as request:
        response = request.get("/addvote",
                               cookies=cookies,
                               allow_redirects=False)
    assert response.status_code == int(HTTPStatus.SEE_OTHER)
    assert response.headers.get("location") == "/tu"

    with client as request:
        response = request.post("/addvote",
                                cookies=cookies,
                                allow_redirects=False)
    assert response.status_code == int(HTTPStatus.SEE_OTHER)
    assert response.headers.get("location") == "/tu"
def test_tu_proposal_unauthorized(client: TestClient, user: User,
                                  proposal: Tuple[User, User, TUVoteInfo]):
    cookies = {"AURSID": user.login(Request(), "testPassword")}
    endpoint = f"/tu/{proposal[2].ID}"
    with client as request:
        response = request.get(endpoint,
                               cookies=cookies,
                               allow_redirects=False)
    assert response.status_code == int(HTTPStatus.SEE_OTHER)
    assert response.headers.get("location") == "/tu"

    with client as request:
        response = request.post(endpoint,
                                cookies=cookies,
                                data={"decision": False},
                                allow_redirects=False)
    assert response.status_code == int(HTTPStatus.SEE_OTHER)
    assert response.headers.get("location") == "/tu"
def test_tu_index_last_votes(client: TestClient, tu_user: User, tu_user2: User,
                             user: User):
    ts = time.utcnow()

    with db.begin():
        # Create a proposal which has ended.
        voteinfo = db.create(TUVoteInfo,
                             Agenda="Test agenda",
                             User=user.Username,
                             Submitted=(ts - 1000),
                             End=(ts - 5),
                             Yes=1,
                             No=1,
                             ActiveTUs=1,
                             Quorum=0.0,
                             Submitter=tu_user)

        # Create a vote on it from tu_user.
        db.create(TUVote, VoteInfo=voteinfo, User=tu_user)
        db.create(TUVote, VoteInfo=voteinfo, User=tu_user2)

    # Now, check that tu_user got populated in the .last-votes table.
    cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
    with client as request:
        response = request.get("/tu", cookies=cookies)
    assert response.status_code == int(HTTPStatus.OK)

    root = parse_root(response.text)
    table = get_table(root, "last-votes")
    rows = get_table_rows(table)
    assert len(rows) == 2

    last_vote = rows[0]
    user, vote_id = last_vote.xpath("./td/a")
    assert user.text.strip() == tu_user.Username
    assert int(vote_id.text.strip()) == voteinfo.ID

    last_vote = rows[1]
    user, vote_id = last_vote.xpath("./td/a")
    assert int(vote_id.text.strip()) == voteinfo.ID
    assert user.text.strip() == tu_user2.Username
def test_tu_stats(client: TestClient, tu_user: User):
    cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
    with client as request:
        response = request.get("/tu", cookies=cookies, allow_redirects=False)
    assert response.status_code == HTTPStatus.OK

    root = parse_root(response.text)
    stats = root.xpath('//table[@class="no-width"]')[0]
    rows = stats.xpath("./tbody/tr")

    # We have one trusted user.
    total = rows[0]
    label, count = total.xpath("./td")
    assert int(count.text.strip()) == 1

    # And we have one active TU.
    active = rows[1]
    label, count = active.xpath("./td")
    assert int(count.text.strip()) == 1

    with db.begin():
        tu_user.InactivityTS = time.utcnow()

    with client as request:
        response = request.get("/tu", cookies=cookies, allow_redirects=False)
    assert response.status_code == HTTPStatus.OK

    root = parse_root(response.text)
    stats = root.xpath('//table[@class="no-width"]')[0]
    rows = stats.xpath("./tbody/tr")

    # We have one trusted user.
    total = rows[0]
    label, count = total.xpath("./td")
    assert int(count.text.strip()) == 1

    # But we have no more active TUs.
    active = rows[1]
    label, count = active.xpath("./td")
    assert int(count.text.strip()) == 0
Пример #8
0
def test_user_login_suspended(user: User):
    with db.begin():
        user.Suspended = True
    assert not user.login(Request(), "testPassword")
Пример #9
0
def test_user_login_twice(user: User):
    request = Request()
    assert user.login(request, "testPassword")
    assert user.login(request, "testPassword")
def test_tu_addvote_post_invalid_username(client: TestClient, tu_user: User):
    cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
    data = {"user": "******"}
    with client as request:
        response = request.post("/addvote", cookies=cookies, data=data)
    assert response.status_code == int(HTTPStatus.NOT_FOUND)
def test_tu_addvote(client: TestClient, tu_user: User):
    cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
    with client as request:
        response = request.get("/addvote", cookies=cookies)
    assert response.status_code == int(HTTPStatus.OK)