| 1 |  |  | """ | 
            
                                                        
            
                                    
            
            
                | 2 |  |  | :Copyright: 2007-2020 Jochen Kupperschmidt | 
            
                                                        
            
                                    
            
            
                | 3 |  |  | :License: MIT, see LICENSE for details. | 
            
                                                        
            
                                    
            
            
                | 4 |  |  | """ | 
            
                                                        
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 6 |  |  | from io import StringIO | 
            
                                                        
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 8 |  |  | from weitersager.config import load_config | 
            
                                                        
            
                                    
            
            
                | 9 |  |  | from weitersager.irc import Channel, Config as IrcConfig, Server as IrcServer | 
            
                                                        
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 12 |  |  | TOML_CONFIG = '''\ | 
            
                                                        
            
                                    
            
            
                | 13 |  |  | [http] | 
            
                                                        
            
                                    
            
            
                | 14 |  |  | host = "127.0.0.1" | 
            
                                                        
            
                                    
            
            
                | 15 |  |  | port = 55555 | 
            
                                                        
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 17 |  |  | [irc.server] | 
            
                                                        
            
                                    
            
            
                | 18 |  |  | host = "orion.astrochat.test" | 
            
                                                        
            
                                    
            
            
                | 19 |  |  | port = 6669 | 
            
                                                        
            
                                    
            
            
                | 20 |  |  | password = "ToTheStars!" | 
            
                                                        
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 22 |  |  | [irc.bot] | 
            
                                                        
            
                                    
            
            
                | 23 |  |  | nickname = "SpaceCowboy" | 
            
                                                        
            
                                    
            
            
                | 24 |  |  | realname = "Monsieur Weitersager" | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 26 |  |  | [[irc.channels]] | 
            
                                                        
            
                                    
            
            
                | 27 |  |  | name = "#skyscreeners" | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 29 |  |  | [[irc.channels]] | 
            
                                                        
            
                                    
            
            
                | 30 |  |  | name = "#elite-astrology" | 
            
                                                        
            
                                    
            
            
                | 31 |  |  | password = "twinkle-twinkle" | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 33 |  |  | [[irc.channels]] | 
            
                                                        
            
                                    
            
            
                | 34 |  |  | name = "#hubblebubble" | 
            
                                                        
            
                                    
            
            
                | 35 |  |  | ''' | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 38 |  |  | def test_load_config(): | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |     toml = StringIO(TOML_CONFIG) | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |     irc_config, http_host, http_port = load_config(toml) | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |     assert irc_config == IrcConfig( | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |         server=IrcServer('orion.astrochat.test', 6669, 'ToTheStars!'), | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |         nickname='SpaceCowboy', | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |         realname='Monsieur Weitersager', | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         channels=[ | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |             Channel('#skyscreeners'), | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |             Channel('#elite-astrology', password='twinkle-twinkle'), | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |             Channel('#hubblebubble'), | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |         ], | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |     ) | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |     assert http_host == '127.0.0.1' | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |     assert http_port == 55555 | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 57 |  |  | TOML_CONFIG_WITH_DEFAULTS = '''\ | 
            
                                                        
            
                                    
            
            
                | 58 |  |  | [irc.server] | 
            
                                                        
            
                                    
            
            
                | 59 |  |  | host = "irc.onlinetalk.test" | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 61 |  |  | [irc.bot] | 
            
                                                        
            
                                    
            
            
                | 62 |  |  | nickname = "TownCrier" | 
            
                                                        
            
                                    
            
            
                | 63 |  |  | ''' | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 66 |  |  | def test_load_config_with_defaults(): | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |     toml = StringIO(TOML_CONFIG_WITH_DEFAULTS) | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |     irc_config, http_host, http_port = load_config(toml) | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |     assert irc_config == IrcConfig( | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |         server=IrcServer('irc.onlinetalk.test', 6667), | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |         nickname='TownCrier', | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |         realname='Weitersager', | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |         channels=[], | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |     ) | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |     assert http_host == '127.0.0.1' | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |     assert http_port == 8080 | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  |