def test_metric_type_name():
    event = metrics.Event(
        type="event",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
        extra_keys={"my_extra": {
            "description": "an extra"
        }},
    )

    assert kotlin.type_name(event) == "EventMetricType<metricKeys>"

    event = metrics.Event(
        type="event",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
    )

    assert kotlin.type_name(event) == "EventMetricType<NoExtraKeys>"

    boolean = metrics.Boolean(
        type="boolean",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
    )
    assert kotlin.type_name(boolean) == "BooleanMetricType"

    ping = pings.Ping(
        name="custom",
        description="description...",
        include_client_id=True,
        bugs=[42],
        notification_emails=["*****@*****.**"],
    )
    assert kotlin.type_name(ping) == "PingType<NoReasonCodes>"

    ping = pings.Ping(
        name="custom",
        description="description...",
        include_client_id=True,
        bugs=[42],
        notification_emails=["*****@*****.**"],
        reasons={
            "foo": "foolicious",
            "bar": "barlicious"
        },
    )
    assert kotlin.type_name(ping) == "PingType<customReasonCodes>"
Exemple #2
0
def test_ping_desc():
    # Make sure to return something for built-in pings.
    for ping_name in pings.RESERVED_PING_NAMES:
        assert len(markdown.ping_desc(ping_name)) > 0

    # We don't expect nothing for unknown pings.
    assert len(markdown.ping_desc("unknown-ping")) == 0

    # If we have a custom ping cache, try look up the
    # description there.
    cache = {}
    cache["cached-ping"] = pings.Ping(
        name="cached-ping",
        description="the description for the custom ping\n with a surprise",
        bugs=["1234"],
        notification_emails=["*****@*****.**"],
        data_reviews=["https://www.example.com/review"],
        include_client_id=False,
    )

    assert (markdown.ping_desc(
        "cached-ping",
        cache) == "the description for the custom ping\n with a surprise")

    # We don't expect nothing for unknown pings, even with caches.
    assert len(markdown.ping_desc("unknown-ping", cache)) == 0
Exemple #3
0
def test_metric_type_name():
    # TODO: Events are not yet supported.
    # event = metrics.Event(
    #     type="event",
    #     category="category",
    #     name="metric",
    #     bugs=[42],
    #     notification_emails=["*****@*****.**"],
    #     description="description...",
    #     expires="never",
    #     extra_keys={"my_extra": {"description": "an extra"}},
    # )

    # assert swift.type_name(event) == "EventMetricType<metricKeys>"

    # event = metrics.Event(
    #     type="event",
    #     category="category",
    #     name="metric",
    #     bugs=[42],
    #     notification_emails=["*****@*****.**"],
    #     description="description...",
    #     expires="never",
    # )

    # assert swift.type_name(event) == "EventMetricType<noExtraKeys>"

    boolean = metrics.Boolean(
        type="boolean",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
    )
    assert swift.type_name(boolean) == "BooleanMetricType"

    ping = pings.Ping(
        name="custom",
        description="description...",
        include_client_id=True,
        bugs=[42],
        notification_emails=["*****@*****.**"],
    )
    assert swift.type_name(ping) == "Ping"