def test_assets_page_nonempty(db, client, requests_mock, as_prosumer, use_owned_by):
    mock_assets = mock_asset_response(multiple=True)
    requests_mock.get(
        "http://localhost//api/v2_0/assets", status_code=200, json=mock_assets
    )
    if use_owned_by:
        asset_index = client.get(
            url_for("AssetCrudUI:owned_by", owner_id=mock_assets[0]["owner_id"])
        )
    else:
        asset_index = client.get(url_for("AssetCrudUI:index"))
    for asset in mock_assets:
        assert asset["display_name"].encode() in asset_index.data
Exemple #2
0
def test_assets_page_nonempty(db, client, requests_mock, as_prosumer_user1,
                              use_owned_by):
    mock_assets = mock_asset_response(multiple=True)
    requests_mock.get(f"{api_path_assets}?account_id=1",
                      status_code=200,
                      json=mock_assets)
    if use_owned_by:
        asset_index = client.get(
            url_for("AssetCrudUI:owned_by",
                    account_id=mock_assets[0]["account_id"]))
    else:
        asset_index = client.get(url_for("AssetCrudUI:index"))
    for asset in mock_assets:
        assert asset["name"].encode() in asset_index.data
def test_edit_asset(db, client, requests_mock, as_admin):
    mock_asset = mock_asset_response(as_list=False)
    requests_mock.patch("http://localhost//api/v2_0/asset/1",
                        status_code=200,
                        json=mock_asset)
    response = client.post(
        url_for("AssetCrudUI:post", id=1),
        follow_redirects=True,
        data=mock_api_data_as_form_input(mock_asset),
    )
    assert response.status_code == 200
    assert b"Editing was successful" in response.data
    assert mock_asset["display_name"] in str(response.data)
    assert str(mock_asset["latitude"]) in str(response.data)
    assert str(mock_asset["longitude"]) in str(response.data)
Exemple #4
0
def test_add_asset(db, client, setup_assets, requests_mock, as_admin):
    """Add a new asset"""
    user = find_user_by_email("*****@*****.**")
    mock_asset = mock_asset_response(account_id=user.account.id, as_list=False)
    requests_mock.post(api_path_assets, status_code=201, json=mock_asset)
    response = client.post(
        url_for("AssetCrudUI:post", id="create"),
        follow_redirects=True,
        data=mock_api_data_as_form_input(mock_asset),
    )
    assert response.status_code == 200  # response is HTML form
    assert "html" in response.content_type
    assert b"Creation was successful" in response.data
    assert mock_asset["name"] in str(response.data)
    assert str(mock_asset["latitude"]) in str(response.data)
    assert str(mock_asset["longitude"]) in str(response.data)
def test_add_asset_with_new_owner(client, requests_mock, as_admin):
    """Test roundtrip and expect new user (new owner) in db"""
    mock_asset = mock_asset_response(owner_id=-1, as_list=False)
    requests_mock.post("http://localhost//api/v2_0/assets",
                       status_code=201,
                       json=mock_asset)
    new_user_email = "*****@*****.**"
    data = copy.deepcopy(mock_asset)
    data["new_owner_email"] = new_user_email
    response = client.post(
        url_for("AssetCrudUI:post", id="create"),
        follow_redirects=True,
        data=mock_api_data_as_form_input(data),
    )
    assert response.status_code == 200
    assert b"Creation was successful" in response.data
    assert find_user_by_email(new_user_email)
Exemple #6
0
def test_asset_page(db, client, setup_assets, requests_mock,
                    as_prosumer_user1):
    user = find_user_by_email("*****@*****.**")
    asset = user.assets[0]
    db.session.expunge(user)
    mock_asset = mock_asset_response(as_list=False)
    mock_asset["latitude"] = asset.latitude
    mock_asset["longitude"] = asset.longitude

    requests_mock.get(f"{api_path_assets}/{asset.id}",
                      status_code=200,
                      json=mock_asset)
    asset_page = client.get(url_for("AssetCrudUI:get", id=asset.id),
                            follow_redirects=True)
    assert ("Edit asset %s" % mock_asset["name"]).encode() in asset_page.data
    assert str(mock_asset["latitude"]).encode() in asset_page.data
    assert str(mock_asset["longitude"]).encode() in asset_page.data
def test_asset_page(db, client, requests_mock, as_prosumer):
    prosumer = find_user_by_email("*****@*****.**")
    asset = prosumer.assets[0]
    db.session.expunge(prosumer)
    mock_asset = mock_asset_response(as_list=False)
    mock_asset["capacity_in_mw"] = asset.capacity_in_mw
    mock_asset["latitude"] = asset.latitude
    mock_asset["longitude"] = asset.longitude

    requests_mock.get(f"http://localhost//api/v2_0/asset/{asset.id}",
                      status_code=200,
                      json=mock_asset)
    asset_page = client.get(url_for("AssetCrudUI:get", id=asset.id),
                            follow_redirects=True)
    assert ("Edit asset %s" %
            mock_asset["display_name"]).encode() in asset_page.data
    assert str(mock_asset["capacity_in_mw"]).encode() in asset_page.data
    assert str(mock_asset["latitude"]).encode() in asset_page.data
    assert str(mock_asset["longitude"]).encode() in asset_page.data