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


Python Channel.save方法代码示例

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


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

示例1: VerifyEmailTestCase

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

    def setUp(self):
        super(VerifyEmailTestCase, self).setUp()
        self.channel = Channel(user=self.alice, kind="email")
        self.channel.value = "[email protected]"
        self.channel.save()

    def test_it_works(self):
        token = self.channel.make_token()
        url = "/integrations/%s/verify/%s/" % (self.channel.code, token)

        r = self.client.post(url)
        assert r.status_code == 200, r.status_code

        channel = Channel.objects.get(code=self.channel.code)
        assert channel.email_verified

    def test_it_handles_bad_token(self):
        url = "/integrations/%s/verify/bad-token/" % self.channel.code

        r = self.client.post(url)
        assert r.status_code == 200, r.status_code

        channel = Channel.objects.get(code=self.channel.code)
        assert not channel.email_verified

    def test_missing_channel(self):
        # Valid UUID, and even valid token but there is no channel for it:
        code = "6837d6ec-fc08-4da5-a67f-08a9ed1ccf62"
        token = self.channel.make_token()
        url = "/integrations/%s/verify/%s/" % (code, token)

        r = self.client.post(url)
        assert r.status_code == 404
开发者ID:MPOWER4RU,项目名称:healthchecks,代码行数:37,代码来源:test_verify_email.py

示例2: UnsubscribeEmailTestCase

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

    def setUp(self):
        super(UnsubscribeEmailTestCase, self).setUp()
        self.channel = Channel(user=self.alice, kind="email")
        self.channel.value = "[email protected]"
        self.channel.save()

    def test_it_works(self):
        token = self.channel.make_token()
        url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)

        r = self.client.get(url)
        self.assertContains(r, "has been unsubscribed", status_code=200)

        q = Channel.objects.filter(code=self.channel.code)
        self.assertEqual(q.count(), 0)

    def test_it_checks_token(self):
        url = "/integrations/%s/unsub/faketoken/" % self.channel.code

        r = self.client.get(url)
        self.assertContains(r, "link you just used is incorrect",
                            status_code=200)

    def test_it_checks_channel_kind(self):
        self.channel.kind = "webhook"
        self.channel.save()

        token = self.channel.make_token()
        url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)

        r = self.client.get(url)
        self.assertEqual(r.status_code, 400)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:36,代码来源:test_unsubscribe_email.py

示例3: ChannelChecksTestCase

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

    def setUp(self):
        super(ChannelChecksTestCase, self).setUp()
        self.channel = Channel(user=self.alice, kind="email")
        self.channel.value = "[email protected]"
        self.channel.save()

    def test_it_works(self):
        url = "/integrations/%s/checks/" % self.channel.code

        self.client.login(username="[email protected]", password="password")
        r = self.client.get(url)
        self.assertContains(r, "[email protected]", status_code=200)

    def test_it_checks_owner(self):
        mallory = User(username="mallory", email="[email protected]")
        mallory.set_password("password")
        mallory.save()

        # channel does not belong to mallory so this should come back
        # with 403 Forbidden:
        url = "/integrations/%s/checks/" % self.channel.code
        self.client.login(username="[email protected]", password="password")
        r = self.client.get(url)
        assert r.status_code == 403

    def test_missing_channel(self):
        # Valid UUID but there is no channel for it:
        url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/checks/"

        self.client.login(username="[email protected]", password="password")
        r = self.client.get(url)
        assert r.status_code == 404
开发者ID:510908220,项目名称:healthchecks,代码行数:36,代码来源:test_channel_checks.py

示例4: add_slack_btn

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
def add_slack_btn(request):
    code = request.GET.get("code", "")
    if len(code) < 8:
        return HttpResponseBadRequest()

    result = requests.post("https://slack.com/api/oauth.access", {
        "client_id": settings.SLACK_CLIENT_ID,
        "client_secret": settings.SLACK_CLIENT_SECRET,
        "code": code
    })

    doc = result.json()
    if doc.get("ok"):
        channel = Channel()
        channel.user = request.team.user
        channel.kind = "slack"
        channel.value = result.text
        channel.save()
        channel.assign_all_checks()
        messages.success(request, "The Slack integration has been added!")
    else:
        s = doc.get("error")
        messages.warning(request, "Error message from slack: %s" % s)

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

示例5: add_telegram

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
def add_telegram(request):
    chat_id, chat_type, chat_name = None, None, None
    qs = request.META["QUERY_STRING"]
    if qs:
        chat_id, chat_type, chat_name = signing.loads(qs, max_age=600)

    if request.method == "POST":
        channel = Channel(user=request.team.user, kind="telegram")
        channel.value = json.dumps({
            "id": chat_id,
            "type": chat_type,
            "name": chat_name
        })
        channel.save()

        channel.assign_all_checks()
        messages.success(request, "The Telegram integration has been added!")
        return redirect("hc-channels")

    ctx = {
        "chat_id": chat_id,
        "chat_type": chat_type,
        "chat_name": chat_name,
        "bot_name": settings.TELEGRAM_BOT_NAME
    }

    return render(request, "integrations/add_telegram.html", ctx)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:29,代码来源:views.py

