Exemple #1
0
 def __init__(self, *args, **kwargs):
     super(LanguageSetForm, self).__init__(*args, **kwargs)
     inventory_manager = InventoryManager()
     self.fields['locale_ids'].choices = tuple([
         (locale.locale_id, locale.lang_name)
         for locale in inventory_manager.get_locales()
     ])
Exemple #2
0
 def __init__(self, *args, **kwargs):
     super(UpdatePackageForm, self).__init__(*args, **kwargs)
     inventory_manager = InventoryManager()
     self.fields[
         'platform_slug'].choices = inventory_manager.get_transplatform_slug_url(
         )
     self.fields[
         'products'].choices = inventory_manager.get_relstream_slug_name()
Exemple #3
0
 def __init__(self, *args, **kwargs):
     inventory_manager = InventoryManager()
     lang_sets = inventory_manager.get_langsets(
         ['lang_set_slug', 'lang_set_name'])
     self.lang_set_choices = tuple([(lang_set.lang_set_slug,
                                     lang_set.lang_set_name)
                                    for lang_set in lang_sets])
     super(StreamBranchesAdminForm, self).__init__(*args, **kwargs)
     self.fields['lang_set'].choices = self.lang_set_choices
Exemple #4
0
class ManagersMixin(object):
    """
    Managers Mixin
    """
    inventory_manager = InventoryManager()
    packages_manager = PackagesManager()
    jobs_log_manager = JobsLogManager()
    release_branch_manager = ReleaseBranchManager()
    graph_manager = GraphManager()

    def get_summary(self):
        """
        Application Inventory Stats
        """
        locales_set = self.inventory_manager.get_locales_set()
        summary = {}
        summary['locales_len'] = len(locales_set[0]) \
            if isinstance(locales_set, tuple) else 0
        platforms = self.inventory_manager.get_transplatform_slug_url()
        summary['platforms_len'] = len(platforms) if platforms else 0
        relstreams = self.inventory_manager.get_relstream_slug_name()
        summary['products_len'] = len(relstreams) if relstreams else 0
        relbranches = self.release_branch_manager.get_release_branches()
        summary['releases_len'] = relbranches.count() if relbranches else 0
        summary['packages_len'] = self.packages_manager.count_packages()
        jobs_count, last_ran_on, last_ran_type = \
            self.jobs_log_manager.get_joblog_stats()
        summary['jobs_len'] = jobs_count
        graph_rules = self.graph_manager.get_graph_rules(only_active=True)
        summary['graph_rules_len'] = graph_rules.count() if graph_rules else 0
        return summary
Exemple #5
0
class ManagersMixin(object):
    """
    Managers Mixin
    """
    inventory_manager = InventoryManager()
    packages_manager = PackagesManager()
    jobs_log_manager = JobsLogManager()
    release_branch_manager = ReleaseBranchManager()
    graph_manager = GraphManager()
