def test_audio_translation_validation(self):
        """Test validation of audio translations."""
        audio_translation = state_domain.AudioTranslation('a.mp3', 20, True)
        audio_translation.validate()

        with self.assertRaisesRegexp(utils.ValidationError,
                                     'Expected audio filename to be a string'):
            with self.swap(audio_translation, 'filename', 20):
                audio_translation.validate()
        with self.assertRaisesRegexp(utils.ValidationError,
                                     'Invalid audio filename'):
            with self.swap(audio_translation, 'filename', '.invalidext'):
                audio_translation.validate()
        with self.assertRaisesRegexp(utils.ValidationError,
                                     'Invalid audio filename'):
            with self.swap(audio_translation, 'filename', 'justanextension'):
                audio_translation.validate()
        with self.assertRaisesRegexp(utils.ValidationError,
                                     'Invalid audio filename'):
            with self.swap(audio_translation, 'filename', 'a.invalidext'):
                audio_translation.validate()

        with self.assertRaisesRegexp(utils.ValidationError,
                                     'Expected file size to be an int'):
            with self.swap(audio_translation, 'file_size_bytes', 'abc'):
                audio_translation.validate()
        with self.assertRaisesRegexp(utils.ValidationError,
                                     'Invalid file size'):
            with self.swap(audio_translation, 'file_size_bytes', -3):
                audio_translation.validate()

        with self.assertRaisesRegexp(utils.ValidationError,
                                     'Expected needs_update to be a bool'):
            with self.swap(audio_translation, 'needs_update', 'hello'):
                audio_translation.validate()
    def setUp(self):
        super(SuggestionIntegrationTests, self).setUp()
        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.signup(self.AUTHOR_EMAIL, 'author')
        self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
        self.author_id = self.get_user_id_from_email(self.AUTHOR_EMAIL)
        self.reviewer_id = self.editor_id

        self.editor = user_services.UserActionsInfo(self.editor_id)

        # Login and create exploration and suggestions.
        self.login(self.EDITOR_EMAIL)

        # Create exploration.
        exploration = (
            self.save_new_linear_exp_with_state_names_and_interactions(
                self.EXP_ID,
                self.editor_id, ['State 1', 'State 2'], ['TextInput'],
                category='Algebra'))

        self.old_content = state_domain.SubtitledHtml('content',
                                                      'old content').to_dict()
        self.old_content_ids_to_audio_translations = {
            'content': {
                self.TRANSLATION_LANGUAGE_CODE:
                state_domain.AudioTranslation('filename.mp3', 20,
                                              False).to_dict()
            },
            'default_outcome': {}
        }
        # Create content in State A with a single audio subtitle.
        exploration.states['State 1'].update_content(self.old_content)
        exploration.states['State 1'].update_content_ids_to_audio_translations(
            self.old_content_ids_to_audio_translations)
        exp_services._save_exploration(self.editor_id, exploration, '', [])  # pylint: disable=protected-access

        rights_manager.publish_exploration(self.editor, self.EXP_ID)
        rights_manager.assign_role_for_exploration(self.editor, self.EXP_ID,
                                                   self.owner_id,
                                                   rights_manager.ROLE_EDITOR)

        self.new_content = state_domain.SubtitledHtml('content',
                                                      'new content').to_dict()

        self.change = {
            'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
            'property_name': exp_domain.STATE_PROPERTY_CONTENT,
            'state_name': 'State 1',
            'new_value': self.new_content
        }

        self.target_version_at_submission = exploration.version