Ejemplo n.º 1
0
def test_iplistresource_on_post_ok(client, superuser):
    json = {"name": "test-list"}
    resp = client.simulate_post(
        "/api/test/iplists", headers={"Authorization": f"Token {superuser}"}, json=json
    )
    assert resp.status_code == 201
    assert resp.json["status"] == "Success"
Ejemplo n.º 2
0
def test_user_on_post_is_admin_username_exists(client, superuser):
    u = create_user("test-user", "test-password")
    json = {"username": "******", "password": "******"}
    resp = client.simulate_post(
        "/api/test/users",
        headers={"Authorization": f"Token {superuser}"},
        json=json)
    assert resp.status_code == 400
Ejemplo n.º 3
0
def test_iplistresource_on_post_bad(client, superuser):
    ip_list = IPList(name="test-list", created_by=User.get_by_token(superuser))
    ip_list.save()
    json = {"name": "test-list"}
    resp = client.simulate_post(
        "/api/test/iplists", headers={"Authorization": f"Token {superuser}"}, json=json
    )
    assert resp.status_code == 400
Ejemplo n.º 4
0
def test_iplistitemresource_on_post_none_new(client, superuser):
    ip_list = IPList(name="test-list", created_by=User.get_by_token(superuser))
    ip_list.save()
    json = {"ips": ["1.1.1.1", "9.9.9.9"], "note": "test note"}
    resp = client.simulate_post(
        "/api/test/iplists/test-list/items",
        headers={"Authorization": f"Token {superuser}"},
        json=json,
    )
    resp = client.simulate_post(
        "/api/test/iplists/test-list/items",
        headers={"Authorization": f"Token {superuser}"},
        json=json,
    )
    assert resp.status_code == 200
    assert ListItem.select().count() == 2
    assert IPListItem.select().where((IPListItem.ip_list == ip_list)).count() == 2
Ejemplo n.º 5
0
def test_asn_post_ok(client, superuser):
    resp = client.simulate_post(
        "/api/test/asn",
        headers={"Authorization": f"Token {superuser}"},
        json={"ips": ["1.1.1.1"]},
    )
    assert resp.status_code == 200
    assert len(resp.json) == 1
Ejemplo n.º 6
0
def test_user_on_post_not_admin(client):
    u = create_user("test-user", "test-password")
    json = {
        "username": "******",
        "password": "******"
    }
    resp = client.simulate_post("/api/test/users",
                                headers={"Authorization": f"Token {u}"},
                                json=json)
    assert resp.status_code == 401
Ejemplo n.º 7
0
def test_user_on_post_is_admin(client, superuser):
    json = {
        "username": "******",
        "password": "******"
    }
    resp = client.simulate_post(
        "/api/test/users",
        headers={"Authorization": f"Token {superuser}"},
        json=json)
    assert resp.status_code == 201
    assert resp.json["status"] == "Success"
Ejemplo n.º 8
0
def test_iplistitemresource_on_post_notes(client, superuser):
    ip_list = IPList(name="test-list", created_by=User.get_by_token(superuser))
    ip_list.save()
    json = {"ips": ["1.1.1.1"], "note": "test note "}
    resp = client.simulate_post(
        "/api/test/iplists/test-list/items",
        headers={"Authorization": f"Token {superuser}"},
        json=json,
    )
    assert resp.status_code == 201
    ip = ListItem.get(ip="1.1.1.1")
    list_item = IPListItem.get(id=1)
    assert list_item.note == "test note"
Ejemplo n.º 9
0
def test_initresource_on_post_ok(client):
    json = {"username": "******", "password": "******"}
    resp = client.simulate_post("/api/test/init", json=json)
    assert resp.status_code == 201
    assert resp.json["status"] == "Success"
Ejemplo n.º 10
0
def test_initresource_on_post_bad(client, superuser):
    json = {"username": "******", "password": "******"}
    resp = client.simulate_post("/api/test/init", json=json)
    assert resp.status_code == 400