本文整理汇总了Python中hc.api.models.Channel类的典型用法代码示例。如果您正苦于以下问题:Python Channel类的具体用法?Python Channel怎么用?Python Channel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VerifyEmailTestCase
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
示例2: ChannelChecksTestCase
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
示例3: test_it_shows_channel_list_with_pushbullet
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")
示例4: test_it_assigns_channels
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)
示例5: add_hipchat
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)
示例6: test_it_shows_webhook_notifications
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)
示例7: test_it_shows_pushover_notifications
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)
示例8: test_it_refreshes_hipchat_access_token
def test_it_refreshes_hipchat_access_token(self, mock_post):
mock_post.return_value.json.return_value = {"expires_in": 100}
channel = Channel(kind="hipchat", user=self.alice, value=json.dumps({
"oauthId": "foo",
"oauthSecret": "bar"
}))
channel.refresh_hipchat_access_token()
# It should request a token using a correct tokenUrl
mock_post.assert_called()
self.assertTrue("expires_at" in channel.value)
示例9: RemoveChannelTestCase
class RemoveChannelTestCase(BaseTestCase):
def setUp(self):
super(RemoveChannelTestCase, 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/remove/" % self.channel.code
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
self.assertRedirects(r, "/integrations/")
assert Channel.objects.count() == 0
def test_team_access_works(self):
url = "/integrations/%s/remove/" % self.channel.code
self.client.login(username="[email protected]", password="password")
self.client.post(url)
assert Channel.objects.count() == 0
def test_it_handles_bad_uuid(self):
url = "/integrations/not-uuid/remove/"
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
assert r.status_code == 400
def test_it_checks_owner(self):
url = "/integrations/%s/remove/" % self.channel.code
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
assert r.status_code == 403
def test_it_handles_missing_uuid(self):
# Valid UUID but there is no channel for it:
url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
assert r.status_code == 302
def test_it_rejects_get(self):
url = "/integrations/%s/remove/" % self.channel.code
self.client.login(username="[email protected]", password="password")
r = self.client.get(url)
self.assertEqual(r.status_code, 405)
示例10: test_it_checks_check_user
def test_it_checks_check_user(self):
charlies_channel = Channel(user=self.charlie, kind="email")
charlies_channel.email = "[email protected]"
charlies_channel.save()
payload = {
"channel": charlies_channel.code,
"check-%s" % self.check.code: True
}
self.client.login(username="[email protected]", password="password")
r = self.client.post("/integrations/", data=payload)
# mc belongs to charlie but self.check does not--
assert r.status_code == 403
示例11: test_it_unassigns_channels
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)
示例12: add_slack_btn
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")
示例13: test_it_formats_complex_slack_value
def test_it_formats_complex_slack_value(self):
ch = Channel(kind="slack", user=self.alice)
ch.value = json.dumps({
"ok": True,
"team_name": "foo-team",
"incoming_webhook": {
"url": "http://example.org",
"channel": "#bar"
}
})
ch.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/integrations/")
self.assertContains(r, "foo-team", status_code=200)
self.assertContains(r, "#bar")
示例14: RemoveChannelTestCase
class RemoveChannelTestCase(TestCase):
def setUp(self):
super(RemoveChannelTestCase, self).setUp()
self.alice = User(username="alice", email="[email protected]")
self.alice.set_password("password")
self.alice.save()
self.channel = Channel(user=self.alice, kind="email")
self.channel.value = "[email protected]"
self.channel.save()
def test_it_works(self):
url = "/integrations/%s/remove/" % self.channel.code
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
self.assertRedirects(r, "/integrations/")
assert Channel.objects.count() == 0
def test_it_handles_bad_uuid(self):
url = "/integrations/not-uuid/remove/"
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
assert r.status_code == 400
def test_it_checks_owner(self):
url = "/integrations/%s/remove/" % self.channel.code
mallory = User(username="mallory", email="[email protected]")
mallory.set_password("password")
mallory.save()
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
assert r.status_code == 403
def test_it_handles_missing_uuid(self):
# Valid UUID but there is no channel for it:
url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"
self.client.login(username="[email protected]", password="password")
r = self.client.post(url)
assert r.status_code == 404
示例15: setUp
def setUp(self):
super(UpdateChannelTestCase, self).setUp()
self.check = Check(user=self.alice)
self.check.save()
self.channel = Channel(user=self.alice, kind="email")
self.channel.email = "[email protected]"
self.channel.save()