blob: c0e38af15f5e17881d3a11e46b0fc25a5ec59742 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""Unittests for the issueimport servlet."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11import unittest
12
13from framework import permissions
14from services import service_manager
15from testing import testing_helpers
16from tracker import issueimport
17from proto import tracker_pb2
18
19
20class IssueExportTest(unittest.TestCase):
21
22 def setUp(self):
23 self.services = service_manager.Services()
24 self.servlet = issueimport.IssueImport(
25 'req', 'res', services=self.services)
26 self.event_log = None
27
28 def testAssertBasePermission(self):
29 """Only site admins can import issues."""
30 mr = testing_helpers.MakeMonorailRequest(
31 perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
32 self.assertRaises(permissions.PermissionException,
33 self.servlet.AssertBasePermission, mr)
34 mr.auth.user_pb.is_site_admin = True
35 self.servlet.AssertBasePermission(mr)
36
37 def testParseComment(self):
38 """Test a Comment JSON is correctly parsed."""
39 users_id_dict = {'adam@test.com': 111}
40 json = {
41 'timestamp': 123,
42 'commenter': 'adam@test.com',
43 'content': 'so basically, what I was thinkig of',
44 'amendments': [],
45 'attachments': [],
46 'description_num': None,
47 }
48 comment = self.servlet._ParseComment(
49 12, users_id_dict, json, self.event_log)
50 self.assertEqual(
51 comment, tracker_pb2.IssueComment(
52 project_id=12, timestamp=123, user_id=111,
53 content='so basically, what I was thinkig of'))
54
55 json_desc = {
56 'timestamp': 223,
57 'commenter': 'adam@test.com',
58 'content': 'I cant believe youve done this',
59 'description_num': '2',
60 'amendments': [],
61 'attachments': [],
62 }
63 desc_comment = self.servlet._ParseComment(
64 12, users_id_dict, json_desc, self.event_log)
65 self.assertEqual(
66 desc_comment, tracker_pb2.IssueComment(
67 project_id=12, timestamp=223, user_id=111,
68 content='I cant believe youve done this',
69 is_description=True))