def test_no_accounts_received(self, mock_render_to_response, mock_get_user_info): responses.reset() responses.add( responses.GET, "https://app.vssps.visualstudio.com/_apis/accounts", json={ "value": [], "count": 0 }, status=200, ) view = AccountConfigView() request = Mock() request.POST = {} request.user = self.user pipeline = Mock() pipeline.fetch_state = lambda key: { "data": { "access_token": "1234567890" } } pipeline.organization = self.organization view.dispatch(request, pipeline) assert mock_get_user_info.called is True assert mock_render_to_response.called is True assert mock_render_to_response.call_args[1]["context"] == { "no_accounts": True }
def test_webhook_subscription_created_once(self, mock_get_scopes): self.assert_installation() state = { "account": {"accountName": self.vsts_account_name, "accountId": self.vsts_account_id}, "base_url": self.vsts_base_url, "identity": { "data": { "access_token": self.access_token, "expires_in": "3600", "refresh_token": self.refresh_token, "token_type": "jwt-bearer", } }, } # The above already created the Webhook, so subsequent calls to # ``build_integration`` should omit that data. provider = VstsIntegrationProvider() pipeline = Mock() pipeline.organization = self.organization provider.set_pipeline(pipeline) data = provider.build_integration(state) assert "subscription" in data["metadata"] assert ( Integration.objects.get(provider="vsts").metadata["subscription"] == data["metadata"]["subscription"] )