blob: 05c7526bca76b100a07da7cbdbdfcb6a54bfc216 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Unittests for the issueimport servlet."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
12from framework import permissions
13from services import service_manager
14from testing import testing_helpers
15from tracker import issueimport
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010016from mrproto import tracker_pb2
Copybara854996b2021-09-07 19:36:02 +000017
18
19class IssueExportTest(unittest.TestCase):
20
21 def setUp(self):
22 self.services = service_manager.Services()
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010023 self.servlet = issueimport.IssueImport(services=self.services)
Copybara854996b2021-09-07 19:36:02 +000024 self.event_log = None
25
26 def testAssertBasePermission(self):
27 """Only site admins can import issues."""
28 mr = testing_helpers.MakeMonorailRequest(
29 perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
30 self.assertRaises(permissions.PermissionException,
31 self.servlet.AssertBasePermission, mr)
32 mr.auth.user_pb.is_site_admin = True
33 self.servlet.AssertBasePermission(mr)
34
35 def testParseComment(self):
36 """Test a Comment JSON is correctly parsed."""
37 users_id_dict = {'adam@test.com': 111}
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010038 config = {
39 'component_defs': [{
40 'path': 'comp1',
41 'component_id': 1,
42 }],
43 }
Copybara854996b2021-09-07 19:36:02 +000044 json = {
45 'timestamp': 123,
46 'commenter': 'adam@test.com',
47 'content': 'so basically, what I was thinkig of',
48 'amendments': [],
49 'attachments': [],
50 'description_num': None,
51 }
52 comment = self.servlet._ParseComment(
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010053 12,
54 users_id_dict,
55 json,
56 self.event_log,
57 config,
58 )
Copybara854996b2021-09-07 19:36:02 +000059 self.assertEqual(
60 comment, tracker_pb2.IssueComment(
61 project_id=12, timestamp=123, user_id=111,
62 content='so basically, what I was thinkig of'))
63
64 json_desc = {
65 'timestamp': 223,
66 'commenter': 'adam@test.com',
67 'content': 'I cant believe youve done this',
68 'description_num': '2',
69 'amendments': [],
70 'attachments': [],
71 }
72 desc_comment = self.servlet._ParseComment(
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010073 12, users_id_dict, json_desc, self.event_log, config)
Copybara854996b2021-09-07 19:36:02 +000074 self.assertEqual(
75 desc_comment, tracker_pb2.IssueComment(
76 project_id=12, timestamp=223, user_id=111,
77 content='I cant believe youve done this',
78 is_description=True))