Exemple #1
0
def test_download_list_pagination(page, limit, expected_limit, total_pages,
                                  status):
    # GIVEN
    create_file_list(db, in_progress_count=10, completed_count=10)

    # WHEN
    if limit is None:
        resp = client.get("/api/downloads?page={}".format(page))
    elif page is None:
        resp = client.get("/api/downloads?limit={}".format(limit))
    else:
        resp = client.get("/api/downloads?page={}&limit={}".format(
            page, limit))

    # THEN
    assert resp.status == "200 OK", resp.get_json()
    assert resp.mimetype == "application/json"

    json_resp = resp.get_json()
    assert "downloads" in json_resp

    assert len(json_resp["downloads"]) == expected_limit
    assert all(
        [download["status"] == status for download in json_resp["downloads"]])

    assert "totalPages" in json_resp
    assert json_resp["totalPages"] == total_pages
def test_index():
    # WHEN
    resp = client.get("/")

    # THEN
    assert resp.status == "200 OK", resp.get_json()
    assert resp.mimetype == "text/html"
    assert "<html>" in str(resp.get_data())
Exemple #3
0
def test_get_settings_loads_missing_settings():
    # GIVEN
    reset_db(db)

    # WHEN
    resp = client.get("/api/settings")

    # THEN
    assert resp.status == "200 OK", resp.get_json()
    assert resp.mimetype == "application/json"

    assert resp.get_json() == {"settings": {"downloadDirectory": "/downloads"}}
Exemple #4
0
def test_get_settings_loads_db_settings():
    # GIVEN
    reset_db(db)
    create_new_setting(db, "downloadDirectory", "/testing")

    # WHEN
    resp = client.get("/api/settings")

    # THEN
    assert resp.status == "200 OK", resp.get_json()
    assert resp.mimetype == "application/json"

    assert resp.get_json() == {"settings": {"downloadDirectory": "/testing"}}
Exemple #5
0
def test_download_list_status_filter(filters):
    # GIVEN
    create_file_list(db, in_progress_count=5, completed_count=5)
    param = ",".join(filters)

    # WHEN
    resp = client.get("/api/downloads?status={}".format(param))

    # THEN
    assert resp.status == "200 OK", resp.get_json()
    assert resp.mimetype == "application/json"

    json_resp = resp.get_json()
    assert "downloads" in json_resp

    assert len(json_resp["downloads"]) == 5
    assert all(download["status"] in filters
               for download in json_resp["downloads"])
Exemple #6
0
def test_get_download_not_found():
    # WHEN
    resp = client.get("/api/downloads/9999")

    # THEN
    assert resp.status == "404 NOT FOUND"