| 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 |  |  | from datetime import datetime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | from napps.kytos.topology.db.models import DocumentBaseModel, SwitchDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | def test_document_base_model_dict() -> None: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     """test_document_base_model_dict.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     _id = "some_id" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     utcnow = datetime.utcnow() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     payload = {"_id": _id, "inserted_at": utcnow, "updated_at": utcnow} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     model = DocumentBaseModel(**payload) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     assert model.dict() == {**payload, **{"id": _id}} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     assert "_id" not in model.dict(exclude={"_id"}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | def test_switch_doc_preset_interfaces() -> None: | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     """test_switch_doc_preset_interfaces.""" | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     dpid = "00:00:00:00:00:00:00:01" | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     interface_id = f"{dpid}:1" | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     interfaces = { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         interface_id: { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             "id": interface_id, | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |             "port_number": 1, | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             "lldp": True, | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |             "enabled": True, | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |             "active": True, | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             "mac": "some_mac", | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |             "speed": 0, | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             "name": "some_name", | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             "switch": dpid, | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     payload = { | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         "_id": dpid, | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         "enabled": True, | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         "active": True, | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         "interfaces": interfaces, | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     model = SwitchDoc(**payload) | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     assert model | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     assert interface_id == model.interfaces[0].id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | def test_switch_doc_no_preset_interfaces() -> None: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     """test_switch_doc_no_preset_interfaces.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     dpid = "00:00:00:00:00:00:00:01" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     interfaces = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     payload = { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         "_id": dpid, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         "enabled": True, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         "active": True, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         "interfaces": interfaces, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     model = SwitchDoc(**payload) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     assert model | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  |     assert model.interfaces == interfaces | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  |