| 
                    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
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    11
                 | 
                                    
                             1                          | 
                
                 | 
                def test_document_base_model_dict() -> None:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    12
                 | 
                                    
                                                     | 
                
                 | 
                    """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
                 | 
                                    
                             1                          | 
                
                 | 
                    assert "_id" not in model.dict(exclude={"_id"}) | 
            
            
                                                        
            
                                    
            
            
                | 
                    19
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    20
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    21
                 | 
                                    
                             1                          | 
                
                 | 
                def test_switch_doc_preset_interfaces() -> None:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    22
                 | 
                                    
                                                     | 
                
                 | 
                    """test_switch_doc_preset_interfaces."""  | 
            
            
                                                        
            
                                    
            
            
                | 
                    23
                 | 
                                    
                             1                          | 
                
                 | 
                    dpid = "00:00:00:00:00:00:00:01"  | 
            
            
                                                        
            
                                    
            
            
                | 
                    24
                 | 
                                    
                             1                          | 
                
                 | 
                    interface_id = f"{dpid}:1" | 
            
            
                                                        
            
                                    
            
            
                | 
                    25
                 | 
                                    
                             1                          | 
                
                 | 
                    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
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    38
                 | 
                                    
                             1                          | 
                
                 | 
                    payload = { | 
            
            
                                                        
            
                                    
            
            
                | 
                    39
                 | 
                                    
                                                     | 
                
                 | 
                        "_id": dpid,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    40
                 | 
                                    
                                                     | 
                
                 | 
                        "enabled": True,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    41
                 | 
                                    
                                                     | 
                
                 | 
                        "active": True,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    42
                 | 
                                    
                                                     | 
                
                 | 
                        "interfaces": interfaces,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    43
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    44
                 | 
                                    
                             1                          | 
                
                 | 
                    model = SwitchDoc(**payload)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    45
                 | 
                                    
                             1                          | 
                
                 | 
                    assert model  | 
            
            
                                                        
            
                                    
            
            
                | 
                    46
                 | 
                                    
                             1                          | 
                
                 | 
                    assert interface_id == model.interfaces[0].id  | 
            
            
                                                        
            
                                    
            
            
                | 
                    47
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    48
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    49
                 | 
                                    
                             1                          | 
                
                 | 
                def test_switch_doc_no_preset_interfaces() -> None:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    50
                 | 
                                    
                                                     | 
                
                 | 
                    """test_switch_doc_no_preset_interfaces."""  | 
            
            
                                                        
            
                                    
            
            
                | 
                    51
                 | 
                                    
                             1                          | 
                
                 | 
                    dpid = "00:00:00:00:00:00:00:01"  | 
            
            
                                                        
            
                                    
            
            
                | 
                    52
                 | 
                                    
                             1                          | 
                
                 | 
                    interfaces = []  | 
            
            
                                                        
            
                                    
            
            
                | 
                    53
                 | 
                                    
                             1                          | 
                
                 | 
                    payload = { | 
            
            
                                                        
            
                                    
            
            
                | 
                    54
                 | 
                                    
                                                     | 
                
                 | 
                        "_id": dpid,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    55
                 | 
                                    
                                                     | 
                
                 | 
                        "enabled": True,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    56
                 | 
                                    
                                                     | 
                
                 | 
                        "active": True,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    57
                 | 
                                    
                                                     | 
                
                 | 
                        "interfaces": interfaces,  | 
            
            
                                                        
            
                                    
            
            
                | 
                    58
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    59
                 | 
                                    
                             1                          | 
                
                 | 
                    model = SwitchDoc(**payload)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    60
                 | 
                                    
                             1                          | 
                
                 | 
                    assert model  | 
            
            
                                                        
            
                                    
            
            
                | 
                    61
                 | 
                                    
                             1                          | 
                
                 | 
                    assert model.interfaces == interfaces  | 
            
            
                                                        
            
                                    
            
            
                | 
                    62
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    63
                 | 
                                    
                                                     | 
                
                 | 
                 | 
            
            
                                                        
            
                                    
            
            
                | 
                    64
                 | 
                                    
                             1                          | 
                
                 | 
                def test_interface_detail_doc() -> None:  | 
            
            
                                                        
            
                                    
            
            
                | 
                    65
                 | 
                                    
                                                     | 
                
                 | 
                    """Test InterfaceDetailDoc"""  | 
            
            
                                                        
            
                                    
            
            
                | 
                    66
                 | 
                                    
                             1                          | 
                
                 | 
                    payload = { | 
            
            
                                                        
            
                                    
            
            
                | 
                    67
                 | 
                                    
                                                     | 
                
                 | 
                        "available_tags": {"vlan": [[200, 300], [500, 550]]}, | 
            
            
                                                        
            
                                    
            
            
                | 
                    68
                 | 
                                    
                                                     | 
                
                 | 
                        "tag_ranges": {"vlan": [[100, 4095]]}, | 
            
            
                                                        
            
                                    
            
            
                | 
                    69
                 | 
                                    
                                                     | 
                
                 | 
                        "special_available_tags": {"vlan": ["any"]} | 
            
            
                                                        
            
                                    
            
            
                | 
                    70
                 | 
                                    
                                                     | 
                
                 | 
                    }  | 
            
            
                                                        
            
                                    
            
            
                | 
                    71
                 | 
                                    
                             1                          | 
                
                 | 
                    model = InterfaceDetailDoc(**payload)  | 
            
            
                                                        
            
                                    
            
            
                | 
                    72
                 | 
                                    
                                                     | 
                
                 | 
                    assert model  | 
            
            
                                                        
            
                                    
            
            
                | 
                    73
                 | 
                                    
                                                     | 
                
                 | 
                 |