Exemple #6
0
class InventoryManagerTest(FixtureTestCase):

    inventory_manager = InventoryManager()
    fixture = db_fixture
    datasets = [
        LanguageData, LanguageSetData, PlatformData, ProductData, ReleaseData
    ]

    def test_get_locales(self):
        """
        Test get_locales
        """
        japanese_locale = self.inventory_manager.get_locales(
            pick_locales=['ja_JP'])
        self.assertEqual(len(japanese_locale), 1)
        self.assertEqual(japanese_locale[0].lang_name, 'Japanese')
        self.assertEqual(japanese_locale[0].locale_alias, 'ja')
        self.assertEqual(japanese_locale[0].locale_script, 'Hani')

    def test_get_active_locales_count(self):
        """
        Test get_active_locales_count
        """
        active_locales = self.inventory_manager.get_active_locales_count()
        self.assertEqual(active_locales, 3)

    def test_get_locale_alias(self):
        """
        Test get_locale_alias
        """
        locale_alias = self.inventory_manager.get_locale_alias('fr_FR')
        self.assertEqual(locale_alias, 'fr')

        locale_alias = self.inventory_manager.get_locale_alias('de_DE')
        self.assertEqual(locale_alias, 'de_DE')

    def test_get_alias_locale(self):
        """
        Test get_alias_locale
        """
        alias_locale = self.inventory_manager.get_alias_locale('fr')
        self.assertEqual(alias_locale, 'fr_FR')

        alias_locale = self.inventory_manager.get_alias_locale('de_DE')
        self.assertEqual(alias_locale, 'de_DE')

    def test_get_locales_set(self):
        """
        Test get_locales_set
        """
        active_locales, inactive_locales, aliases = \
            self.inventory_manager.get_locales_set()
        self.assertEqual(len(active_locales), 3)
        self.assertEqual(len(inactive_locales), 1)
        self.assertEqual(len(aliases), 4)

    def test_get_locale_lang_tuple(self):
        """
        Test get_locale_lang_tuple
        """
        ru_tuple = ('ru_RU', 'Russian')
        fr_tuple = ('fr_FR', 'French')
        locale_lang_tuple = self.inventory_manager.get_locale_lang_tuple()
        self.assertEqual(len(locale_lang_tuple), 3)

        locale_lang_tuple = self.inventory_manager.get_locale_lang_tuple(
            locales=['fr_FR', 'ru_RU'])
        self.assertEqual(len(locale_lang_tuple), 2)
        self.assertTupleEqual(locale_lang_tuple[0], ru_tuple)
        self.assertTupleEqual(locale_lang_tuple[1], fr_tuple)

    def test_get_langset(self):
        """
        Test get_get_langset
        """
        lang_set = self.inventory_manager.get_langset(
            langset_slug='custom-set')
        self.assertEqual(lang_set.lang_set_name, 'Custom Set')
        self.assertEqual(lang_set.lang_set_color, 'Peru')

    def test_get_langsets(self):
        """
        Test get_langsets
        """
        lang_sets = self.inventory_manager.get_langsets(
            fields=['lang_set_name', 'locale_ids'])
        self.assertEqual(len(lang_sets), 2)
        self.assertNotIn('lang_set_color', vars(lang_sets[0]))
        self.assertListEqual(lang_sets[0].locale_ids, ['fr_FR', 'ja_JP'])

    def test_get_locale_groups(self):
        """
        Test get_locale_groups
        """
        locale_groups = self.inventory_manager.get_locale_groups('ja_JP')
        self.assertDictEqual(locale_groups,
                             {'ja_JP': ['custom-set', 'f27-set']})

    def test_get_all_locales_groups(self):
        """
        Test get_all_locales_groups
        """
        groups_of_all_locales = self.inventory_manager.get_all_locales_groups()
        self.assertDictEqual(
            groups_of_all_locales, {
                'ja_JP': ['custom-set', 'f27-set'],
                'fr_FR': ['custom-set', 'f27-set'],
                'ru_RU': ['f27-set'],
                'ko_KR': []
            })

    def test_get_translation_platforms(self):
        """
        Test get_translation_platforms
        """
        transplatforms = self.inventory_manager.get_translation_platforms(
            engine='zanata')
        self.assertEqual(transplatforms[1].api_url,
                         'https://translate.zanata.org')
        self.assertEqual(transplatforms[1].platform_slug, 'ZNTAPUB')

    def test_get_transplatforms_set(self):
        """
        Test get_transplatforms_set
        """
        active_platforms, inactive_platforms = self.inventory_manager.get_transplatforms_set(
        )
        self.assertEqual(len(active_platforms), 2)
        self.assertEqual(len(inactive_platforms), 0)

    def test_get_transplatform_slug_url(self):
        """
        test get_transplatform_slug_url
        """
        slug_url_tuple = self.inventory_manager.get_transplatform_slug_url()
        self.assertTupleEqual(slug_url_tuple,
                              (('ZNTAFED', 'https://fedora.zanata.org'),
                               ('ZNTAPUB', 'https://translate.zanata.org')))

    def test_get_relbranch_locales(self):
        """
        Test get_relbranch_locales
        """
        relbranch_locales = self.inventory_manager.get_relbranch_locales(
            "nonexisting-relbranch")
        self.assertFalse(relbranch_locales)
        relbranch_locales = self.inventory_manager.get_relbranch_locales(
            'fedora-27')
        self.assertListEqual(relbranch_locales, ['ja_JP', 'fr_FR', 'ru_RU'])

    def test_get_release_streams(self):
        """
        Test get_release_streams
        """
        relstream_fedora = Product.objects.get(product_name='Fedora')
        relstream_rhel = Product.objects.get(product_name='RHEL')

        release_streams = self.inventory_manager.get_release_streams()
        self.assertEqual(len(release_streams), 2)
        self.assertIn(relstream_fedora, release_streams)
        self.assertIn(relstream_rhel, release_streams)

        release_streams = self.inventory_manager.get_release_streams(
            stream_slug='RHEL')
        self.assertEqual(len(release_streams), 1)
        self.assertIn(relstream_rhel, release_streams)

        release_streams = self.inventory_manager.get_release_streams(
            only_active=True)
        self.assertEqual(len(release_streams), 1)
        self.assertIn(relstream_fedora, release_streams)

    def test_get_relstream_slug_name(self):
        """
        Test get_relstream_slug_name
        """
        relstream_slug_name_tuple = self.inventory_manager.get_relstream_slug_name(
        )
        self.assertEqual(len(relstream_slug_name_tuple), 1)
        self.assertTupleEqual(relstream_slug_name_tuple[0],
                              ('fedora', 'Fedora'))

    def test_get_relstream_build_tags(self):
        """
        Test get_relstream_build_tags
        """
        tags = self.inventory_manager.get_relstream_build_tags(
            stream_slug='fedora')
        self.assertIsInstance(tags, dict)
        self.assertDictEqual(tags, {'fedora': ['f28', 'f29', 'rawhide']})
