Added tests for test_default_data.json

Part of bug 1210519

Change-Id: I4c6ee5fcccfaac1844a353ba5bb78131cd99f6eb
This commit is contained in:
Ilya Shakhat 2013-12-23 16:52:56 +04:00
parent 49f81f38ea
commit b251344cca
2 changed files with 30 additions and 13 deletions

View File

@ -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"

View File

@ -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')