1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#!/usr/bin/env vpython3
# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Unit tests for update_annotations_doc.py
"""
import os
import sys
import unittest
from mock import MagicMock
# Mock some imports which aren't necessary during testing.
sys.modules["infra_libs"] = MagicMock()
import update_annotations_doc
import generator_utils
# Absolute path to chrome/src.
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
SRC_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "../../.."))
TESTS_DIR = os.path.join(SCRIPT_DIR, "test_data")
class UpdateAnnotationsDocTest(unittest.TestCase):
network_doc_obj = update_annotations_doc.NetworkTrafficAnnotationsDoc(
"", "", "", "", "")
def test_create_group_request(self):
text = "TestGroup"
req, index = self.network_doc_obj._create_group_or_sender_request(
text, 0, generator_utils.Placeholder.GROUP)
self.assertEqual(len(text)+1, index)
expected_req = [
{"insertText": {"text": "TestGroup\n", "location": {"index": 0}}},
{"updateParagraphStyle": {
"fields": "*",
"range": {"endIndex": 10, "startIndex": 0},
"paragraphStyle": {
"spacingMode": "NEVER_COLLAPSE",
"direction": "LEFT_TO_RIGHT",
"namedStyleType": "HEADING_1",
"spaceAbove": {"unit": "PT"}
}
}
},
{"updateTextStyle": {
"textStyle": {
"fontSize": {"magnitude": 20, "unit": "PT"},
"bold": False,
"weightedFontFamily": {
"fontFamily": "Roboto",
"weight": 400
}
},
"range": {"endIndex": 10, "startIndex": 0}, "fields": "*"}}
]
self.assertEqual(expected_req, req)
def test_create_sender_request(self):
text = "TestSender"
print(text)
req, index = self.network_doc_obj._create_group_or_sender_request(
text, 0, generator_utils.Placeholder.SENDER)
self.assertEqual(len(text)+1, index)
expected_req = [
{"insertText": {"text": "TestSender\n", "location": {"index": 0}}},
{"updateParagraphStyle": {
"fields": "*",
"range": {"endIndex": 11, "startIndex": 0},
"paragraphStyle": {
"spacingMode": "NEVER_COLLAPSE",
"direction": "LEFT_TO_RIGHT",
"namedStyleType": "HEADING_2",
"spaceAbove": {"unit": "PT"}
}
}
},
{"updateTextStyle": {
"textStyle": {"fontSize": {"magnitude": 14, "unit": "PT"},
"bold": True,
"weightedFontFamily": {"fontFamily": "Roboto", "weight": 400}},
"range": {"endIndex": 11, "startIndex": 0}, "fields": "*"}
}
]
self.assertEqual(expected_req, req)
def test_create_annotation_request(self):
traffic_annotation = generator_utils.TrafficAnnotation(
**{
"unique_id": "unique_id_A",
"description": "description_A",
"trigger": "trigger_A",
"data": "data_A",
"settings": "settings_A",
"policy": "chrome_policy_A"
})
req, index = self.network_doc_obj._create_annotation_request(
traffic_annotation, 0)
self.assertEqual(109, index)
expected_req = [
{'insertText': {'text': '\n', 'location': {'index': 0}}},
{'insertTable': {'rows': 1, 'location': {'index': 0}, 'columns': 2}},
{'insertText': {'text': 'unique_id_A', 'location': {'index': 4}}},
{
'insertText': {
'text': "description_A\nTrigger: trigger_A\nData: data_A\nSettings: "
"settings_A\nPolicy: chrome_policy_A", 'location': {'index': 17}}},
{'updateTableColumnProperties': {
'columnIndices': [0],
'fields': '*',
'tableColumnProperties': {
'width': {'magnitude': 153, 'unit': 'PT'},
'widthType': 'FIXED_WIDTH'},
'tableStartLocation': {'index': 1}}},
{'updateTableColumnProperties': {
'columnIndices': [1],
'fields': '*',
'tableColumnProperties': {
'width': {'magnitude': 534, 'unit': 'PT'},'widthType': 'FIXED_WIDTH'},
'tableStartLocation': {'index': 1}}},
{'updateTableCellStyle': {
'fields': '*',
'tableCellStyle': {
'rowSpan': 1,
'borderBottom': {
'color': {
'color': {'rgbColor': {'blue': 1.0, 'green': 1.0, 'red': 1.0}}},
'width': {'unit': 'PT'}, 'dashStyle': 'SOLID'},
'paddingBottom': {'magnitude': 1.44, 'unit': 'PT'},
'paddingLeft': {'magnitude': 1.44, 'unit': 'PT'},
'paddingTop': {'magnitude': 1.44, 'unit': 'PT'},
'borderLeft': {
'color': {
'color': {'rgbColor': {'blue': 1.0, 'green': 1.0, 'red': 1.0}}},
'width': {'unit': 'PT'},
'dashStyle': 'SOLID'},
'columnSpan': 1,
'backgroundColor': {
'color': {'rgbColor': {'blue': 1.0, 'green': 1.0, 'red': 1.0}}},
'borderRight': {
'color': {
'color': {'rgbColor': {'blue': 1.0, 'green': 1.0, 'red': 1.0}}},
'width': {'unit': 'PT'},
'dashStyle': 'SOLID'},
'borderTop': {
'color': {
'color': {'rgbColor': {'blue': 1.0, 'green': 1.0, 'red': 1.0}}},
'width': {'unit': 'PT'},
'dashStyle': 'SOLID'},
'paddingRight': {'magnitude': 1.44, 'unit': 'PT'}},
'tableStartLocation': {'index': 1}}},
{'updateParagraphStyle': {
'fields': '*',
'range': {'endIndex': 108, 'startIndex': 4},
'paragraphStyle': {
'spacingMode': 'NEVER_COLLAPSE',
'direction': 'LEFT_TO_RIGHT',
'spaceBelow': {'magnitude': 4, 'unit': 'PT'},
'lineSpacing': 100,
'avoidWidowAndOrphan': False,
'namedStyleType': 'NORMAL_TEXT'}}},
{'updateTextStyle': {
'textStyle': {'fontSize': {'magnitude': 9, 'unit': 'PT'},
'bold': False,
'weightedFontFamily': {'fontFamily': 'Roboto', 'weight': 400}},
'range': {'endIndex': 108, 'startIndex': 4}, 'fields': '*'}}]
self.assertEqual(expected_req, req)
if __name__ == "__main__":
unittest.main()
|