Conditions | 2 |
Total Lines | 96 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
36 | @patch('gvm.protocols.latest.Gmp', new_callable=GmpMockFactory) |
||
37 | def test_combine_reports(self, mock_gmp: GmpMockFactory): |
||
38 | # bah! |
||
39 | mock_gmp.mock_responses( |
||
40 | 'get_report', |
||
41 | [ |
||
42 | '<get_reports_response status="200" status_text="OK">' |
||
43 | '<report id="00000000-0000-0000-0000-000000000000">' |
||
44 | '<name>2020-11-13T14:47:28Z</name>' |
||
45 | '<creation_time>2020-11-13T14:47:28Z</creation_time>' |
||
46 | '<modification_time>2020-11-13T14:47:28Z</modification_time>' |
||
47 | '<task id="00000000-0000-0000-0001-000000000000">' |
||
48 | '<name>Offline Scan from 2020-11-13T15:47:28+01:00 8</name>' |
||
49 | '</task>' |
||
50 | '<report id="00000000-0000-0000-0000-000000000000">' |
||
51 | '<scan_run_status>Done</scan_run_status>' |
||
52 | '<timestamp>2020-11-13T14:47:48Z</timestamp>' |
||
53 | '<scan_start>2020-11-13T14:47:28Z</scan_start>' |
||
54 | '<results start="1" max="100">' |
||
55 | '<result id="00000001-0000-0000-0000-000000000000">' |
||
56 | '</result>' |
||
57 | '<result id="00000001-0000-0000-0000-000000000001">' |
||
58 | '</result>' |
||
59 | '</results>' |
||
60 | '<scan_end>2020-11-13T14:47:28Z</scan_end>' |
||
61 | '</report>' |
||
62 | '</report>' |
||
63 | '</get_reports_response>', |
||
64 | '<get_reports_response status="200" status_text="OK">' |
||
65 | '<report id="00000000-0000-0000-0000-000000000001">' |
||
66 | '<name>2020-11-13T14:47:28Z</name>' |
||
67 | '<creation_time>2020-11-13T14:47:28Z</creation_time>' |
||
68 | '<modification_time>2020-11-13T14:47:28Z</modification_time>' |
||
69 | '<task id="00000000-0000-0000-0002-000000000000">' |
||
70 | '<name>Offline Scan from 2020-11-13T15:47:28+01:00 8</name>' |
||
71 | '</task>' |
||
72 | '<report id="00000000-0000-0000-0000-000000000001">' |
||
73 | '<scan_run_status>Done</scan_run_status>' |
||
74 | '<timestamp>2020-11-13T14:47:48Z</timestamp>' |
||
75 | '<scan_start>2020-11-13T14:47:28Z</scan_start>' |
||
76 | '<results start="1" max="100">' |
||
77 | '<result id="00000001-0000-0000-0000-000000000002">' |
||
78 | '</result>' |
||
79 | '<result id="00000001-0000-0000-0000-000000000003">' |
||
80 | '</result>' |
||
81 | '</results>' |
||
82 | '<scan_end>2020-11-13T14:47:28Z</scan_end>' |
||
83 | '</report>' |
||
84 | '</report>' |
||
85 | '</get_reports_response>', |
||
86 | '<get_reports_response status="200" status_text="OK">' |
||
87 | '<report id="00000000-0000-0000-0000-000000000002">' |
||
88 | '<name>2020-11-13T14:47:28Z</name>' |
||
89 | '<creation_time>2020-11-13T14:47:28Z</creation_time>' |
||
90 | '<modification_time>2020-11-13T14:47:28Z</modification_time>' |
||
91 | '<task id="00000000-0000-0000-0003-000000000000">' |
||
92 | '<name>Offline Scan from 2020-11-13T15:47:28+01:00 8</name>' |
||
93 | '</task>' |
||
94 | '<report id="00000000-0000-0000-0000-000000000002">' |
||
95 | '<scan_run_status>Done</scan_run_status>' |
||
96 | '<timestamp>2020-11-13T14:47:48Z</timestamp>' |
||
97 | '<scan_start>2020-11-13T14:47:28Z</scan_start>' |
||
98 | '<results start="1" max="100">' |
||
99 | '<result id="00000001-0000-0000-0000-000000000004">' |
||
100 | '</result>' |
||
101 | '</results>' |
||
102 | '<scan_end>2020-11-13T14:47:28Z</scan_end>' |
||
103 | '</report>' |
||
104 | '</report>' |
||
105 | '</get_reports_response>', |
||
106 | ], |
||
107 | ) |
||
108 | args = Namespace( |
||
109 | script=[ |
||
110 | 'foo', |
||
111 | '00000000-0000-0000-0000-000000000000', |
||
112 | '00000000-0000-0000-0000-000000000001', |
||
113 | '00000000-0000-0000-0000-000000000002', |
||
114 | ] |
||
115 | ) |
||
116 | |||
117 | combined_report = self.combine_reports.combine_reports( |
||
118 | gmp=mock_gmp.gmp_protocol, args=args |
||
119 | ) |
||
120 | |||
121 | results = ( |
||
122 | combined_report.find('report').find('results').findall('result') |
||
123 | ) |
||
124 | i = 0 |
||
125 | for result in results: |
||
126 | self.assertEqual( |
||
127 | result.get('id'), f'00000001-0000-0000-0000-00000000000{str(i)}' |
||
128 | ) |
||
129 | i += 1 |
||
130 | |||
131 | self.assertEqual(i, 5) |
||
132 | |||
180 |