test_plugin.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:sentry-plugins 作者: getsentry 项目源码 文件源码
def test_link_issue_with_comment(self):
        responses.add(
            responses.PATCH,
            'https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workitems/309?api-version=3.0',
            body=WORK_ITEM_RESPONSE,
            content_type='application/json',
        )

        self.plugin.set_option(
            'instance', 'fabrikam-fiber-inc.visualstudio.com', self.project)
        group = self.create_group(message='Hello world', culprit='foo.bar')

        request = self.request.get('/')
        request.user = AnonymousUser()
        form_data = {
            'item_id': '309',
            'comment': 'Fix this.',
        }
        with self.assertRaises(PluginError):
            self.plugin.link_issue(request, group, form_data)

        request.user = self.user
        self.login_as(self.user)
        UserSocialAuth.objects.create(
            user=self.user,
            provider=self.plugin.auth_provider,
            uid='a89e7204-9ca0-4680-ba7a-cfcf6b3c7445',
            extra_data={
                'access_token': 'foo',
                'refresh_token': 'bar',
            }
        )

        assert self.plugin.link_issue(request, group, form_data) == {
            'id': 309,
            'title': 'Customer can sign in using their Microsoft Account',
            'url': 'https://fabrikam-fiber-inc.visualstudio.com/web/wi.aspx?pcguid=d81542e4-cdfa-4333-b082-1ae2d6c3ad16&id=309',
        }
        request = responses.calls[-1].request
        assert request.headers['Content-Type'] == 'application/json-patch+json'
        payload = json.loads(request.body)
        assert payload == [
            {
                'op': 'add',
                'path': '/fields/System.History',
                'value': '<p>Fix this.</p>\n',
            },
            # {
            #     "op": "add",
            #     "path": "/relations/-",
            #     "value": {
            #         "rel": "Hyperlink",
            #         "url": 'http://testserver/baz/bar/issues/1/',
            #     }
            # }
        ]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号