| 1 |  |  | """This test suite cover the db models, however, most have been | 
            
                                                        
            
                                    
            
            
                | 2 |  |  | indirectly tested on test_main.py, so for now it's mostly to cover | 
            
                                                        
            
                                    
            
            
                | 3 |  |  | the remaning parts.""" | 
            
                                                        
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 5 | 1 |  | from datetime import datetime | 
            
                                                        
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 7 | 1 |  | from napps.kytos.topology.db.models import (DocumentBaseModel, | 
            
                                                        
            
                                    
            
            
                | 8 |  |  |                                             InterfaceDetailDoc, SwitchDoc) | 
            
                                                        
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 10 | 1 |  |  | 
            
                                                        
            
                                    
            
            
                | 11 |  |  | def test_document_base_model_dict() -> None: | 
            
                                                        
            
                                    
            
            
                | 12 | 1 |  |     """test_document_base_model_dict.""" | 
            
                                                        
            
                                    
            
            
                | 13 | 1 |  |     _id = "some_id" | 
            
                                                        
            
                                    
            
            
                | 14 | 1 |  |     utcnow = datetime.utcnow() | 
            
                                                        
            
                                    
            
            
                | 15 | 1 |  |     payload = {"_id": _id, "inserted_at": utcnow, "updated_at": utcnow} | 
            
                                                        
            
                                    
            
            
                | 16 | 1 |  |     model = DocumentBaseModel(**payload) | 
            
                                                        
            
                                    
            
            
                | 17 | 1 |  |     assert model.dict() == {**payload, **{"id": _id}} | 
            
                                                        
            
                                    
            
            
                | 18 |  |  |     assert "_id" not in model.dict(exclude={"_id"}) | 
            
                                                        
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 20 | 1 |  |  | 
            
                                                        
            
                                    
            
            
                | 21 |  |  | def test_switch_doc_preset_interfaces() -> None: | 
            
                                                        
            
                                    
            
            
                | 22 | 1 |  |     """test_switch_doc_preset_interfaces.""" | 
            
                                                        
            
                                    
            
            
                | 23 | 1 |  |     dpid = "00:00:00:00:00:00:00:01" | 
            
                                                        
            
                                    
            
            
                | 24 | 1 |  |     interface_id = f"{dpid}:1" | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |     interfaces = { | 
            
                                                        
            
                                    
            
            
                | 26 |  |  |         interface_id: { | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |             "id": interface_id, | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |             "port_number": 1, | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |             "lldp": True, | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |             "enabled": True, | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |             "active": True, | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |             "mac": "some_mac", | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |             "speed": 0, | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |             "name": "some_name", | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |             "switch": dpid, | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 37 | 1 |  |     } | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |     payload = { | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |         "_id": dpid, | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |         "enabled": True, | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |         "active": True, | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |         "interfaces": interfaces, | 
            
                                                        
            
                                    
            
            
                | 43 | 1 |  |     } | 
            
                                                        
            
                                    
            
            
                | 44 | 1 |  |     model = SwitchDoc(**payload) | 
            
                                                        
            
                                    
            
            
                | 45 | 1 |  |     assert model | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |     assert interface_id == model.interfaces[0].id | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 48 | 1 |  |  | 
            
                                                        
            
                                    
            
            
                | 49 |  |  | def test_switch_doc_no_preset_interfaces() -> None: | 
            
                                                        
            
                                    
            
            
                | 50 | 1 |  |     """test_switch_doc_no_preset_interfaces.""" | 
            
                                                        
            
                                    
            
            
                | 51 | 1 |  |     dpid = "00:00:00:00:00:00:00:01" | 
            
                                                        
            
                                    
            
            
                | 52 | 1 |  |     interfaces = [] | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |     payload = { | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         "_id": dpid, | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |         "enabled": True, | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         "active": True, | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |         "interfaces": interfaces, | 
            
                                                        
            
                                    
            
            
                | 58 | 1 |  |     } | 
            
                                                        
            
                                    
            
            
                | 59 | 1 |  |     model = SwitchDoc(**payload) | 
            
                                                        
            
                                    
            
            
                | 60 | 1 |  |     assert model | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |     assert model.interfaces == interfaces | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 64 |  |  | def test_interface_detail_doc() -> None: | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |     """Test InterfaceDetailDoc""" | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |     payload = { | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |         "available_tags": {"vlan": [[200, 300], [500, 550]]}, | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |         "tag_ranges": {"vlan": [[100, 4095]]}, | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |         "special_available_tags": {"vlan": ["any"]}, | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |         "special_tags": {"vlan": ["any", "untagged"]} | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |     model = InterfaceDetailDoc(**payload) | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |     assert model | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  |