def test_wrong_import_id():
    import_id = -1
    server_api = get_server_api()
    response = requests.get(
        f"{server_api}{endpoint.format(import_id=import_id)}")
    assert response.status_code == 200
    assert response.json() == {"data": []}
Ejemplo n.º 2
0
def test_get_citizens(import_fixture):
    import_id = import_fixture
    server_api = get_server_api()
    response = requests.get(f"{server_api}{endpoint.format(import_id=import_id)}")

    assert response.status_code == 200
    assert response.json() == c.simple_stats_response
def test_wrong_cases(case_name, field, wrong_value):
    server_api = get_server_api()
    citizen_to_import = c.citizen_template.copy()
    citizen_to_import[field] = wrong_value
    data = {"citizens": [citizen_to_import]}
    response = requests.post(f"{server_api}/{endpoint}", json=data)
    assert response.status_code == 400
Ejemplo n.º 4
0
def test_use_access_token(superuser_token_headers) -> None:
    server_api = get_server_api()
    r = requests.post(
        f"{server_api}{settings.API_VERSION}/login/test-token",
        headers=superuser_token_headers,
    )
    result = r.json()
    assert r.status_code == 200
    assert "email" in result
Ejemplo n.º 5
0
def test_not_existent_user(import_fixture):
    import_id = import_fixture
    server_api = get_server_api()
    response = requests.patch(
        f"{server_api}{endpoint.format(import_id=import_id, citizen_id=69)}",
        json=c.update_data,
    )
    assert response.status_code == 404
    assert response.json() == {"detail": "Item not found"}
def test_get_citizens(import_fixture):
    import_id = import_fixture
    server_api = get_server_api()
    response = requests.get(
        f"{server_api}{endpoint.format(import_id=import_id)}")

    assert response.status_code == 200

    gotten_citizens = response.json()["data"]
    assert len(gotten_citizens) == 3
    assert gotten_citizens == import_c.simple_import_data["citizens"]
Ejemplo n.º 7
0
def test_wrong_cases(case_name, field, wrong_value, import_fixture):
    import_id = import_fixture
    server_api = get_server_api()
    citizen_to_update = c.update_data.copy()
    citizen_to_update[field] = wrong_value
    response = requests.patch(
        f"{server_api}{endpoint.format(import_id=import_id, citizen_id=3)}",
        json=citizen_to_update,
    )

    assert response.status_code == 400
Ejemplo n.º 8
0
def test_base_update(import_fixture):
    import_id = import_fixture
    server_api = get_server_api()
    response = requests.patch(
        f"{server_api}{endpoint.format(import_id=import_id, citizen_id=3)}",
        json=c.update_data,
    )

    citizen_after_update_template = import_c.simple_import_data["citizens"][
        2].copy()
    citizen_after_update_template.update(c.update_data)

    assert response.status_code == 200
    assert response.json()["data"] == citizen_after_update_template
Ejemplo n.º 9
0
def test_get_access_token() -> None:
    server_api = get_server_api()
    login_url = f"{server_api}{settings.API_VERSION}/login/access-token"
    login_data = {
        "username": settings.FIRST_ADMIN_USER,
        "password": settings.FIRST_ADMIN_PASSWORD,
    }

    r = requests.post(login_url, data=login_data)
    assert r.status_code == 200
    assert r.text is not None and r.text != ''

    tokens = r.json()
    assert "access_token" in tokens
    assert tokens["access_token"]
def import_citizens(import_data: dict) -> int:
    server_api = get_server_api()
    response = requests.post(f"{server_api}/imports", json=import_data)
    return response.json()["data"]["import_id"]
def test_base_import():
    server_api = get_server_api()
    response = requests.post(f"{server_api}/{endpoint}", json=c.simple_import_data)
    assert response.status_code == 200
    assert response.json() == {"data": {"import_id": IntValue()}}
Ejemplo n.º 12
0
def server_api():
    return get_server_api()