def test_remove_duplicate_approvals(self): """ Ensure that duplicate approvals are removed. """ # Trigger creation of new approved translation. self.main_vcs_translation.strings[None] = 'New Translated String' self.main_vcs_translation.fuzzy = False # Translation approved after the sync started simulates the race # where duplicate translations occur. duplicate_translation = TranslationFactory.create( entity=self.main_db_entity, locale=self.translated_locale, string='Other New Translated String', approved=True, approved_date=aware_datetime(1970, 1, 3) ) ChangedEntityLocale.objects.filter(entity=self.main_db_entity).delete() with patch('pontoon.sync.tasks.VCSProject', return_value=self.vcs_project): sync_project_repo(self.db_project.pk, self.repository.pk, self.project_sync_log.pk, self.now) # Only one translation should be approved: the duplicate_translation. assert_equal(self.main_db_entity.translation_set.filter(approved=True).count(), 1) new_translation = self.main_db_entity.translation_set.get( string='New Translated String' ) assert_false(new_translation.approved) assert_true(new_translation.approved_date is None) duplicate_translation.refresh_from_db() assert_true(duplicate_translation.approved) assert_equal(duplicate_translation.approved_date, aware_datetime(1970, 1, 3))
def test_always_close(self): """Ensure that the connection is closed even if an exception is thrown.""" self.channel.queue_declare.side_effect = IOError with assert_raises(IOError): shove.send_command('my_queue', 'my_project', 'asdf', 75) assert_true(self.connection.close.called)
def test_translation_counts(self): """ Translation memory should aggregate identical translations strings from the different entities and count up their occurrences. """ new_locale = LocaleFactory.create() memory_entry = TranslationMemoryFactory.create(source="aaaa", target="ccc", locale=new_locale) TranslationMemoryFactory.create(source="abaa", target="ccc", locale=new_locale) TranslationMemoryFactory.create(source="aaab", target="ccc", locale=new_locale) TranslationMemoryFactory.create(source="aaab", target="ccc", locale=new_locale) response = self.client.get('/translation-memory/', { 'text': 'aaaa', 'pk': memory_entry.entity.pk, 'locale': memory_entry.locale.code }) result = response.json() src_string = result[0].pop('source') assert_true(src_string in ('abaa', 'aaab', 'aaab')) assert_equal( result, [{ u'count': 3, u'quality': 75.0, u'target': u'ccc', }] )
def test_entity_filters(self): """ Tests if right filter calls right method in the Entity manager. """ filters = ( 'missing', 'fuzzy', 'suggested', 'translated', 'unchanged', 'has-suggestions', 'rejected', ) for filter_ in filters: filter_name = filter_.replace('-', '_') params = { 'project': self.resource.project.slug, 'locale': self.locale.code, 'paths[]': [self.resource.path], 'limit': 1, } if filter_ in ('unchanged', 'has-suggestions', 'rejected'): params['extra'] = filter_ else: params['status'] = filter_ with patch('pontoon.base.models.Entity.objects.{}'.format(filter_name), return_value=getattr(Entity.objects, filter_name)(self.locale, False)) as filter_mock: self.client.ajax_post('/get-entities/', params) assert_true(filter_mock.called)
def test_removed_files(self): with patch.object( self.vcsrepository, 'execute', side_effect=self.execute_success ) as mock_execute: removed_files = self.vcsrepository.get_removed_files('/path', '1') assert_true(mock_execute.called) assert_equal(removed_files, ['removed_file1.properties', 'removed_file2.properties'])
def test_connect_normal_auth_account(self): self.log_mock.return_value = False self.adapter.pre_social_login(MagicMock(), self.get_sociallogin('fxa')) assert_true(self.sociallogin.account.pk) assert_equal(self.sociallogin.user, self.user)
def test_no_project_configuration_extra_locales(self): """ Only create/update the TranslatedResource object for active locales, even if the inactive locale has a resource. """ update_translated_resources_without_config( self.db_project, self.vcs_project, self.translated_locale, ) assert_true(TranslatedResource.objects.filter( resource=self.main_db_resource, locale=self.translated_locale ).exists()) assert_true(TranslatedResource.objects.filter( resource=self.other_db_resource, locale=self.translated_locale ).exists()) assert_false(TranslatedResource.objects.filter( resource=self.main_db_resource, locale=self.inactive_locale ).exists()) assert_false(TranslatedResource.objects.filter( resource=self.other_db_resource, locale=self.inactive_locale ).exists())
def test_finished(self): log = RepositorySyncLogFactory.create(end_time=None) assert_false(log.finished) log.end_time = aware_datetime(2015, 1, 1) log.save() assert_true(log.finished)
def test_with_or_without_project_config( self, update_translated_resources_with_config_mock, update_translated_resources_without_config_mock, ): """ Pick the right update_translated_resources() method, depending on whether the project configuration file is provided or not. """ # Without project config self.vcs_project.configuration = None update_translated_resources( self.db_project, self.vcs_project, self.translated_locale, ) assert_false(update_translated_resources_with_config_mock.called) assert_true(update_translated_resources_without_config_mock.called) # Reset called value update_translated_resources_with_config_mock.called = False update_translated_resources_without_config_mock.called = False # With project config self.vcs_project.configuration = True update_translated_resources( self.db_project, self.vcs_project, self.translated_locale, ) assert_true(update_translated_resources_with_config_mock.called) assert_false(update_translated_resources_without_config_mock.called)
def test_project_configuration_basic(self): """ Create/update the TranslatedResource objects based on project configuration. """ with patch.object(self.vcs_project, 'configuration') as configuration: with patch.object(configuration, 'locale_resources') as locale_resources: locale_resources.return_value = [ self.other_db_resource, ] update_translated_resources_with_config( self.db_project, self.vcs_project, self.translated_locale, ) assert_true( TranslatedResource.objects.filter( resource=self.other_db_resource, locale=self.translated_locale, ).exists() ) assert_false( TranslatedResource.objects.filter( resource=self.missing_db_resource, locale=self.translated_locale, ).exists() )
def test_finished(self): sync_log = SyncLogFactory.create() # Create repo without existing log so sync is unfinished. repo = RepositoryFactory.create() project_sync_log = ProjectSyncLogFactory.create( sync_log=sync_log, project__repositories=[repo]) # Sync isn't finished until all repos are finished. assert_false(sync_log.finished) repo_log = RepositorySyncLogFactory.create( repository=repo, project_sync_log=project_sync_log, start_time=aware_datetime(2015, 1, 1), end_time=None ) del sync_log.finished assert_false(sync_log.finished) repo_log.end_time = aware_datetime(2015, 1, 2) repo_log.save() del sync_log.finished assert_true(sync_log.finished)
def test_connect_existing_persona_account(self): self.log_mock.side_effect = lambda provider: provider == 'persona' self.adapter.pre_social_login(MagicMock, self.get_sociallogin('fxa')) assert_true(self.sociallogin.account.pk) assert_equal(self.sociallogin.user, self.user)
def test_default_period(self): """ Calling the top contributors should result in period being None. """ self.client.get('/contributors/') assert_true(self.mock_render.call_args[0][0]['period'] is None) assert_true(self.mock_translations_manager.call_args[0][0] is None)
def test_entity_filters(self): """ Tests if right filter calls right method in the Entity manager. """ filters = ( 'missing', 'fuzzy', 'suggested', 'translated', 'untranslated', 'has-suggestions', 'unchanged', ) for filter_ in filters: filter_name = filter_.replace('-', '_') with patch('pontoon.base.models.Entity.objects.{}'.format(filter_name), return_value=Entity.objects.all()) as filter_mock: self.client.post('/get-entities/', { 'project': self.resource.project.slug, 'locale': self.locale.code, 'paths[]': [self.resource.path], 'filter': filter_, 'limit': 1, }, HTTP_X_REQUESTED_WITH='XMLHttpRequest') assert_true(filter_mock.called) assert_equal(filter_mock.call_args, call(self.locale))
def test_can_commit_true(self): """ can_commit should be True if there is a repo that can be committed to. """ repo = RepositoryFactory.build(type=Repository.GIT) project = ProjectFactory.create(repositories=[repo]) assert_true(project.can_commit)
def test_success_true(self): """ If all shove instances executed the command successfully, return True. """ command = SentCommandFactory.create() CommandLogFactory.create_batch(2, sent_command=command, return_code=0) assert_true(command.success)
def test_consumer_incorrect_response(self, log): """If the consumer receives an incorrect response, it should log it and return.""" callback = Mock() consume = self._get_consume(callback) consume(self.channel, Mock(), Mock(), '{"blah": "foo", "BAR": 3}') assert_true(log.warning.called) assert_true(not callback.called)
def test_consumer_invalid_json(self, log): """If the consumer receives invalid JSON, it should log it and return.""" callback = Mock() consume = self._get_consume(callback) consume(self.channel, Mock(), Mock(), 'asdfas__EWtwet') assert_true(log.warning.called) assert_true(not callback.called)
def test_success_none(self): """ If any shove instance hasn't received a return code yet, return None. """ command = SentCommandFactory.create() CommandLogFactory.create(sent_command=command, return_code=0) CommandLogFactory.create(sent_command=command, return_code=None) assert_true(command.success is None)
def test_handle_log_not_found(self, log): """If no log can be found with the given key, log a warning and return.""" monitor_shove_logs.handle_log_event({ 'log_key': 99999999999, 'return_code': 0, 'output': 'asdf' }) assert_true(log.warning.called) assert_equal(CommandLog.objects.count(), 0)
def test_handle_log_key_invalid(self, log): """If the given log key isn't a valid pk, log a warning and return.""" monitor_shove_logs.handle_log_event({ 'log_key': 'not.an.int', 'return_code': 0, 'output': 'asdf' }) assert_true(log.warning.called) assert_equal(CommandLog.objects.count(), 0)
def test_handle_heartbeat_missing_key(self): """ If the given data is missing a required key, log a warning and return. """ with patch.object(monitor_shove_instances, 'log') as log: monitor_shove_instances.handle_heartbeat_event({'incorrect': 'keys'}) assert_true(log.warning.called) assert_equal(ShoveInstance.objects.count(), 0)
def test_unsure_changes(self): """ If any of the repos returns None as a revision number, consider the VCS as changed even if the revisions match the last sync. """ self.mock_repo_pull.return_value = {'single_locale': None} self.repository.last_synced_revisions = {'single_locale': None} self.repository.save() assert_true(pull_changes(self.db_project))
def test_basic(self): """ Pull_changes should call repo.pull for each repo for the project, save the return value to repo.last_synced_revisions, and return whether any changes happened in VCS. """ self.mock_repo_pull.return_value = {'single_locale': 'asdf'} assert_true(pull_changes(self.db_project)) self.repository.refresh_from_db() assert_equal(self.repository.last_synced_revisions, {'single_locale': 'asdf'})
def test_no_changes_force(self): """ If the database and VCS both have no changes, but force is true, do not skip syncing resources. """ self.mock_pull_changes.return_value = [False, {}] self.mock_project_needs_sync.return_value = False sync_project(self.db_project.pk, self.sync_log.pk, force=True) assert_true(self.mock_update_originals.called)
def test_empty_locale(self): """Lookup won't add an empty collation to a sql query.""" entities = Entity.objects.filter( string__icontains_collate=('string', '') ) query_sql = entities.query.sql_with_params()[0] # Force evaluation of query on the real database. assert_equal(entities.count(), 10) assert_true('COLLATE' not in query_sql)
def test_no_changes_force(self): """ If the database and VCS both have no changes, but force is true, do not skip sync. """ self.mock_pull_changes.return_value = False self.mock_project_needs_sync.return_value = False sync_project(self.db_project.pk, self.sync_log.pk, force=True) assert_true(self.mock_perform_sync_project.called)
def test_db_changed_no_repo_changed(self): """ If the database has changes and VCS doesn't, do not skip syncing the project. """ self.mock_pull_changes.return_value = False self.mock_project_needs_sync.return_value = True sync_project(self.db_project.pk, self.sync_log.pk) assert_true(self.mock_perform_sync_project.called)
def test_users_without_translations(self): """ Checks if user contributors without translations aren't returned. """ active_contributor = TranslationFactory.create(user__email="*****@*****.**").user inactive_contributor = UserFactory.create(email="*****@*****.**") top_contributors = User.translators.with_translation_counts() assert_true(active_contributor in top_contributors) assert_true(inactive_contributor not in top_contributors)
def test_needs_sync(self): """ Project.needs_sync should be True if ChangedEntityLocale objects exist for its entities or if Project.has_changed is True. """ assert_true(ProjectFactory.create(has_changed=True).needs_sync) project = ProjectFactory.create(has_changed=False) ChangedEntityLocaleFactory.create(entity__resource__project=project) assert_true(project.needs_sync)
def test_db_changed_no_repo_changed(self): """ If the database has changes and VCS doesn't, do not skip syncing the project. """ self.mock_pull_changes.return_value = False self.mock_project_needs_sync.return_value = True with patch('pontoon.sync.core.handle_entity') as mock_handle_entity: sync_project(self.db_project) assert_true(mock_handle_entity.called)
def test_connect_existing_fxa_account(self): """ Check if user that previously connected via fxa is able to connect his persona account. """ self.log_mock.side_effect = lambda provider: provider == 'fxa' self.adapter.pre_social_login(MagicMock, self.get_sociallogin('persona')) assert_true(self.sociallogin.account.pk) assert_equal(self.sociallogin.user, self.user)
def test_unsure_changes(self): """ If any of the repos returns None as a revision number, consider the VCS as changed even if the revisions match the last sync. """ self.mock_repo_pull.return_value = {'single_locale': None} self.repository.last_synced_revisions = {'single_locale': None} self.repository.save() has_changed, _ = pull_changes(self.db_project) assert_true(has_changed)
def test_users_without_translations(self): """ Checks if user contributors without translations aren't returned. """ active_contributor = TranslationFactory.create( user__email='*****@*****.**').user inactive_contributor = UserFactory.create(email='*****@*****.**') top_contributors = User.translators.with_translation_counts() assert_true(active_contributor in top_contributors) assert_true(inactive_contributor not in top_contributors)
def test_unique_translations(self): """ Checks if contributors with identical translations are returned. """ unique_translator = TranslationFactory.create().user identical_translator = IdenticalTranslationFactory.create().user top_contributors = User.translators.with_translation_counts() assert_true(unique_translator in top_contributors) assert_true(identical_translator not in top_contributors)
def test_basic(self): """ Pull_changes should call repo.pull for each repo for the project and return whether any changes happened in VCS. """ mock_db_project = MagicMock() mock_db_project.repositories.all.return_value = [self.repository] self.mock_repo_pull.return_value = {'single_locale': 'asdf'} has_changed, _ = pull_changes(self.db_project) assert_true(has_changed)
def test_save_create_dirs(self): """ If the directories in a resource's path don't exist, create them on save. """ path = os.path.join(tempfile.mkdtemp(), 'does', 'not', 'exist.dtd') translated_resource = self.create_nonexistant_resource(path) translated_resource.translations[0].strings = {None: 'New Translated String'} translated_resource.save(LocaleFactory.create()) assert_true(os.path.exists(path))
def test_collation_query(self): """Check if collate is applied to a given lookup.""" entities = Entity.objects.filter( string__icontains_collate=('qwertyuiop', 'C')) query_sql = entities.query.sql_with_params()[0] # Force evaluation of query on the real database. assert_equal(entities.count(), 10) assert_true( query_sql.endswith( 'WHERE UPPER("base_entity"."string"::text COLLATE "C") ' 'LIKE UPPER(%s COLLATE "C")'))
def test_project_locale_added(self): """ When a locale is added to a project, has_changed should be set to True. """ project = ProjectFactory.create(locales=[], has_changed=False) assert_false(project.has_changed) locale = LocaleFactory.create() ProjectLocaleFactory.create(project=project, locale=locale) project.refresh_from_db() assert_true(project.has_changed)
def test_get_or_set_project_files_new_locale(self): self.vcs_project.configuration.add_locale = Mock() locale_code = 'new-locale-code' assert_equal( self.vcs_project.configuration.get_or_set_project_files( locale_code, ).locale, locale_code, ) assert_true(self.vcs_project.configuration.add_locale.called)
def test_release_lock_after_timeout(self): """ Tests if lock is released after specified timeout. """ with patch('pontoon.sync.core.cache') as mock_cache: @serial_task(3) def timeout_task(self): return 42 first_call = timeout_task.delay() assert_true(first_call.successful()) assert_equal(first_call.get(), 42) mock_cache.add.assert_called_with(ANY, ANY, timeout=3)
def test_save_create_dirs(self): """ If the directories in a resource's path don't exist, create them on save. """ path = self.get_nonexistant_file_path() translated_resource = self.get_nonexistant_file_resource(path) translated_resource.translations[0].strings = {None: "New Translated String"} assert_false(os.path.exists(path)) translated_resource.save(LocaleFactory.create()) assert_true(os.path.exists(path))
def test_has_translation_for(self): """ Return True if a translation exists for the given locale, even if the translation is empty/falsey. """ empty_translation = VCSTranslationFactory(strings={}) full_translation = VCSTranslationFactory(strings={None: 'TRANSLATED'}) entity = VCSEntityFactory() entity.translations = {'empty': empty_translation, 'full': full_translation} assert_false(entity.has_translation_for('missing')) assert_true(entity.has_translation_for('empty')) assert_true(entity.has_translation_for('full'))
def test_excluded_contributors(self): """ Checks if contributors with mails in settings.EXCLUDE are excluded from top contributors list. """ included_contributor = TranslationFactory.create( user__email='*****@*****.**').user excluded_contributor = TranslationFactory.create( user__email='*****@*****.**').user top_contributors = User.translators.with_translation_counts() assert_true(included_contributor in top_contributors) assert_true(excluded_contributor not in top_contributors)
def test_update_vcs_entity(self): """ Update the VCS translations with translations in the database. """ self.update_main_vcs_entity(string='New Translated String') assert_equal(self.main_vcs_translation.strings, {None: 'New Translated String'}) # Ensure only resources that were updated are saved. assert_true(self.main_vcs_resource.save.called) assert_false(self.other_vcs_resource.save.called) # Update the VCS translation with info about the last # translation. assert_equal(self.main_vcs_translation.last_updated, self.main_db_translation.date) assert_equal(self.main_vcs_translation.last_translator, self.main_db_translation.user)
def test_exception_during_sync(self): """ Any error during performing synchronization should release the lock. """ @serial_task(100) def exception_task(self): raise UserError first_call = exception_task.delay() second_call = exception_task.delay() assert_true(first_call.failed()) assert_true(second_call.failed()) assert_raises(UserError, first_call.get) assert_raises(UserError, second_call.get)
def test_serial_task(self): """ Test if sync will create lock in cache and release this after task is done. """ @serial_task(100) def test_task(self, callback): return callback() def execute_second_inner_task(): return test_task.delay(lambda: None) first_call = test_task.delay(execute_second_inner_task) second_call = first_call.get() assert_true(first_call.successful()) assert_true(second_call.failed()) assert_raises(RuntimeError, second_call.get)
def test_no_changes_skip(self): """ If the database and VCS both have no changes, skip sync and log a message. """ self.mock_pull_changes.return_value = False self.mock_project_needs_sync.return_value = False with patch('pontoon.sync.tasks.log') as mock_log: sync_project(self.db_project.pk, self.sync_log.pk) assert_false(self.mock_perform_sync_project.called) mock_log.info.assert_called_with( CONTAINS('Skipping', self.db_project.slug) ) # When skipping, mark the project log properly. assert_true(ProjectSyncLog.objects.get(project=self.db_project).skipped)
def test_no_changes_skip(self): """ If the database and the source repository both have no changes, and project has a single repository, skip sync. """ self.mock_pull_changes.return_value = False self.mock_project_needs_sync.return_value = False with patch('pontoon.sync.tasks.log') as mock_log: sync_project(self.db_project.pk, self.sync_log.pk) assert_false(self.mock_update_originals.called) mock_log.info.assert_called_with( CONTAINS('Skipping project', self.db_project.slug) ) # When skipping, mark the project log properly. assert_true(ProjectSyncLog.objects.get(project=self.db_project).skipped)
def test_serial_task(self): """ Test if sync will create lock in cache and release this after task is done. """ @serial_task(100) def test_task(self, call_subtask): if call_subtask: return subtask() def subtask(): return test_task.delay() first_call = test_task.delay(call_subtask=True) second_call = first_call.get() assert_true(first_call.successful()) assert_true(second_call.failed()) assert_raises(RuntimeError, second_call.get)
def test_finished(self): repo = RepositoryFactory.create() project_sync_log = ProjectSyncLogFactory.create( project__repositories=[repo]) # Sync isn't finished until all repos are finished. assert_false(project_sync_log.finished) repo_log = RepositorySyncLogFactory.create( repository=repo, project_sync_log=project_sync_log, start_time=aware_datetime(2015, 1, 1), end_time=None) assert_false(project_sync_log.finished) repo_log.end_time = aware_datetime(2015, 1, 2) repo_log.save() assert_true(project_sync_log.finished)
def test_remove_duplicate_approvals(self): """ Ensure that duplicate approvals are removed. """ # Trigger creation of new approved translation. self.main_vcs_translation.strings[None] = "New Translated String" self.main_vcs_translation.fuzzy = False self.mock_pull_changes.return_value = [ True, { self.repository.pk: Locale.objects.filter(pk=self.translated_locale.pk) }, ] # Translation approved after the sync started simulates the race # where duplicate translations occur. duplicate_translation = TranslationFactory.create( entity=self.main_db_entity, locale=self.translated_locale, string="Other New Translated String", approved=True, approved_date=aware_datetime(1970, 1, 3), ) ChangedEntityLocale.objects.filter(entity=self.main_db_entity).delete() with patch("pontoon.sync.tasks.VCSProject", return_value=self.vcs_project): sync_translations(self.db_project.pk, self.project_sync_log.pk, self.now) # Only one translation should be approved: the duplicate_translation. assert_equal( self.main_db_entity.translation_set.filter(approved=True).count(), 1) new_translation = self.main_db_entity.translation_set.get( string="New Translated String") assert_false(new_translation.approved) assert_true(new_translation.approved_date is None) duplicate_translation.refresh_from_db() assert_true(duplicate_translation.approved) assert_equal(duplicate_translation.approved_date, aware_datetime(1970, 1, 3))
def test_basic(self): """ Create/update the TranslatedResource object on all resources available in the current locale. """ update_translated_resources(self.db_project, self.vcs_project, self.translated_locale) assert_true(TranslatedResource.objects.filter( resource=self.main_db_resource, locale=self.translated_locale ).exists()) assert_true(TranslatedResource.objects.filter( resource=self.other_db_resource, locale=self.translated_locale ).exists()) assert_false(TranslatedResource.objects.filter( resource=self.missing_db_resource, locale=self.translated_locale ).exists())
def test_invalid_period(self): """ Checks how view handles invalid period, it result in period being None - displays all data. """ # If period parameter is invalid value self.client.get('/contributors/?period=invalidperiod') assert_true(self.mock_render.call_args[0][0]['period'] is None) assert_true(self.mock_translations_manager.call_args[0][0] is None) # Period shouldn't be negative integer self.client.get('/contributors/?period=-6') assert_true(self.mock_render.call_args[0][0]['period'] is None) assert_true(self.mock_translations_manager.call_args[0][0] is None)
def test_basic(self): """ Pull_changes should call repo.pull for each repo for the project, save the return value to repo.last_synced_revisions, and return whether any changes happened in VCS. """ mock_db_project = MagicMock() mock_db_project.repositories.all.return_value = [self.repository] self.mock_repo_pull.return_value = {'single_locale': 'asdf'} has_changed, revisions = pull_changes(self.db_project) assert_true(has_changed) assert_equal(revisions, {self.repository.pk: { 'single_locale': 'asdf' }}) self.repository.last_synced_revisions = revisions[self.repository.pk] self.repository.save() self.repository.refresh_from_db() assert_equal(self.repository.last_synced_revisions, {'single_locale': 'asdf'})
def test_no_subpage_no_stats_in_current_locale(self): """ If there are stats for a resource available in other locales but not in the current one, and no subpages, do not set ctx['part']. """ locale, locale_no_stats = LocaleFactory.create_batch(2) project = ProjectFactory.create(locales=[locale, locale_no_stats]) # Need two resources to trigger setting the part value. resource = ResourceFactory.create(project=project, path='foo.lang', entity_count=1) ResourceFactory.create(project=project, entity_count=1) StatsFactory.create(resource=resource, locale=locale) self.client_login() url = '/{locale.code}/{project.slug}/'.format(locale=locale_no_stats, project=project) with patch('pontoon.base.views.render', wraps=render) as mock_render: self.client.get(url) assert_true('part' not in mock_render.call_args[0][2])
def test_no_project_configuration_asymmetric(self): """ Create/update the TranslatedResource object on asymmetric resources even if they don't exist in the target locale. """ with patch.object(Resource, 'is_asymmetric', new_callable=PropertyMock) as is_asymmetric: is_asymmetric.return_value = True update_translated_resources_without_config( self.db_project, self.vcs_project, self.translated_locale, ) assert_true( TranslatedResource.objects.filter( resource=self.main_db_resource, locale=self.translated_locale).exists()) assert_true( TranslatedResource.objects.filter( resource=self.other_db_resource, locale=self.translated_locale).exists()) assert_true( TranslatedResource.objects.filter( resource=self.missing_db_resource, locale=self.translated_locale).exists())
def test_extra_locales(self): """ Only create/update the TranslatedResource object for active locales, even if the inactive locale has a resource. """ update_translated_resources(self.db_project, self.vcs_project, self.translated_locale) assert_true(TranslatedResource.objects.filter( resource=self.main_db_resource, locale=self.translated_locale ).exists()) assert_true(TranslatedResource.objects.filter( resource=self.other_db_resource, locale=self.translated_locale ).exists()) assert_false(TranslatedResource.objects.filter( resource=self.main_db_resource, locale=self.inactive_locale ).exists()) assert_false(TranslatedResource.objects.filter( resource=self.other_db_resource, locale=self.inactive_locale ).exists())
def test_finished(self): sync_log = SyncLogFactory.create() # Create repo without existing log so sync is unfinished. repo = RepositoryFactory.create() project_sync_log = ProjectSyncLogFactory.create( sync_log=sync_log, project__repositories=[repo]) # Sync isn't finished until all repos are finished. assert_false(sync_log.finished) repo_log = RepositorySyncLogFactory.create( repository=repo, project_sync_log=project_sync_log, start_time=aware_datetime(2015, 1, 1), end_time=None) del sync_log.finished assert_false(sync_log.finished) repo_log.end_time = aware_datetime(2015, 1, 2) repo_log.save() del sync_log.finished assert_true(sync_log.finished)