Exemple #7
0
 def __init__(self, *args, **kwargs):
     inventory_manager = InventoryManager()
     self.locale_choices = tuple([(locale.locale_id, locale.lang_name)
                                  for locale in inventory_manager.get_locales()])
     super(LanguageSetAdminForm, self).__init__(*args, **kwargs)
     self.fields['locale_ids'].choices = self.locale_choices
class InventoryTest(TestCase):

    inventory_manager = InventoryManager()

    def setUp(self):
        """
        Lets dump some test data in db
        """
        Languages.objects.update_or_create(locale_id='ja_JP',
                                           lang_name='Japanese',
                                           locale_alias='ja',
                                           lang_status=True)

        Languages.objects.update_or_create(locale_id='fr_FR',
                                           lang_name='French',
                                           locale_alias='fr',
                                           lang_status=False)

        LanguageSet.objects.update_or_create(lang_set_name='Custom Set',
                                             lang_set_slug='custom-set',
                                             lang_set_color='Peru',
                                             locale_ids=['fr_FR', 'ja_JP'])

        TransPlatform.objects.update_or_create(
            engine_name='zanata',
            subject='public',
            api_url='https://translate.zanata.org',
            platform_slug='ZNTAPUB',
            server_status=True)

    def test_get_locales(self):
        """
        Test get_locales
        """
        japanese_locale = self.inventory_manager.get_locales(
            pick_locales=['ja_JP'])
        self.assertEqual(japanese_locale[0].lang_name, 'Japanese')
        self.assertEqual(japanese_locale[0].locale_alias, 'ja')

    def test_get_locale_alias(self):
        """
        Test get_locale_alias
        """
        locale_alias = self.inventory_manager.get_locale_alias('fr_FR')
        self.assertEqual(locale_alias, 'fr')

        locale_alias = self.inventory_manager.get_locale_alias('de_DE')
        self.assertEqual(locale_alias, 'de_DE')

    def test_get_locales_set(self):
        """
        Test get_locales_set
        """
        active_locales, inactive_locales, aliases = \
            self.inventory_manager.get_locales_set()
        self.assertEqual(len(active_locales), 1)
        self.assertEqual(len(inactive_locales), 1)
        self.assertEqual(len(aliases), 2)

    def test_get_langset(self):
        """
        Test get_get_langset
        """
        lang_set = self.inventory_manager.get_langset(
            langset_slug='custom-set')
        self.assertEqual(lang_set.lang_set_name, 'Custom Set')
        self.assertEqual(lang_set.lang_set_color, 'Peru')

    def test_get_langsets(self):
        """
        Test get_langsets
        """
        lang_sets = self.inventory_manager.get_langsets(
            fields=['lang_set_name', 'locale_ids'])
        self.assertEqual(len(lang_sets), 1)
        self.assertNotIn('lang_set_color', vars(lang_sets[0]))
        self.assertListEqual(lang_sets[0].locale_ids, ['fr_FR', 'ja_JP'])

    def test_get_locale_groups(self):
        """
        Test get_locale_groups
        """
        locale_groups = self.inventory_manager.get_locale_groups('ja_JP')
        self.assertDictEqual(locale_groups, {'ja_JP': ['custom-set']})

    def test_get_all_locales_groups(self):
        """
        Test get_all_locales_groups
        """
        groups_of_all_locales = self.inventory_manager.get_all_locales_groups()
        self.assertDictEqual(groups_of_all_locales, {
            'ja_JP': ['custom-set'],
            'fr_FR': ['custom-set']
        })

    def test_get_translation_platforms(self):
        """
        Test get_translation_platforms
        """
        transplatforms = self.inventory_manager.get_translation_platforms(
            engine='zanata')
        self.assertEqual(transplatforms[0].api_url,
                         'https://translate.zanata.org')
        self.assertEqual(transplatforms[0].platform_slug, 'ZNTAPUB')

    def test_get_transplatforms_set(self):
        """
        Test get_transplatforms_set
        """
        active_platforms, inactive_platforms = self.inventory_manager.get_transplatforms_set(
        )
        self.assertEqual(len(active_platforms), 1)
        self.assertEqual(len(inactive_platforms), 0)

    def test_get_transplatform_slug_url(self):
        """
        test get_transplatform_slug_url
        """
        slug_url_tuple = self.inventory_manager.get_transplatform_slug_url()
        self.assertTupleEqual(slug_url_tuple,
                              (('ZNTAPUB', 'https://translate.zanata.org'), ))