当前位置: 首页>>代码示例>>Python>>正文


Python Check.assign_all_channels方法代码示例

本文整理汇总了Python中hc.api.models.Check.assign_all_channels方法的典型用法代码示例。如果您正苦于以下问题:Python Check.assign_all_channels方法的具体用法?Python Check.assign_all_channels怎么用?Python Check.assign_all_channels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hc.api.models.Check的用法示例。


在下文中一共展示了Check.assign_all_channels方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: checks

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import assign_all_channels [as 别名]
def checks(request):
    if request.method == "GET":
        q = Check.objects.filter(user=request.user)
        doc = {"checks": [check.to_dict() for check in q]}
        return JsonResponse(doc)

    elif request.method == "POST":
        check = Check(user=request.user)
        check.name = str(request.json.get("name", ""))
        check.tags = str(request.json.get("tags", ""))
        if "timeout" in request.json:
            check.timeout = td(seconds=request.json["timeout"])
        if "grace" in request.json:
            check.grace = td(seconds=request.json["grace"])

        check.save()

        # This needs to be done after saving the check, because of
        # the M2M relation between checks and channels:
        if request.json.get("channels") == "*":
            check.assign_all_channels()

        return JsonResponse(check.to_dict(), status=201)

    # If request is neither GET nor POST, return "405 Method not allowed"
    return HttpResponse(status=405)
开发者ID:Persistent13,项目名称:healthchecks,代码行数:28,代码来源:views.py

示例2: add_check

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import assign_all_channels [as 别名]
def add_check(request):
    assert request.method == "POST"

    check = Check(user=request.team.user)
    check.save()

    check.assign_all_channels()

    return redirect("hc-checks")
开发者ID:haswalt,项目名称:healthchecks,代码行数:11,代码来源:views.py

示例3: add_check

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import assign_all_channels [as 别名]
def add_check(request):
    num_checks = Check.objects.filter(user=request.team.user).count()
    if num_checks >= request.team.check_limit:
        return HttpResponseBadRequest()

    check = Check(user=request.team.user)
    check.save()

    check.assign_all_channels()

    return redirect("hc-checks")
开发者ID:cogzidel,项目名称:healthchecks,代码行数:13,代码来源:views.py

示例4: checks

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import assign_all_channels [as 别名]
def checks(request):
    if request.method == "GET":
        q = Check.objects.filter(user=request.user)
        doc = {"checks": [check.to_dict() for check in q]}
        return JsonResponse(doc)

    elif request.method == "POST":
        name = str(request.json.get("name", ""))
        tags = str(request.json.get("tags", ""))

        timeout = DEFAULT_TIMEOUT
        if "timeout" in request.json:
            timeout = td(seconds=request.json["timeout"])

        grace = DEFAULT_GRACE
        if "grace" in request.json:
            grace = td(seconds=request.json["grace"])

        unique_fields = request.json.get("unique", [])
        if unique_fields:
            existing_checks = Check.objects.filter(user=request.user)
            if "name" in unique_fields:
                existing_checks = existing_checks.filter(name=name)
            if "tags" in unique_fields:
                existing_checks = existing_checks.filter(tags=tags)
            if "timeout" in unique_fields:
                existing_checks = existing_checks.filter(timeout=timeout)
            if "grace" in unique_fields:
                existing_checks = existing_checks.filter(grace=grace)

            if existing_checks.count() > 0:
                # There might be more than one matching check, return first
                first_match = existing_checks.first()
                return JsonResponse(first_match.to_dict(), status=200)

        check = Check(user=request.user, name=name, tags=tags,
                      timeout=timeout, grace=grace)

        check.save()

        # This needs to be done after saving the check, because of
        # the M2M relation between checks and channels:
        if request.json.get("channels") == "*":
            check.assign_all_channels()

        return JsonResponse(check.to_dict(), status=201)

    # If request is neither GET nor POST, return "405 Method not allowed"
    return HttpResponse(status=405)
开发者ID:haswalt,项目名称:healthchecks,代码行数:51,代码来源:views.py

示例5: create_check

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import assign_all_channels [as 别名]
def create_check(request):
    if request.method == "GET":
        code = 200
        response = {
            "checks": [
                {
                    "name": check.name,
                    "ping_url": check.url(),
                    "tags": check.tags,
                    "timeout": int(check.timeout.total_seconds()),
                    "grace": int(check.grace.total_seconds()),
                    # "channels": check.channels,
                }
                for check in Check.objects.filter(user=request.user)
            ]
        }
    elif request.method == "POST":
        check = Check(user=request.user)
        check.name = str(request.json.get("name", ""))
        check.tags = str(request.json.get("tags", ""))
        if "timeout" in request.json:
            check.timeout = td(seconds=request.json["timeout"])
        if "grace" in request.json:
            check.grace = td(seconds=request.json["grace"])

        check.save()

        # This needs to be done after saving the check, because of
        # the M2M relation between checks and channels:
        if request.json.get("channels") == "*":
            check.assign_all_channels()

        code = 201
        response = {"ping_url": check.url()}
    else:
        return HttpResponse(status=405)

    return JsonResponse(response, status=code)
