From b251344cca8ec8ba8416f225d46bb9b1681e7e02 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Mon, 23 Dec 2013 16:52:56 +0400 Subject: [PATCH] Added tests for test_default_data.json Part of bug 1210519 Change-Id: I4c6ee5fcccfaac1844a353ba5bb78131cd99f6eb --- etc/test_default_data.json | 8 ++++---- tests/unit/test_config_files.py | 35 ++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/etc/test_default_data.json b/etc/test_default_data.json index 1ae22e398..b8525f11b 100644 --- a/etc/test_default_data.json +++ b/etc/test_default_data.json @@ -31,10 +31,6 @@ ], "companies": [ - { - "company_name": "Mirantis", - "domains": ["mirantis.com"] - }, { "company_name": "*independent", "domains": [""] @@ -47,6 +43,10 @@ "company_name": "Intel", "domains": ["intel.com"] }, + { + "company_name": "Mirantis", + "domains": ["mirantis.com"] + }, { "domains": ["robots"], "company_name": "*robots" diff --git a/tests/unit/test_config_files.py b/tests/unit/test_config_files.py index a0c9439aa..3e1c6d9dc 100644 --- a/tests/unit/test_config_files.py +++ b/tests/unit/test_config_files.py @@ -22,8 +22,6 @@ import testtools class TestConfigFiles(testtools.TestCase): def setUp(self): super(TestConfigFiles, self).setUp() - self.longMessage = True - self.maxDiff = 2048 def _read_file(self, file_name): with open(file_name, 'r') as content_file: @@ -33,7 +31,7 @@ class TestConfigFiles(testtools.TestCase): def _verify_ordering(self, array, key, msg): sorted_array = sorted(array, key=key) diff_msg = None - for i in range(0, len(array)): + for i in range(len(array)): if array[i] != sorted_array[i]: diff_msg = ('First differing element %s:\n%s\n%s' % (i, array[i], sorted_array[i])) @@ -45,19 +43,38 @@ class TestConfigFiles(testtools.TestCase): schema = self._read_file('etc/corrections.schema.json') jsonschema.validate(corrections, schema) - def test_default_data(self): - default_data = self._read_file('etc/default_data.json') + def _verify_default_data_by_schema(self, file_name): + default_data = self._read_file(file_name) schema = self._read_file('etc/default_data.schema.json') jsonschema.validate(default_data, schema) - def test_companies_in_alphabetical_order(self): - companies = self._read_file('etc/default_data.json')['companies'] + def test_default_data_schema_conformance(self): + self._verify_default_data_by_schema('etc/default_data.json') + + def test_test_default_data_schema_conformance(self): + self._verify_default_data_by_schema('etc/test_default_data.json') + + def _verify_companies_in_alphabetical_order(self, file_name): + companies = self._read_file(file_name)['companies'] self._verify_ordering( companies, key=lambda x: x['domains'][0], msg='List of companies should be ordered by the first domain') - def test_users_in_alphabetical_order(self): - users = self._read_file('etc/default_data.json')['users'] + def test_companies_in_alphabetical_order(self): + self._verify_companies_in_alphabetical_order('etc/default_data.json') + + def test_companies_in_alphabetical_order_in_test_file(self): + self._verify_companies_in_alphabetical_order( + 'etc/test_default_data.json') + + def _verify_users_in_alphabetical_order(self, file_name): + users = self._read_file(file_name)['users'] self._verify_ordering( users, key=lambda x: x['launchpad_id'], msg='List of users should be ordered by launchpad id') + + def test_users_in_alphabetical_order(self): + self._verify_users_in_alphabetical_order('etc/default_data.json') + + def test_users_in_alphabetical_order_in_test_file(self): + self._verify_users_in_alphabetical_order('etc/test_default_data.json')