def test_isodate():
    """
    Test that expires_after_build_date is parsed into a datetime.
    """
    m = metrics.Boolean(
        type='boolean',
        category='category',
        name='metric',
        bugs=[42],
        expires_after_build_date='2018-06-10',
        notification_emails=['*****@*****.**'],
        description='description...',
    )
    assert isinstance(m.expires_after_build_date, datetime.date)

    with pytest.raises(ValueError):
        m = metrics.Boolean(
            type='boolean',
            category='category',
            name='metric',
            bugs=[42],
            expires_after_build_date='foo',
            notification_emails=['*****@*****.**'],
            description='description...',
        )
def test_expires():
    """
    Test that expires is parsed correctly
    """
    for date, expired in [
        ("2018-06-10", True),
        (datetime.datetime.utcnow().date().isoformat(), True),
        ("3000-01-01", False),
    ]:
        m = metrics.Boolean(
            type="boolean",
            category="category",
            name="metric",
            bugs=[42],
            expires=date,
            notification_emails=["*****@*****.**"],
            description="description...",
        )
        assert m.is_expired() == expired

    with pytest.raises(ValueError):
        m = metrics.Boolean(
            type="boolean",
            category="category",
            name="metric",
            bugs=[42],
            expires="foo",
            notification_emails=["*****@*****.**"],
            description="description...",
        )
def test_enforcement():
    """
    Test dataclasses enforcement.
    """
    with pytest.raises(TypeError):
        metrics.Boolean()

    # Python dataclasses don't actually validate any types, so we
    # delegate to jsonschema
    with pytest.raises(jsonschema.exceptions.ValidationError):
        metrics.Boolean(type='boolean',
                        category='category',
                        name='metric',
                        bugs=[42],
                        description=42,
                        notification_emails=['*****@*****.**'])
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>"
def test_enforcement():
    """
    Test dataclasses enforcement.
    """
    with pytest.raises(TypeError):
        metrics.Boolean()

    # Python dataclasses don't actually validate any types, so we
    # delegate to jsonschema
    with pytest.raises(ValueError):
        metrics.Boolean(
            type="boolean",
            category="category",
            name="metric",
            bugs=[42],
            description=42,
            notification_emails=["*****@*****.**"],
            expires="never",
        )
Beispiel #6
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"