Add some basic unittests for metadata sanity #50
@ -1,3 +1,19 @@
 | 
				
			|||||||
 | 
					# Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 | 
					# you may not use this file except in compliance with the License.
 | 
				
			||||||
 | 
					# You may obtain a copy of the License at
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#    http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 | 
					# distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 | 
					# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 | 
				
			||||||
 | 
					# implied.
 | 
				
			||||||
 | 
					# See the License for the specific language governing permissions and
 | 
				
			||||||
 | 
					# limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Please consult with otc_metadata.services.Services:_sort_data for expected
 | 
				
			||||||
 | 
					# sort order. When unsure perform tools/sort_metadata.py for getting it sorted.
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
documents:
 | 
					documents:
 | 
				
			||||||
  - hc_location: api/antiddos
 | 
					  - hc_location: api/antiddos
 | 
				
			||||||
    html_location: docs/antiddos/api-ref
 | 
					    html_location: docs/antiddos/api-ref
 | 
				
			||||||
@ -1021,6 +1037,8 @@ service_categories:
 | 
				
			|||||||
    title: Security Services
 | 
					    title: Security Services
 | 
				
			||||||
  - name: storage
 | 
					  - name: storage
 | 
				
			||||||
    title: Storage
 | 
					    title: Storage
 | 
				
			||||||
 | 
					  - name: other
 | 
				
			||||||
 | 
					    title: Other
 | 
				
			||||||
services:
 | 
					services:
 | 
				
			||||||
  - repositories:
 | 
					  - repositories:
 | 
				
			||||||
      - environment: internal
 | 
					      - environment: internal
 | 
				
			||||||
 | 
				
			|||||||
@ -21,8 +21,45 @@ Tests for `otc-metadata` module.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from unittest import TestCase
 | 
					from unittest import TestCase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from otc_metadata import services
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestOtcMetadata(TestCase):
 | 
					class TestOtcMetadata(TestCase):
 | 
				
			||||||
 | 
					    def setUp(self):
 | 
				
			||||||
 | 
					        self.data = services.Services()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_something(self):
 | 
					    def test_data_is_sorted(self):
 | 
				
			||||||
        pass
 | 
					        curr = self.data
 | 
				
			||||||
 | 
					        new = services.Services()
 | 
				
			||||||
 | 
					        new._sort_data()
 | 
				
			||||||
 | 
					        self.assertEqual(
 | 
				
			||||||
 | 
					            curr._service_data, new._service_data, "Data is sorted properly"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_service_categories(self):
 | 
				
			||||||
 | 
					        category = dict()
 | 
				
			||||||
 | 
					        for cat in self.data._service_data["service_categories"]:
 | 
				
			||||||
 | 
					            category[cat["name"]] = cat["title"]
 | 
				
			||||||
 | 
					        for srv in self.data.all_services:
 | 
				
			||||||
 | 
					            self.assertTrue(
 | 
				
			||||||
 | 
					                srv["service_category"] in category,
 | 
				
			||||||
 | 
					                f"Category {srv['service_category']} is present",
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_doc_contains_required_data(self):
 | 
				
			||||||
 | 
					        srv_types = dict()
 | 
				
			||||||
 | 
					        for srv in self.data.all_services:
 | 
				
			||||||
 | 
					            srv_types[srv["service_type"]] = srv
 | 
				
			||||||
 | 
					        for doc in self.data.all_docs:
 | 
				
			||||||
 | 
					            for attr in [
 | 
				
			||||||
 | 
					                "rst_location",
 | 
				
			||||||
 | 
					                "service_type",
 | 
				
			||||||
 | 
					                "title",
 | 
				
			||||||
 | 
					                "type",
 | 
				
			||||||
 | 
					            ]:
 | 
				
			||||||
 | 
					                self.assertIn(attr, doc, f"Document {doc} contains {attr}")
 | 
				
			||||||
 | 
					            self.assertIn(
 | 
				
			||||||
 | 
					                doc["service_type"],
 | 
				
			||||||
 | 
					                srv_types,
 | 
				
			||||||
 | 
					                f"Document {doc} contains valid service_type",
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								tox.ini
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tox.ini
									
									
									
									
									
								
							@ -19,7 +19,6 @@ commands = {posargs}
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[flake8]
 | 
					[flake8]
 | 
				
			||||||
# E123, E125 skipped as they are invalid PEP-8.
 | 
					# E123, E125 skipped as they are invalid PEP-8.
 | 
				
			||||||
 | 
					 | 
				
			||||||
show-source = True
 | 
					show-source = True
 | 
				
			||||||
ignore = E123,E125,W503
 | 
					ignore = E123,E125,W503
 | 
				
			||||||
builtins = _
 | 
					builtins = _
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user