<commit_before>from flask import current_app as app
from test_factory import SuperdeskTestCase
from .app_initialize import AppInitializeWithDataCommand
from .app_scaffold_data import AppScaffoldDataCommand
from superdesk import get_resource_service


class AppInitializeWithDataCommandTestCase(SuperdeskTestCase):

    def test_app_initialization(self):
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)

    def test_app_initialization_multiple_loads(self):
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)
        result = command.run()
        self.assertEqual(result, 0)

    def data_scaffolding_test(self):
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)

        docs = [{
            '_id': str(x),
            'type': 'text',
            'abstract': 'test abstract {}'.format(x),
            'headline': 'test headline {}'.format(x),
            'body_html': 'test long story body {}'.format(x),
            'allow_post_publish_actions': True
        } for x in range(0, 40)]
        get_resource_service('published').post(docs)

        stories_per_desk = 2
        existing_desks = 18
        command = AppScaffoldDataCommand()
        result = command.run(stories_per_desk)
        self.assertEqual(result, 0)

        cursor = get_resource_service('desks').get_from_mongo(None, {})
        self.assertEqual(cursor.count(), existing_desks)

        cursor = get_resource_service('archive').get_from_mongo(None, {})
        self.assertEqual(cursor.count(), existing_desks * stories_per_desk)

    def test_app_initialization_index_creation(self):
        result = app.data.mongo.pymongo(resource='users').db['users'].index_information()
        self.assertEqual(result, {})
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)
        result = app.data.mongo.pymongo(resource='users').db['users'].index_information()
        self.assertTrue('username_1' in result)
        self.assertTrue('first_name_1_last_name-1')<commit_msg>Fixing the test of app:initialize_data<commit_after>from flask import current_app as app
from test_factory import SuperdeskTestCase
from .app_initialize import AppInitializeWithDataCommand
from .app_scaffold_data import AppScaffoldDataCommand
from superdesk import get_resource_service


class AppInitializeWithDataCommandTestCase(SuperdeskTestCase):

    def test_app_initialization(self):
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)

    def test_app_initialization_multiple_loads(self):
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)
        result = command.run()
        self.assertEqual(result, 0)

    def data_scaffolding_test(self):
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)

        docs = [{
            '_id': str(x),
            'type': 'text',
            'abstract': 'test abstract {}'.format(x),
            'headline': 'test headline {}'.format(x),
            'body_html': 'test long story body {}'.format(x),
            'allow_post_publish_actions': True
        } for x in range(0, 40)]
        get_resource_service('published').post(docs)

        stories_per_desk = 2
        existing_desks = 18
        command = AppScaffoldDataCommand()
        result = command.run(stories_per_desk)
        self.assertEqual(result, 0)

        cursor = get_resource_service('desks').get_from_mongo(None, {})
        self.assertEqual(cursor.count(), existing_desks)

        cursor = get_resource_service('archive').get_from_mongo(None, {})
        self.assertEqual(cursor.count(), existing_desks * stories_per_desk)

    def test_app_initialization_index_creation(self):
        result = app.data.mongo.pymongo(resource='users').db['users'].index_information()
        self.assertEqual(result, {})
        command = AppInitializeWithDataCommand()
        result = command.run()
        self.assertEqual(result, 0)
        result = app.data.mongo.pymongo(resource='users').db['users'].index_information()
        self.assertTrue('username_1' in result)
        self.assertTrue('first_name_1_last_name_-1' in result)
{'fraction_non_alphanumeric': 0.1064835659612787, 'fraction_numerical': 0.00675371454299865, 'mean_word_length': 3.2274024738344433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3428753', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1250, 'n_words': 235}