示例6: add_hipchat

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
def add_hipchat(request):
    if "installable_url" in request.GET:
        url = request.GET["installable_url"]
        assert url.startswith("https://api.hipchat.com")
        response = requests.get(url)
        if "oauthId" not in response.json():
            messages.warning(request, "Something went wrong!")
            return redirect("hc-channels")

        channel = Channel(kind="hipchat")
        channel.user = request.team.user
        channel.value = response.text
        channel.save()

        channel.refresh_hipchat_access_token()
        channel.assign_all_checks()
        messages.success(request, "The HipChat integration has been added!")
        return redirect("hc-channels")

    install_url = "https://www.hipchat.com/addons/install?" + urlencode({
        "url": settings.SITE_ROOT + reverse("hc-hipchat-capabilities")
    })

    ctx = {
        "page": "channels",
        "install_url": install_url
    }
    return render(request, "integrations/add_hipchat.html", ctx)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:30,代码来源:views.py

示例7: add_slack

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
def add_slack(request):
    if not settings.SLACK_CLIENT_ID and not request.user.is_authenticated:
        return redirect("hc-login")

    if request.method == "POST":
        form = AddUrlForm(request.POST)
        if form.is_valid():
            channel = Channel(user=request.team.user, kind="slack")
            channel.value = form.cleaned_data["value"]
            channel.save()

            channel.assign_all_checks()
            return redirect("hc-channels")
    else:
        form = AddUrlForm()

    ctx = {
        "page": "channels",
        "form": form,
        "slack_client_id": settings.SLACK_CLIENT_ID
    }

    if settings.SLACK_CLIENT_ID:
        ctx["state"] = _prepare_state(request, "slack")

    return render(request, "integrations/add_slack.html", ctx)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:28,代码来源:views.py

示例8: add_pushover

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
def add_pushover(request):
    if settings.PUSHOVER_API_TOKEN is None or settings.PUSHOVER_SUBSCRIPTION_URL is None:
        raise Http404("pushover integration is not available")

    if request.method == "POST":
        # Initiate the subscription
        nonce = get_random_string()
        request.session["po_nonce"] = nonce

        failure_url = settings.SITE_ROOT + reverse("hc-channels")
        success_url = settings.SITE_ROOT + reverse("hc-add-pushover") + "?" + urlencode({
            "nonce": nonce,
            "prio": request.POST.get("po_priority", "0"),
        })
        subscription_url = settings.PUSHOVER_SUBSCRIPTION_URL + "?" + urlencode({
            "success": success_url,
            "failure": failure_url,
        })

        return redirect(subscription_url)

    # Handle successful subscriptions
    if "pushover_user_key" in request.GET:
        if "nonce" not in request.GET or "prio" not in request.GET:
            return HttpResponseBadRequest()

        # Validate nonce
        if request.GET["nonce"] != request.session.get("po_nonce"):
            return HttpResponseForbidden()

        # Validate priority
        if request.GET["prio"] not in ("-2", "-1", "0", "1", "2"):
            return HttpResponseBadRequest()

        # All looks well--
        del request.session["po_nonce"]

        if request.GET.get("pushover_unsubscribed") == "1":
            # Unsubscription: delete all Pushover channels for this user
            Channel.objects.filter(user=request.user, kind="po").delete()
            return redirect("hc-channels")
        else:
            # Subscription
            user_key = request.GET["pushover_user_key"]
            priority = int(request.GET["prio"])

            channel = Channel(user=request.team.user, kind="po")
            channel.value = "%s|%d" % (user_key, priority)
            channel.save()
            channel.assign_all_checks()
            return redirect("hc-channels")

    # Show Integration Settings form
    ctx = {
        "page": "channels",
        "po_retry_delay": td(seconds=settings.PUSHOVER_EMERGENCY_RETRY_DELAY),
        "po_expiration": td(seconds=settings.PUSHOVER_EMERGENCY_EXPIRATION),
    }
    return render(request, "integrations/add_pushover.html", ctx)
开发者ID:haswalt,项目名称:healthchecks,代码行数:61,代码来源:views.py

示例9: test_it_shows_channel_list_with_pushbullet

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
    def test_it_shows_channel_list_with_pushbullet(self):
        self.client.login(username="[email protected]", password="password")

        ch = Channel(user=self.alice, kind="pushbullet", value="test-token")
        ch.save()

        r = self.client.get("/admin/api/channel/")
        self.assertContains(r, "Pushbullet")
开发者ID:haswalt,项目名称:healthchecks,代码行数:10,代码来源:test_admin.py

示例10: test_it_assigns_channels

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
    def test_it_assigns_channels(self):
        channel = Channel(user=self.alice)
        channel.save()

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

        self.assertEqual(r.status_code, 201)
        check = Check.objects.get()
        self.assertEqual(check.channel_set.get(), channel)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:11,代码来源:test_create_check.py

