Enforce alphabetical order in default data
* Default data users and companies are sorted * Tests are added Change-Id: I140a9858f4bdf34c335f19573bcd781e556668b4
This commit is contained in:
parent
3ad43d1d58
commit
4b27373ea2
File diff suppressed because it is too large
Load Diff
@ -22,12 +22,24 @@ 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:
|
||||
content = content_file.read()
|
||||
return json.loads(content)
|
||||
|
||||
def _verify_ordering(self, array, key, msg):
|
||||
sorted_array = sorted(array, key=key)
|
||||
diff_msg = None
|
||||
for i in range(0, len(array)):
|
||||
if array[i] != sorted_array[i]:
|
||||
diff_msg = ('First differing element %s:\n%s\n%s' %
|
||||
(i, array[i], sorted_array[i]))
|
||||
if diff_msg:
|
||||
self.fail(msg + '\n' + diff_msg)
|
||||
|
||||
def test_corrections(self):
|
||||
corrections = self._read_file('etc/corrections.json')
|
||||
schema = self._read_file('etc/corrections.schema.json')
|
||||
@ -37,3 +49,15 @@ class TestConfigFiles(testtools.TestCase):
|
||||
default_data = self._read_file('etc/default_data.json')
|
||||
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']
|
||||
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']
|
||||
self._verify_ordering(
|
||||
users, key=lambda x: x['launchpad_id'],
|
||||
msg='List of users should be ordered by launchpad id')
|
||||
|
Loading…
x
Reference in New Issue
Block a user