示例#1
0
    def test_canonical_profiles_and_profile_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_and_term_group(
                profiles=profiles, profile_paths=paths)

        self.assertEqual(self._depth(cpft), 5)

        fm_levels = set(p[l].get('FMLevel') for p in profiles for l in p
                        if p[l].get('FMLevel'))

        for l in fm_levels:
            for gid in cpft[l]:
                for tty, v in cpft[l][gid].items():
                    self.assertTrue(
                        set(v.keys()).issuperset([
                            'FMLevel', 'FMLevelName', 'FMTermGroupID',
                            'FMTermType'
                        ]))
                    self.assertEqual(l, v['FMLevel'])
                    self.assertEqual(gid, v['FMTermGroupID'])
                    self.assertEqual(tty, v['FMTermType'].lower())

        matching_profile_term = lambda t: ([
            cpft[l][gid][tty] for l in cpft for gid in cpft[l]
            for tty in cpft[l][gid] for _t in cpft[l][gid][tty]
            if t.lower() == cpft[l][gid][tty]['ProfileElementName'].lower()
        ][0] if [
            cpft[l][gid][tty] for l in cpft for gid in cpft[l]
            for tty in cpft[l][gid] for _t in cpft[l][gid][tty]
            if t.lower() == cpft[l][gid][tty]['ProfileElementName'].lower()
        ] else None)

        self.assertEqual(fm_levels, set(cpft.keys()))

        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)
示例#2
0
    def test_only_canonical_profiles_provided(self):
        profiles = (
            self.exposures_profile,
            self.accounts_profile,
        )

        cpft = unified_canonical_fm_profile_by_level_and_term_group(
            profiles=profiles)

        self.assertEqual(self._depth(cpft), 5)

        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 gid in cpft[l]:
                for tty, v in cpft[l][gid].items():
                    self.assertTrue(
                        set(v.keys()).issuperset([
                            'FMLevel', 'FMLevelName', 'FMTermGroupID',
                            'FMTermType'
                        ]))
                    self.assertEqual(l, v['FMLevel'])
                    self.assertEqual(gid, v['FMTermGroupID'])
                    self.assertEqual(tty, v['FMTermType'].lower())

        matching_profile_term = lambda t: ([
            cpft[l][gid][tty] for l in cpft for gid in cpft[l]
            for tty in cpft[l][gid] for _t in cpft[l][gid][tty]
            if t.lower() == cpft[l][gid][tty]['ProfileElementName'].lower()
        ][0] if [
            cpft[l][gid][tty] for l in cpft for gid in cpft[l]
            for tty in cpft[l][gid] for _t in cpft[l][gid][tty]
            if t.lower() == cpft[l][gid][tty]['ProfileElementName'].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)
示例#3
0
 def setUp(self):
     self.exposures_profile = canonical_exposures_profile
     self.accounts_profile = canonical_accounts_profile
     self.unified_canonical_profile = unified_canonical_fm_profile_by_level_and_term_group(
         profiles=[self.exposures_profile, self.accounts_profile])
     self.fm_agg_profile = oasis_fm_agg_profile
示例#4
0
 def test_no_canonical_profiles_or_profile_paths_provided__oasis_exception_is_raised(
         self):
     with self.assertRaises(OasisException):
         unified_canonical_fm_profile_by_level_and_term_group()