| Total Complexity | 6 | 
| Total Lines | 45 | 
| Duplicated Lines | 51.11 % | 
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | """Module to help to create tests."""  | 
            ||
| 2 | from unittest.mock import Mock  | 
            ||
| 3 | |||
| 4 | from kytos.core.config import KytosConfig  | 
            ||
| 5 | from kytos.core import Controller  | 
            ||
| 6 | |||
| 7 | |||
| 8 | def get_controller_mock():  | 
            ||
| 9 | """Return a controller mock."""  | 
            ||
| 10 | options = KytosConfig().options['daemon']  | 
            ||
| 11 | controller = Controller(options)  | 
            ||
| 12 | controller.log = Mock()  | 
            ||
| 13 | return controller  | 
            ||
| 14 | |||
| 15 | |||
| 16 | View Code Duplication | def get_napp_urls(napp):  | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 17 | """Return the kytos/topology urls.  | 
            ||
| 18 | |||
| 19 | The urls will be like:  | 
            ||
| 20 | |||
| 21 | urls = [  | 
            ||
| 22 | (options, methods, url)  | 
            ||
| 23 | ]  | 
            ||
| 24 | |||
| 25 | """  | 
            ||
| 26 | controller = napp.controller  | 
            ||
| 27 | controller.api_server.register_napp_endpoints(napp)  | 
            ||
| 28 | |||
| 29 | urls = []  | 
            ||
| 30 | for rule in controller.api_server.app.url_map.iter_rules():  | 
            ||
| 31 |         options = {} | 
            ||
| 32 | for arg in rule.arguments:  | 
            ||
| 33 |             options[arg] = "[{0}]".format(arg) | 
            ||
| 34 | |||
| 35 |         if f'{napp.username}/{napp.name}' in str(rule): | 
            ||
| 36 |             urls.append((options, rule.methods, f'{str(rule)}')) | 
            ||
| 37 | |||
| 38 | return urls  | 
            ||
| 39 | |||
| 40 | |||
| 41 | def get_app_test_client(napp):  | 
            ||
| 42 | """Return a flask api test client."""  | 
            ||
| 43 | napp.controller.api_server.register_napp_endpoints(napp)  | 
            ||
| 44 | return napp.controller.api_server.app.test_client()  | 
            ||
| 45 |