Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Unittests for the issueimport servlet.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import unittest |
| 11 | |
| 12 | from framework import permissions |
| 13 | from services import service_manager |
| 14 | from testing import testing_helpers |
| 15 | from tracker import issueimport |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 16 | from mrproto import tracker_pb2 |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | class IssueExportTest(unittest.TestCase): |
| 20 | |
| 21 | def setUp(self): |
| 22 | self.services = service_manager.Services() |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 23 | self.servlet = issueimport.IssueImport(services=self.services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 24 | 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 38 | config = { |
| 39 | 'component_defs': [{ |
| 40 | 'path': 'comp1', |
| 41 | 'component_id': 1, |
| 42 | }], |
| 43 | } |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 44 | 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 53 | 12, |
| 54 | users_id_dict, |
| 55 | json, |
| 56 | self.event_log, |
| 57 | config, |
| 58 | ) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 59 | 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ínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 73 | 12, users_id_dict, json_desc, self.event_log, config) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 74 | 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)) |