| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
""" |
| 14 |
test_data |
| 15 |
------------ |
| 16 |
|
| 17 |
Tests for `os_service_types.data` module. |
| 18 |
|
| 19 |
""" |
| 20 |
|
| 21 |
import json |
| 22 |
|
| 23 |
from os_service_types import data |
| 24 |
from os_service_types.tests import base |
| 25 |
|
| 26 |
|
| 27 |
class TestData(base.TestCase, base.TemporaryFileMixin): |
| 28 |
def setUp(self): |
| 29 |
super().setUp() |
| 30 |
|
| 31 |
def test_load(self): |
| 32 |
json_data = {'some_key': 'some_value'} |
| 33 |
filename = self.create_json(json_data) |
| 34 |
actual_data = data.read_data(filename) |
| 35 |
self.assertEqual(json_data, actual_data) |
| 36 |
|
| 37 |
def test_load_service_types(self): |
| 38 |
json_data = data.read_data('service-types.json') |
| 39 |
for key in [ |
| 40 |
"all_types_by_service_type", |
| 41 |
"forward", |
| 42 |
"primary_service_by_project", |
| 43 |
"reverse", |
| 44 |
]: |
| 45 |
self.assertIn(key, json_data) |
| 46 |
|
| 47 |
def test_load_non_existing(self): |
| 48 |
self.assertRaises( |
| 49 |
FileNotFoundError, data.read_data, '/non-existing-file' |
| 50 |
) |
| 51 |
|
| 52 |
def create_json(self, json_data): |
| 53 |
fd, name = self.create_temp_file(suffix='.json') |
| 54 |
with fd: |
| 55 |
json.dump(json_data, fd) |
| 56 |
return name |