| 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
|
|---|
| 21 | import os
|
|---|
| 22 |
|
|---|
| 23 | from gnuboat_mapservice.server_impl import Config
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | class TestConfig(unittest.TestCase):
|
|---|
| 27 | def test_config_from_file(self):
|
|---|
| 28 | """Test case load config from file
|
|---|
| 29 | """
|
|---|
| 30 | new_config = {'TESTING': True, 'DOES_NOT_EXISTS': 1234}
|
|---|
| 31 |
|
|---|
| 32 | config = Config.Config()
|
|---|
| 33 | assert config.TESTING == False
|
|---|
| 34 |
|
|---|
| 35 | config_file = tempfile.NamedTemporaryFile(
|
|---|
| 36 | mode='w', prefix='gnuboat-test-config', delete=False
|
|---|
| 37 | )
|
|---|
| 38 | yaml.dump(
|
|---|
| 39 | new_config,
|
|---|
| 40 | config_file,
|
|---|
| 41 | default_flow_style=False,
|
|---|
| 42 | allow_unicode=True
|
|---|
| 43 | )
|
|---|
| 44 | config_file.close()
|
|---|
| 45 | config_file = os.path.join(tempfile.gettempdir(), config_file.name)
|
|---|
| 46 |
|
|---|
| 47 | config = Config.load_from_file(config_file)
|
|---|
| 48 | assert config.TESTING == True
|
|---|
| 49 | assert config.DOES_NOT_EXISTS == 1234
|
|---|
| 50 | os.remove(config_file)
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | if __name__ == '__main__':
|
|---|
| 54 | unittest.main()
|
|---|