def test_canonical_profile_and_profiles_paths_provided(self): profiles = ( self.exposures_profile, self.accounts_profile, ) with NamedTemporaryFile( 'w') as exposures_profile_file, NamedTemporaryFile( 'w') as accounts_profile_file: with io.open(exposures_profile_file.name, 'w', encoding='utf-8') as f1, io.open( accounts_profile_file.name, 'w', encoding='utf-8') as f2: f1.write(u'{}'.format(json.dumps(self.exposures_profile))) f2.write(u'{}'.format(json.dumps(self.accounts_profile))) paths = ( exposures_profile_file.name, accounts_profile_file.name, ) cpft = unified_canonical_fm_profile_by_level(profiles=profiles, profile_paths=paths) self.assertEqual(self._depth(cpft), 4) fm_levels = set(p[l].get('FMLevel') for p in profiles for l in p if p[l].get('FMLevel')) self.assertEqual(fm_levels, set(cpft.keys())) for l in fm_levels: for _, v in cpft[l].items(): self.assertTrue( set(v.keys()).issuperset([ 'FMLevel', 'FMLevelName', 'FMTermGroupID', 'FMTermType' ])) self.assertEqual(l, v['FMLevel']) matching_profile_term = lambda t: ([ cpft[l][_t] for l in cpft for _t in cpft[l] if t.lower() == _t.lower() ][0] if [ cpft[l][_t] for l in cpft for _t in cpft[l] if t.lower() == _t.lower() ] else None) non_fm_terms = set(t for p in profiles for t in p if 'FMLevel' not in p[t]) for t in (_t for p in profiles for _t in p): pt = matching_profile_term(t) self.assertIsNotNone( pt) if t not in non_fm_terms else self.assertIsNone(pt)
def test_only_canonical_profiles_provided(self): profiles = ( self.exposures_profile, self.accounts_profile, ) cpft = unified_canonical_fm_profile_by_level(profiles=profiles) self.assertEqual(self._depth(cpft), 4) fm_levels = set(p[l].get('FMLevel') for p in profiles for l in p if p[l].get('FMLevel')) self.assertEqual(fm_levels, set(cpft.keys())) for l in fm_levels: for _, v in cpft[l].items(): self.assertTrue( set(v.keys()).issuperset([ 'FMLevel', 'FMLevelName', 'FMTermGroupID', 'FMTermType' ])) self.assertEqual(l, v['FMLevel']) matching_profile_term = lambda t: ([ cpft[l][_t] for l in cpft for _t in cpft[l] if t.lower() == _t.lower() ][0] if [ cpft[l][_t] for l in cpft for _t in cpft[l] if t.lower() == _t.lower() ] else None) non_fm_terms = set(t for p in profiles for t in p if 'FMLevel' not in p[t]) for t in (_t for p in profiles for _t in p): pt = matching_profile_term(t) self.assertIsNotNone( pt) if t not in non_fm_terms else self.assertIsNone(pt)
def test_no_canonical_profiles_or_profiles_paths_provided__oasis_exception_is_raised( self): with self.assertRaises(OasisException): unified_canonical_fm_profile_by_level()