示例11: NotifyTestCase

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
class NotifyTestCase(TestCase):

    def _setup_data(self, channel_kind, channel_value, email_verified=True):
        self.alice = User(username="alice")
        self.alice.save()

        self.check = Check()
        self.check.status = "down"
        self.check.save()

        self.channel = Channel(user=self.alice)
        self.channel.kind = channel_kind
        self.channel.value = channel_value
        self.channel.email_verified = email_verified
        self.channel.save()
        self.channel.checks.add(self.check)

    @patch("hc.api.models.requests.get")
    def test_webhook(self, mock_get):
        self._setup_data("webhook", "http://example")
        mock_get.return_value.status_code = 200

        self.channel.notify(self.check)
        mock_get.assert_called_with(u"http://example", timeout=5)

    @patch("hc.api.models.requests.get", side_effect=ReadTimeout)
    def test_webhooks_handle_timeouts(self, mock_get):
        self._setup_data("webhook", "http://example")
        self.channel.notify(self.check)
        assert Notification.objects.count() == 1

    def test_email(self):
        self._setup_data("email", "[email protected]")
        self.channel.notify(self.check)
        assert Notification.objects.count() == 1

        # And email should have been sent
        self.assertEqual(len(mail.outbox), 1)

    def test_it_skips_unverified_email(self):
        self._setup_data("email", "[email protected]", email_verified=False)
        self.channel.notify(self.check)

        assert Notification.objects.count() == 0
        self.assertEqual(len(mail.outbox), 0)

    @patch("hc.api.models.requests.post")
    def test_pd(self, mock_post):
        self._setup_data("pd", "123")
        mock_post.return_value.status_code = 200

        self.channel.notify(self.check)
        assert Notification.objects.count() == 1

        args, kwargs = mock_post.call_args
        assert "trigger" in kwargs["data"]
开发者ID:diwu1989,项目名称:healthchecks,代码行数:58,代码来源:test_notify.py

示例12: add_zendesk

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
def add_zendesk(request):
    if settings.ZENDESK_CLIENT_ID is None:
        raise Http404("zendesk integration is not available")

    if request.method == "POST":
        domain = request.POST.get("subdomain")
        request.session["subdomain"] = domain
        redirect_uri = settings.SITE_ROOT + reverse("hc-add-zendesk")
        auth_url = "https://%s.zendesk.com/oauth/authorizations/new?" % domain
        auth_url += urlencode({
            "client_id": settings.ZENDESK_CLIENT_ID,
            "redirect_uri": redirect_uri,
            "response_type": "code",
            "scope": "requests:read requests:write",
            "state": _prepare_state(request, "zendesk")
        })

        return redirect(auth_url)

    if "code" in request.GET:
        code = _get_validated_code(request, "zendesk")
        if code is None:
            return HttpResponseBadRequest()

        domain = request.session.pop("subdomain")
        url = "https://%s.zendesk.com/oauth/tokens" % domain

        redirect_uri = settings.SITE_ROOT + reverse("hc-add-zendesk")
        result = requests.post(url, {
            "client_id": settings.ZENDESK_CLIENT_ID,
            "client_secret": settings.ZENDESK_CLIENT_SECRET,
            "code": code,
            "grant_type": "authorization_code",
            "redirect_uri": redirect_uri,
            "scope": "read"
        })

        doc = result.json()
        if "access_token" in doc:
            doc["subdomain"] = domain

            channel = Channel(kind="zendesk")
            channel.user = request.team.user
            channel.value = json.dumps(doc)
            channel.save()
            channel.assign_all_checks()
            messages.success(request,
                             "The Zendesk integration has been added!")
        else:
            messages.warning(request, "Something went wrong")

        return redirect("hc-channels")

    ctx = {"page": "channels"}
    return render(request, "integrations/add_zendesk.html", ctx)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:57,代码来源:views.py

示例13: test_it_shows_webhook_notifications

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
    def test_it_shows_webhook_notifications(self):
        ch = Channel(kind="webhook", user=self.alice, value="foo/$NAME")
        ch.save()

        Notification(owner=self.check, channel=ch, check_status="down").save()

        url = "/checks/%s/log/" % self.check.code

        self.client.login(username="[email protected]", password="password")
        r = self.client.get(url)
        self.assertContains(r, "Called webhook foo/$NAME", status_code=200)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:13,代码来源:test_log.py

示例14: test_it_shows_pushover_notifications

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
    def test_it_shows_pushover_notifications(self):
        ch = Channel(kind="po", user=self.alice)
        ch.save()

        Notification(owner=self.check, channel=ch, check_status="down").save()

        url = "/checks/%s/log/" % self.check.code

        self.client.login(username="[email protected]", password="password")
        r = self.client.get(url)
        self.assertContains(r, "Sent a Pushover notification", status_code=200)
开发者ID:cogzidel,项目名称:healthchecks,代码行数:13,代码来源:test_log.py

示例15: _make_user

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import save [as 别名]
def _make_user(email):
    username = str(uuid.uuid4())[:30]
    user = User(username=username, email=email)
    user.save()

    channel = Channel()
    channel.user = user
    channel.kind = "email"
    channel.value = email
    channel.email_verified = True
    channel.save()

    return user
开发者ID:bobocola,项目名称:healthchecks,代码行数:15,代码来源:views.py


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