Esempio n. 1
0
async def test_fetch_placement(manager: ServiceLifecycleManager,
                               connection: Connection, snapshot_endpoint):
    topic = topics.MANO_PLACE

    # Should send placement request that matches snapshot
    with snapshot_endpoint(
            topic,
        {"mapping": PLACEMENT},
            matcher=path_type(mapping={
                "functions": (list, ),
                "nsd": (dict, )
            },
                              strict=True),
    ):
        await manager._fetch_placement(topology=[])

    # Should store the placement in the Service document and its Function documents
    assert PLACEMENT == manager.service.placement
    for function in manager.service.functions:
        assert str(function.vim) == VIM_ID

    # Should raise PlacementError if the returned mapping is ``None``
    with simple_async_endpoint(connection, topic, {"mapping": None}):
        with pytest.raises(PlacementError):
            await manager._fetch_placement(topology=[])
Esempio n. 2
0
async def test_deploy_vnf(
    manager: ServiceLifecycleManager,
    connection: Connection,
    fetched_placement,
    snapshot_endpoint,
):
    topic = topics.MANO_DEPLOY
    function = manager.service.functions[0]

    # Should send requests that match their snapshots
    with snapshot_endpoint(
            topic,
            response={
                "request_status": "COMPLETED",
                "vnfr": {
                    "key": "value"
                }
            },
            matcher=path_type(mapping={"vnfd": (dict, )}, strict=True),
    ):
        await manager._deploy_vnf(function)

    # Should raise errors from the IA
    with simple_async_endpoint(connection, topic, {
            "request_status": "ERROR",
            "message": "failed"
    }):
        with pytest.raises(InstantiationError, match="failed"):
            await manager._deploy_vnf(function)
Esempio n. 3
0
def test_matches_regex_in_regex_mode(snapshot):
    my_matcher = path_type(
        {
            r"data\.list\..*\.date_created": (datetime.datetime, ),
            r"any_number": (int, ),
        },
        regex=True,
    )
    actual = {
        "data": {
            "list": [
                {
                    "k": "1",
                    "date_created": datetime.datetime.now()
                },
                {
                    "k": "2",
                    "date_created": datetime.datetime.now()
                },
            ],
        },
        "any_number": 3,
        "any_number_adjacent": "hi",
        "specific_number": 5,
    }
    assert actual == snapshot(matcher=my_matcher)
Esempio n. 4
0
def test_raises_unexpected_type(snapshot):
    kwargs = {
        "mapping": {
            "date_created": (datetime.datetime, ),
            "date_updated": (datetime.datetime, ),
            "nested.id": (str, ),
        },
        "types": (uuid.UUID, int),
    }
    actual = {
        "date_created": datetime.datetime.now(),
        "date_updated": datetime.date(2020, 6, 1),
        "nested": {
            "id": 4
        },
        "some_uuid": uuid.uuid4(),
    }
    assert actual == snapshot(matcher=path_type(**kwargs, strict=False))
    with pytest.raises(AssertionError,
                       match="does not match any of the expected"):
        assert actual == snapshot(matcher=path_type(**kwargs))
Esempio n. 5
0
def test_matches_expected_type(snapshot):
    my_matcher = path_type(
        {
            "date_created": (datetime.datetime, ),
            "nested.id": (int, )
        },
        types=(uuid.UUID, ))
    actual = {
        "date_created": datetime.datetime.now(),
        "nested": {
            "id": 4
        },
        "some_uuid": uuid.uuid4(),
    }
    assert actual == snapshot(matcher=my_matcher)
Esempio n. 6
0
def test_matcher(snapshot_json):
    content = {
        "int": random.randint(1, 100),
        "date": datetime.datetime.utcnow(),
        "foo": {
            "x": "y",
            "another_date": datetime.datetime.utcnow(),
        },
    }
    matcher = path_type({
        "int": (int, ),
        "date": (datetime.date, ),
        "foo.another_date": (dict, datetime.datetime),
    })
    assert snapshot_json(matcher=matcher) == content
Esempio n. 7
0
def test_matcher_path_type_noop(snapshot):
    with pytest.raises(PathTypeError, match="argument cannot be empty"):
        path_type()