Esempio n. 1
0
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", project=request.project)
        channel.user = request.project.owner
        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)
Esempio n. 2
0
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)
Esempio n. 3
0
    def test_it_refreshes_hipchat_access_token(self, mock_post):
        mock_post.return_value.json.return_value = {"expires_in": 100}

        value = json.dumps({"oauthId": "foo", "oauthSecret": "bar"})

        channel = Channel(kind="hipchat", project=self.project, value=value)
        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)
    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)