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


Python Channel.make_token方法代码示例

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


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

示例1: VerifyEmailTestCase

# 需要导入模块: from hc.api.models import Channel [as 别名]
# 或者: from hc.api.models.Channel import make_token [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 make_token [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


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