예제 #1
0
    def test_merge_bundles(self):
        p1, expected_bundle1 = _create_product_bundle()
        p2, expected_bundle2 = _create_product_bundle('yay')

        bundle1 = utils.bundle_for_product(p1, 'en-US')
        bundle2 = utils.bundle_for_product(p2, 'en-US')

        merged = utils.merge_bundles(bundle1, bundle2)

        assert 'locales' in merged
        eq_(1, len(merged['locales']))

        expected_locale = expected_bundle1['locale']
        expected_locale['products'] += expected_bundle2['locale']['products']

        eq_(expected_locale, merged['locales'][0])

        assert 'topics' in merged
        eq_(4, len(merged['topics']))

        merged['topics'].sort(key=lambda t: t['slug'])

        eq_(expected_bundle1['topic1'], merged['topics'][0])
        eq_(expected_bundle1['topic2'], merged['topics'][1])
        eq_(expected_bundle2['topic1'], merged['topics'][2])
        eq_(expected_bundle2['topic2'], merged['topics'][3])

        assert 'docs' in merged
        eq_(4, len(merged['docs']))

        merged['docs'].sort(key=lambda d: d['title'])

        eq_(expected_bundle1['doc1'], merged['docs'][0])
        eq_(expected_bundle1['doc2'], merged['docs'][1])
        eq_(expected_bundle2['doc1'], merged['docs'][2])
        eq_(expected_bundle2['doc2'], merged['docs'][3])

        eq_(2, len(merged['indexes']))
        merged['indexes'].sort(key=lambda i: i['key'])
        eq_('en-US~moofirefox', merged['indexes'][0]['key'])
        eq_('en-US~yayfirefox', merged['indexes'][1]['key'])
예제 #2
0
    def test_merge_bundles(self):
        p1, expected_bundle1 = _create_product_bundle()
        p2, expected_bundle2 = _create_product_bundle('yay')

        bundle1 = utils.bundle_for_product(p1, 'en-US')
        bundle2 = utils.bundle_for_product(p2, 'en-US')

        merged = utils.merge_bundles(bundle1, bundle2)

        assert 'locales' in merged
        eq_(1, len(merged['locales']))

        expected_locale = expected_bundle1['locale']
        expected_locale['products'] += expected_bundle2['locale']['products']

        eq_(expected_locale, merged['locales'][0])

        assert 'topics' in merged
        eq_(4, len(merged['topics']))

        merged['topics'].sort(key=lambda t: t['slug'])

        eq_(expected_bundle1['topic1'], merged['topics'][0])
        eq_(expected_bundle1['topic2'], merged['topics'][1])
        eq_(expected_bundle2['topic1'], merged['topics'][2])
        eq_(expected_bundle2['topic2'], merged['topics'][3])

        assert 'docs' in merged
        eq_(4, len(merged['docs']))

        merged['docs'].sort(key=lambda d: d['title'])

        eq_(expected_bundle1['doc1'], merged['docs'][0])
        eq_(expected_bundle1['doc2'], merged['docs'][1])
        eq_(expected_bundle2['doc1'], merged['docs'][2])
        eq_(expected_bundle2['doc2'], merged['docs'][3])

        eq_(2, len(merged['indexes']))
        merged['indexes'].sort(key=lambda i: i['key'])
        eq_('en-US~moofirefox', merged['indexes'][0]['key'])
        eq_('en-US~yayfirefox', merged['indexes'][1]['key'])
예제 #3
0
def build_kb_bundles(products=('firefox-os', 'firefox', 'mobile')):
    redis = redis_client('default')

    if not redis:
        raise IOError('Redis not available. Cannot generate offline bundles.')

    start_time = time.time()
    size = 0

    products = [Product.objects.get(slug=p) for p in products]
    with statsd.timer('offline.build_kb_bundles.time_elapsed'):
        for locale in settings.SUMO_LANGUAGES:
            for product in products:
                with uselocale(locale):
                    bundle = merge_bundles(bundle_for_product(product, locale))

                size += len(
                    insert_bundle_into_redis(redis, product.slug, locale,
                                             bundle)[0])

    time_taken = time.time() - start_time
    log.info('Generated all offline bundles. '
             'Size: {0}. Took {1} seconds'.format(size, time_taken))
예제 #4
0
def build_kb_bundles(products=('firefox-os', 'firefox', 'mobile')):
    redis = redis_client('default')

    if not redis:
        raise IOError('Redis not available. Cannot generate offline bundles.')

    start_time = time.time()
    size = 0

    products = [Product.objects.get(slug=p) for p in products]
    with statsd.timer('offline.build_kb_bundles.time_elapsed'):
        for locale in settings.SUMO_LANGUAGES:
            for product in products:
                with uselocale(locale):
                    bundle = merge_bundles(bundle_for_product(product, locale))

                size += len(insert_bundle_into_redis(redis,
                                                     product.slug,
                                                     locale,
                                                     bundle)[0])

    time_taken = time.time() - start_time
    log.info('Generated all offline bundles. '
             'Size: {0}. Took {1} seconds'.format(size, time_taken))