def testValues(self): my_ordered_dict = OrderedDict() my_ordered_dict['nba_player'] = 'Steph Curry' my_ordered_dict['nba_mvp_count'] = 1 my_ordered_dict['is_retired'] = False my_ordered_dict['nba_finals_years'] = ['2015', '2016', '2017'] expected_values = ['Steph Curry', 1, False, ['2015', '2016', '2017']] values = my_ordered_dict.getValues() self.assertEqual( len(expected_values), len(values), 'expected the ordered dict values to be the same length as the expected values' ) for i, value in enumerate(values): self.assertEqual( value, expected_values[i], 'expected value at position %s to be %s' % (str(i), str(expected_values[i])))
def testOrderedDictSort(self): dict1 = OrderedDict() dict1[ 'SecurityConfig.myrealm.IoT-IDCS-Authenticator.ClientSecretEncrypted'] = '' dict1['AdminUserName'] = '' dict1['ServerTemp.ms-template.SSL.ListenPort'] = '8100' dict1['AdminPassword'] = '' dict1['JDBC.IoTServerDS.user.Value'] = 'admin' dict1['SecurityConfig.CredentialEncrypted'] = '' dict1['JDBC.IoTServerDS.PasswordEncrypted'] = '' dict1['SecurityConfig.NodeManagerUsername'] = '******' sorted_dict = OrderedDict() sorted_keys = dict1.keys() sorted_keys.sort() for key in sorted_keys: sorted_dict[key] = dict1[key] self.assertEqual(sorted_dict.getValues()[-1], '8100', 'expected dictionary to be sorted by name')