| [096625e] | 1 | '''
|
|---|
| 2 | Copyright (C) 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 3 |
|
|---|
| 4 | This program is free software: you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 16 | '''
|
|---|
| 17 |
|
|---|
| 18 | import unittest
|
|---|
| 19 | import tempfile
|
|---|
| 20 | import yaml
|
|---|
| [adda9f2] | 21 | import os
|
|---|
| [096625e] | 22 |
|
|---|
| [adda9f2] | 23 | from gnuboat_mapservice.server_impl import Config
|
|---|
| [096625e] | 24 |
|
|---|
| 25 | class TestConfig(unittest.TestCase):
|
|---|
| 26 | def test_config_from_file(self):
|
|---|
| 27 | """Test case load config from file
|
|---|
| 28 | """
|
|---|
| 29 | new_config = {
|
|---|
| 30 | 'TESTING': True,
|
|---|
| 31 | 'DOES_NOT_EXISTS': 1234
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | config = Config.Config()
|
|---|
| 35 | assert config.TESTING == False
|
|---|
| 36 |
|
|---|
| 37 | config_file = tempfile.NamedTemporaryFile(mode='w', prefix='gnuboat-test-config', delete=False)
|
|---|
| 38 | yaml.dump(new_config, config_file, default_flow_style=False, allow_unicode=True)
|
|---|
| 39 | config_file.close()
|
|---|
| 40 | config_file = os.path.join(tempfile.gettempdir(), config_file.name)
|
|---|
| 41 |
|
|---|
| 42 | config = Config.load_from_file(config_file)
|
|---|
| 43 | assert config.TESTING == True
|
|---|
| 44 | assert config.DOES_NOT_EXISTS == 1234
|
|---|
| 45 | os.remove(config_file)
|
|---|
| 46 |
|
|---|
| 47 | if __name__ == '__main__':
|
|---|
| 48 | unittest.main()
|
|---|