开发者ID:agaridata,项目名称:healthchecks,代码行数:40,代码来源:views.py

示例6: create_check

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import assign_all_channels [as 别名]
def create_check(request):
    if request.method != "POST":
        return HttpResponse(status=405)

    check = Check(user=request.user)
    check.name = str(request.json.get("name", ""))
    check.tags = str(request.json.get("tags", ""))
    if "timeout" in request.json:
        check.timeout = td(seconds=request.json["timeout"])
    if "grace" in request.json:
        check.grace = td(seconds=request.json["grace"])

    check.save()

    # This needs to be done after saving the check, because of
    # the M2M relation between checks and channels:
    if request.json.get("channels") == "*":
        check.assign_all_channels()

    response = {
        "ping_url": check.url()
    }

    return JsonResponse(response, status=201)
开发者ID:510908220,项目名称:healthchecks,代码行数:26,代码来源:views.py

示例7: UpdateCheckTestCase

# 需要导入模块: from hc.api.models import Check [as 别名]
# 或者: from hc.api.models.Check import assign_all_channels [as 别名]
class UpdateCheckTestCase(BaseTestCase):

    def setUp(self):
        super(UpdateCheckTestCase, self).setUp()
        self.check = Check(user=self.alice)
        self.check.save()

    def post(self, code, data):
        url = "/api/v1/checks/%s" % code
        r = self.client.post(url, json.dumps(data),
                             content_type="application/json")

        return r

    def test_it_works(self):
        r = self.post(self.check.code, {
            "api_key": "abc",
            "name": "Foo",
            "tags": "bar,baz",
            "timeout": 3600,
            "grace": 60
        })

        self.assertEqual(r.status_code, 200)

        doc = r.json()
        assert "ping_url" in doc
        self.assertEqual(doc["name"], "Foo")
        self.assertEqual(doc["tags"], "bar,baz")
        self.assertEqual(doc["last_ping"], None)
        self.assertEqual(doc["n_pings"], 0)

        self.assertTrue("schedule" not in doc)
        self.assertTrue("tz" not in doc)

        self.assertEqual(Check.objects.count(), 1)

        self.check.refresh_from_db()
        self.assertEqual(self.check.name, "Foo")
        self.assertEqual(self.check.tags, "bar,baz")
        self.assertEqual(self.check.timeout.total_seconds(), 3600)
        self.assertEqual(self.check.grace.total_seconds(), 60)

    def test_it_unassigns_channels(self):
        channel = Channel(user=self.alice)
        channel.save()

        self.check.assign_all_channels()

        r = self.post(self.check.code, {
            "api_key": "abc",
            "channels": ""
        })

        self.assertEqual(r.status_code, 200)
        check = Check.objects.get()
        self.assertEqual(check.channel_set.count(), 0)

    def test_it_requires_post(self):
        url = "/api/v1/checks/%s" % self.check.code
        r = self.client.get(url, HTTP_X_API_KEY="abc")
        self.assertEqual(r.status_code, 405)

    def test_it_handles_invalid_uuid(self):
        r = self.post("not-an-uuid", {"api_key": "abc"})
        self.assertEqual(r.status_code, 400)

    def test_it_handles_missing_check(self):
        made_up_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
        r = self.post(made_up_code, {"api_key": "abc"})
        self.assertEqual(r.status_code, 404)

    def test_it_validates_ownership(self):
        check = Check(user=self.bob, status="up")
        check.save()

        r = self.post(check.code, {"api_key": "abc"})
        self.assertEqual(r.status_code, 403)

    def test_it_updates_cron_to_simple(self):
        self.check.kind = "cron"
        self.check.schedule = "5 * * * *"
        self.check.save()

        r = self.post(self.check.code, {"api_key": "abc", "timeout": 3600})
        self.assertEqual(r.status_code, 200)

        self.check.refresh_from_db()
        self.assertEqual(self.check.kind, "simple")
开发者ID:cogzidel,项目名称:healthchecks,代码行数:91,代码来源:test_update_check.py


注:本文中的hc.api.models.Check.assign_all_channels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。