Esempio n. 1
0
def badge(request, username, signature, tag, format="svg"):
    if not check_signature(username, tag, signature):
        return HttpResponseNotFound()

    status = "up"
    q = Check.objects.filter(user__username=username)
    if tag != "*":
        q = q.filter(tags__contains=tag)
        label = tag
    else:
        label = settings.MASTER_BADGE_LABEL

    for check in q:
        if tag != "*" and tag not in check.tags_list():
            continue

        check_status = check.get_status()
        if status == "up" and check_status == "grace":
            status = "late"

        if check_status == "down":
            status = "down"
            break

    if format == "json":
        return JsonResponse({"status": status})

    svg = get_badge_svg(label, status)
    return HttpResponse(svg, content_type="image/svg+xml")
Esempio n. 2
0
def badge(request, username, signature, tag):
    if not check_signature(username, tag, signature):
        return HttpResponseBadRequest()

    status = "up"
    q = Check.objects.filter(user__username=username, tags__contains=tag)
    now = timezone.now()
    for check in q:
        if tag not in check.tags_list():
            continue

        if status == "up" and check.in_grace_period():
            status = "late"

        if check.last_ping - now < check.timeout - check.grace:
            return "over"
        if check.get_status() == "down":
            status = "down"
            break
        if check.runs_too_often() == "over":
            status = "over"
            break

    svg = get_badge_svg(tag, status)
    return HttpResponse(svg, content_type="image/svg+xml")
Esempio n. 3
0
def badge(request, username, signature, tag, format="svg"):
    if not check_signature(username, tag, signature):
        return HttpResponseNotFound()

    status = "up"
    q = Check.objects.filter(user__username=username)
    if tag != "*":
        q = q.filter(tags__contains=tag)
        label = tag
    else:
        label = settings.MASTER_BADGE_LABEL

    for check in q:
        if tag != "*" and tag not in check.tags_list():
            continue

        if status == "up" and check.in_grace_period():
            status = "late"

        if check.get_status() == "down":
            status = "down"
            break

    if format == "json":
        return JsonResponse({"status": status})

    svg = get_badge_svg(label, status)
    return HttpResponse(svg, content_type="image/svg+xml")
Esempio n. 4
0
def badge(request, badge_key, signature, tag, fmt="svg"):
    if not check_signature(badge_key, tag, signature):
        return HttpResponseNotFound()

    if fmt not in ("svg", "json", "shields"):
        return HttpResponseNotFound()

    q = Check.objects.filter(project__badge_key=badge_key)
    if tag != "*":
        q = q.filter(tags__contains=tag)
        label = tag
    else:
        label = settings.MASTER_BADGE_LABEL

    status, total, grace, down = "up", 0, 0, 0
    for check in q:
        if tag != "*" and tag not in check.tags_list():
            continue

        total += 1
        check_status = check.get_status(with_started=False)

        if check_status == "down":
            down += 1
            status = "down"
            if fmt == "svg":
                # For SVG badges, we can leave the loop as soon as we
                # find the first "down"
                break
        elif check_status == "grace":
            grace += 1
            if status == "up":
                status = "late"

    if fmt == "shields":
        color = "success"
        if status == "down":
            color = "critical"
        elif status == "late":
            color = "important"

        return JsonResponse({
            "label": label,
            "message": status,
            "color": color
        })

    if fmt == "json":
        return JsonResponse({
            "status": status,
            "total": total,
            "grace": grace,
            "down": down
        })

    svg = get_badge_svg(label, status)
    return HttpResponse(svg, content_type="image/svg+xml")
Esempio n. 5
0
def badge(request, username, signature, tag):
    if not check_signature(username, tag, signature):
        return HttpResponseBadRequest()

    status = "up"
    q = Check.objects.filter(user__username=username, tags__contains=tag)
    for check in q:
        if tag not in check.tags_list():
            continue

        if status == "up" and check.in_grace_period():
            status = "late"

        if check.get_status() == "down":
            status = "down"
            break

    svg = get_badge_svg(tag, status)
    return HttpResponse(svg, content_type="image/svg+xml")
Esempio n. 6
0
def badge(request, username, signature, tag):
    if not check_signature(username, tag, signature):
        return HttpResponseBadRequest()

    status = "up"
    q = Check.objects.filter(user__username=username, tags__contains=tag)
    for check in q:
        if tag not in check.tags_list():
            continue

        if status == "up" and check.in_grace_period():
            status = "late"

        if check.get_status() == "down":
            status = "down"
            break

    svg = get_badge_svg(tag, status)
    return HttpResponse(svg, content_type="image/svg+xml")
Esempio n. 7
0
    def test_it_makes_svg(self):
        svg = get_badge_svg("foo", "up")
        self.assertTrue("#4c1" in svg)

        svg = get_badge_svg("bar", "down")
        self.assertTrue("#e05d44" in svg)
Esempio n. 8
0
 def test_it_uses_decimal_dot(self):
     svg = get_badge_svg("a", "up")
     self.assertIn("8.5", svg)
     self.assertNotIn("8,5", svg)
Esempio n. 9
0
    def test_it_makes_svg(self):
        svg = get_badge_svg("foo", "up")
        self.assertTrue("#4c1" in svg)

        svg = get_badge_svg("bar", "down")
        self.assertTrue("#e05d44" in svg)