Added tests for test_default_data.json
Part of bug 1210519 Change-Id: I4c6ee5fcccfaac1844a353ba5bb78131cd99f6eb
This commit is contained in:
parent
49f81f38ea
commit
b251344cca
@ -31,10 +31,6 @@
|
|||||||
],
|
],
|
||||||
|
|
||||||
"companies": [
|
"companies": [
|
||||||
{
|
|
||||||
"company_name": "Mirantis",
|
|
||||||
"domains": ["mirantis.com"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"company_name": "*independent",
|
"company_name": "*independent",
|
||||||
"domains": [""]
|
"domains": [""]
|
||||||
@ -47,6 +43,10 @@
|
|||||||
"company_name": "Intel",
|
"company_name": "Intel",
|
||||||
"domains": ["intel.com"]
|
"domains": ["intel.com"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"company_name": "Mirantis",
|
||||||
|
"domains": ["mirantis.com"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"domains": ["robots"],
|
"domains": ["robots"],
|
||||||
"company_name": "*robots"
|
"company_name": "*robots"
|
||||||
|
@ -22,8 +22,6 @@ import testtools
|
|||||||
class TestConfigFiles(testtools.TestCase):
|
class TestConfigFiles(testtools.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestConfigFiles, self).setUp()
|
super(TestConfigFiles, self).setUp()
|
||||||
self.longMessage = True
|
|
||||||
self.maxDiff = 2048
|
|
||||||
|
|
||||||
def _read_file(self, file_name):
|
def _read_file(self, file_name):
|
||||||
with open(file_name, 'r') as content_file:
|
with open(file_name, 'r') as content_file:
|
||||||
@ -33,7 +31,7 @@ class TestConfigFiles(testtools.TestCase):
|
|||||||
def _verify_ordering(self, array, key, msg):
|
def _verify_ordering(self, array, key, msg):
|
||||||
sorted_array = sorted(array, key=key)
|
sorted_array = sorted(array, key=key)
|
||||||
diff_msg = None
|
diff_msg = None
|
||||||
for i in range(0, len(array)):
|
for i in range(len(array)):
|
||||||
if array[i] != sorted_array[i]:
|
if array[i] != sorted_array[i]:
|
||||||
diff_msg = ('First differing element %s:\n%s\n%s' %
|
diff_msg = ('First differing element %s:\n%s\n%s' %
|
||||||
(i, array[i], sorted_array[i]))
|
(i, array[i], sorted_array[i]))
|
||||||
@ -45,19 +43,38 @@ class TestConfigFiles(testtools.TestCase):
|
|||||||
schema = self._read_file('etc/corrections.schema.json')
|
schema = self._read_file('etc/corrections.schema.json')
|
||||||
jsonschema.validate(corrections, schema)
|
jsonschema.validate(corrections, schema)
|
||||||
|
|
||||||
def test_default_data(self):
|
def _verify_default_data_by_schema(self, file_name):
|
||||||
default_data = self._read_file('etc/default_data.json')
|
default_data = self._read_file(file_name)
|
||||||
schema = self._read_file('etc/default_data.schema.json')
|
schema = self._read_file('etc/default_data.schema.json')
|
||||||
jsonschema.validate(default_data, schema)
|
jsonschema.validate(default_data, schema)
|
||||||
|
|
||||||
def test_companies_in_alphabetical_order(self):
|
def test_default_data_schema_conformance(self):
|
||||||
companies = self._read_file('etc/default_data.json')['companies']
|
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(
|
self._verify_ordering(
|
||||||
companies, key=lambda x: x['domains'][0],
|
companies, key=lambda x: x['domains'][0],
|
||||||
msg='List of companies should be ordered by the first domain')
|
msg='List of companies should be ordered by the first domain')
|
||||||
|
|
||||||
def test_users_in_alphabetical_order(self):
|
def test_companies_in_alphabetical_order(self):
|
||||||
users = self._read_file('etc/default_data.json')['users']
|
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(
|
self._verify_ordering(
|
||||||
users, key=lambda x: x['launchpad_id'],
|
users, key=lambda x: x['launchpad_id'],
|
||||||
msg='List of users should be ordered by 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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user