| Conditions | 1 |
| Total Lines | 64 |
| Code Lines | 45 |
| 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 | """Module to test the main napp file.""" |
||
| 98 | @patch('napps.kytos.mef_eline.storehouse.StoreHouse.get_data') |
||
| 99 | @patch('napps.kytos.mef_eline.scheduler.Scheduler.add') |
||
| 100 | @patch('napps.kytos.mef_eline.main.Main.uni_from_dict') |
||
| 101 | @patch('napps.kytos.mef_eline.storehouse.StoreHouse.save_evc') |
||
| 102 | @patch('napps.kytos.mef_eline.main.EVC.as_dict') |
||
| 103 | @patch('napps.kytos.mef_eline.models.EVC._validate') |
||
| 104 | def test_create_a_circuit_case_1(self, *args): |
||
| 105 | """Test create a new circuit.""" |
||
| 106 | (validate_mock, evc_as_dict_mock, save_evc_mock, |
||
| 107 | uni_from_dict_mock, sched_add_mock, storehouse_data_mock) = args |
||
| 108 | |||
| 109 | validate_mock.return_value = True |
||
| 110 | save_evc_mock.return_value = True |
||
| 111 | uni_from_dict_mock.side_effect = ['uni_a', 'uni_z'] |
||
| 112 | evc_as_dict_mock.return_value = {} |
||
| 113 | sched_add_mock.return_value = True |
||
| 114 | storehouse_data_mock.return_value = {} |
||
| 115 | |||
| 116 | api = self.get_app_test_client(self.napp) |
||
| 117 | url = f'{self.server_name_url}/v2/evc/' |
||
| 118 | payload = { |
||
| 119 | "name": "my evc1", |
||
| 120 | "frequency": "* * * * *", |
||
| 121 | "uni_a": { |
||
| 122 | "interface_id": "00:00:00:00:00:00:00:01:1", |
||
| 123 | "tag": { |
||
| 124 | "tag_type": 1, |
||
| 125 | "value": 80 |
||
| 126 | } |
||
| 127 | }, |
||
| 128 | "uni_z": { |
||
| 129 | "interface_id": "00:00:00:00:00:00:00:02:2", |
||
| 130 | "tag": { |
||
| 131 | "tag_type": 1, |
||
| 132 | "value": 1 |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | response = api.post(url, json=payload) |
||
| 138 | current_data = json.loads(response.data) |
||
| 139 | |||
| 140 | # verify expected result from request |
||
| 141 | self.assertEqual(201, response.status_code) |
||
| 142 | self.assertIn('circuit_id', current_data) |
||
| 143 | |||
| 144 | # verify uni called |
||
| 145 | uni_from_dict_mock.called_twice() |
||
| 146 | uni_from_dict_mock.assert_any_call(payload['uni_z']) |
||
| 147 | uni_from_dict_mock.assert_any_call(payload['uni_a']) |
||
| 148 | |||
| 149 | # verify validation called |
||
| 150 | validate_mock.assert_called_once() |
||
| 151 | validate_mock.assert_called_with(frequency='* * * * *', |
||
| 152 | name='my evc1', |
||
| 153 | uni_a='uni_a', |
||
| 154 | uni_z='uni_z') |
||
| 155 | # verify save method is called |
||
| 156 | save_evc_mock.assert_called_once() |
||
| 157 | |||
| 158 | # verify evc as dict is called to save in the box |
||
| 159 | evc_as_dict_mock.assert_called_once() |
||
| 160 | # verify add circuit in sched |
||
| 161 | sched_add_mock.assert_called_once() |
||
| 162 | |||
| 213 |