Пример #1
0
    def to_dict(self) -> Dict[str, Union[bool, float, str, List[str]]]:
        """Returns a dict representation of the BeamJobRun.

        Returns:
            dict(str: *). The dict has the following structure:
                job_id: str. The ID of the job execution.
                job_name: str. The name of the job class that implements the
                    job's logic.
                job_state: str. The state of the job at the time the model was
                    last updated.
                job_started_on_msecs: float. The number of milliseconds since
                    UTC epoch at which the job was created.
                job_updated_on_msecs: float. The number of milliseconds since
                    UTC epoch at which the job's state was last updated.
                job_is_synchronous: bool. Whether the job has been run
                    synchronously.
        """
        return {
            'job_id':
            self.job_id,
            'job_name':
            self.job_name,
            'job_state':
            self.job_state,
            'job_started_on_msecs':
            (utils.get_time_in_millisecs(self.job_started_on)),
            'job_updated_on_msecs':
            (utils.get_time_in_millisecs(self.job_updated_on)),
            'job_is_synchronous':
            self.job_is_synchronous,
        }
Пример #2
0
    def get(self, thread_id):
        """Handles GET requests."""
        messages = feedback_services.get_messages(thread_id)
        author_ids = [m.author_id for m in messages]
        authors_settings = user_services.get_users_settings(author_ids)

        message_ids = [m.message_id for m in messages]
        feedback_services.update_messages_read_by_the_user(
            self.user_id, thread_id, message_ids)

        message_summary_list = []
        suggestion = suggestion_services.get_suggestion_by_id(thread_id)
        suggestion_thread = feedback_services.get_thread(thread_id)

        exploration_id = feedback_services.get_exp_id_from_thread_id(thread_id)
        if suggestion:
            exploration = exp_fetchers.get_exploration_by_id(exploration_id)
            current_content_html = (
                exploration.states[suggestion.change.state_name].content.html)
            suggestion_summary = {
                'suggestion_html':
                suggestion.change.new_value['html'],
                'current_content_html':
                current_content_html,
                'description':
                suggestion_thread.subject,
                'author_username':
                authors_settings[0].username,
                'author_picture_data_url':
                (authors_settings[0].profile_picture_data_url),
                'created_on_msecs':
                utils.get_time_in_millisecs(messages[0].created_on)
            }
            message_summary_list.append(suggestion_summary)
            messages.pop(0)
            authors_settings.pop(0)

        for m, author_settings in zip(messages, authors_settings):

            if author_settings is None:
                author_username = None
                author_picture_data_url = None
            else:
                author_username = author_settings.username
                author_picture_data_url = (
                    author_settings.profile_picture_data_url)

            message_summary = {
                'message_id': m.message_id,
                'text': m.text,
                'updated_status': m.updated_status,
                'author_username': author_username,
                'author_picture_data_url': author_picture_data_url,
                'created_on_msecs': utils.get_time_in_millisecs(m.created_on)
            }
            message_summary_list.append(message_summary)

        self.render_json({'message_summary_list': message_summary_list})
Пример #3
0
    def test_to_dict(self) -> None:
        run = beam_job_domain.BeamJobRun('123', 'FooJob', 'RUNNING', self.NOW,
                                         self.NOW, True)

        self.assertEqual(
            run.to_dict(), {
                'job_id': '123',
                'job_name': 'FooJob',
                'job_state': 'RUNNING',
                'job_started_on_msecs': utils.get_time_in_millisecs(self.NOW),
                'job_updated_on_msecs': utils.get_time_in_millisecs(self.NOW),
                'job_is_synchronous': True,
            })
Пример #4
0
    def export_data(cls, user_id):
        """Exports the data from BlogPostModel into dict format for Takeout.

        Args:
            user_id: str. The ID of the user whose data should be exported.

        Returns:
            dict. Dictionary of the data from BlogPostModel.
        """
        user_data = {}
        blog_post_models = cls.get_all().filter(
            cls.author_id == user_id).fetch()

        for blog_post_model in blog_post_models:
            user_data[blog_post_model.id] = {
                'title':
                blog_post_model.title,
                'content':
                blog_post_model.content,
                'url_fragment':
                blog_post_model.url_fragment,
                'tags':
                blog_post_model.tags,
                'thumbnail_filename':
                blog_post_model.thumbnail_filename,
                'published_on':
                utils.get_time_in_millisecs(blog_post_model.published_on),
            }

        return user_data
Пример #5
0
    def export_data(
            cls,
            user_id: str
    ) -> Dict[str, Dict[str, Union[str, bool, None]]]:
        """Exports the data from GeneralFeedbackThreadModel
        into dict format for Takeout.

        Args:
            user_id: str. The ID of the user whose data should be exported.

        Returns:
            dict. Dictionary of the data from GeneralFeedbackThreadModel.
        """

        user_data = {}
        feedback_models: Sequence[GeneralFeedbackThreadModel] = (
            cls.get_all().filter(cls.original_author_id == user_id).fetch())

        for feedback_model in feedback_models:
            user_data[feedback_model.id] = {
                'entity_type': feedback_model.entity_type,
                'entity_id': feedback_model.entity_id,
                'status': feedback_model.status,
                'subject': feedback_model.subject,
                'has_suggestion': feedback_model.has_suggestion,
                'summary': feedback_model.summary,
                'message_count': feedback_model.message_count,
                'last_updated_msec': utils.get_time_in_millisecs(
                    feedback_model.last_updated)
            }

        return user_data
Пример #6
0
 def test_to_dict_with_non_existing_resolver_id(self) -> None:
     task_entry = improvements_domain.TaskEntry(
         constants.TASK_ENTITY_TYPE_EXPLORATION, self.exp.id, 1,
         constants.TASK_TYPE_HIGH_BOUNCE_RATE,
         constants.TASK_TARGET_TYPE_STATE, feconf.DEFAULT_INIT_STATE_NAME,
         'issue description', constants.TASK_STATUS_RESOLVED, None,
         self.MOCK_DATE)
     # In case of non-existing resolver_id,
     # get_task_dict_with_username_and_profile_picture should return
     # with no changes to the TaskEntry dict.
     task_entry_dict = (
         improvements.
         get_task_dict_with_username_and_profile_picture(  # type: ignore[no-untyped-call]
             task_entry))
     self.assertEqual(
         task_entry_dict, {
             'entity_type': 'exploration',
             'entity_id': self.exp.id,
             'entity_version': 1,
             'task_type': 'high_bounce_rate',
             'target_type': 'state',
             'target_id': 'Introduction',
             'issue_description': 'issue description',
             'status': 'resolved',
             'resolver_username': None,
             'resolver_profile_picture_data_url': None,
             'resolved_on_msecs': utils.get_time_in_millisecs(
                 self.MOCK_DATE),
         })
Пример #7
0
 def test_to_dict(self) -> None:
     fake_date = datetime.datetime(2016, 4, 10, 0, 0, 0, 0)
     expected_thread_dict: feedback_domain.FeedbackThreadDict = {
         'thread_id': self.THREAD_ID,
         'status': u'open',
         'state_name': u'a_state_name',
         'summary': 'test summary',
         'original_author_id': self.viewer_id,
         'message_count': 1,
         'subject': u'a subject',
         'last_updated_msecs': utils.get_time_in_millisecs(fake_date),
         'last_nonempty_message_text': 'last message',
         'last_nonempty_message_author_id': self.viewer_id,
     }
     observed_thread = feedback_domain.FeedbackThread(
         self.THREAD_ID, feconf.ENTITY_TYPE_EXPLORATION, self.EXP_ID,
         expected_thread_dict['state_name'], self.viewer_id,
         expected_thread_dict['status'], expected_thread_dict['subject'],
         expected_thread_dict['summary'], False, 1, fake_date, fake_date,
         'last message', self.viewer_id)
     # Using type ignore[arg-type] here because assertDictEqual method
     # expects both arguments to be of type Dict[Any, Any].
     self.assertDictEqual(
         expected_thread_dict,
         observed_thread.to_dict())  # type: ignore[arg-type]
Пример #8
0
    def generate_id(cls, ticket_name: str) -> str:
        """Generates key for the instance of AppFeedbackReportTicketModel
        class in the required format with the arguments provided.

        Args:
            ticket_name: str. The name assigned to the ticket on creation.

        Returns:
            str. The generated ID for this entity using the current datetime in
            milliseconds (as the entity's creation timestamp), a SHA1 hash of
            the ticket_name, and a random string, of the form
            '[creation_datetime_msec]:[hash(ticket_name)]:[random hash]'.
        """
        current_datetime_in_msec = utils.get_time_in_millisecs(
            datetime.datetime.utcnow())
        for _ in python_utils.RANGE(base_models.MAX_RETRIES):
            name_hash = utils.convert_to_hash(ticket_name,
                                              base_models.ID_LENGTH)
            random_hash = utils.convert_to_hash(
                python_utils.UNICODE(
                    utils.get_random_int(base_models.RAND_RANGE)),
                base_models.ID_LENGTH)
            new_id = '%s.%s.%s' % (int(current_datetime_in_msec), name_hash,
                                   random_hash)
            if not cls.get_by_id(new_id):
                return new_id
        raise Exception(
            'The id generator for AppFeedbackReportTicketModel is producing too'
            'many collisions.')
Пример #9
0
 def test_get_time_in_millisecs_with_complicated_time(self) -> None:
     dt = datetime.datetime(2020, 6, 15, 5, 18, 23, microsecond=123456)
     msecs = utils.get_time_in_millisecs(dt)
     self.assertEqual(
         dt,
         datetime.datetime.fromtimestamp(python_utils.divide(
             msecs, 1000.0)))  # type: ignore[no-untyped-call]
Пример #10
0
    def to_dict(self):
        """Returns a dict representation of this FeedbackThread object.

        Returns:
            dict. A dict representation of the FeedbackThread object.
        """
        return {
            'last_updated_msecs':
            (utils.get_time_in_millisecs(self.last_updated)),
            'original_author_username': (user_services.get_username(
                self.original_author_id) if self.original_author_id else None),
            'state_name':
            self.state_name,
            'status':
            self.status,
            'subject':
            self.subject,
            'summary':
            self.summary,
            'thread_id':
            self.id,
            'message_count':
            self.message_count,
            'last_nonempty_message_text':
            self.last_nonempty_message_text,
            'last_nonempty_message_author':
            (user_services.get_username(self.last_nonempty_message_author_id)
             if self.last_nonempty_message_author_id else None),
        }
Пример #11
0
    def export_data(cls, user_id: str) -> Dict[str, Dict[str, str]]:
        """Exports the data from AppFeedbackReportModel into dict format for
        Takeout.

        Args:
            user_id: str. The ID of the user whose data should be exported;
                this would be the ID of the user who has scrubbed the report.

        Returns:
            dict. Dictionary of the data from AppFeedbackReportModel.
        """
        user_data = {}
        report_models: Sequence[AppFeedbackReportModel] = (
            cls.get_all().filter(cls.scrubbed_by == user_id).fetch())
        for report_model in report_models:
            submitted_on_msec = utils.get_time_in_millisecs(
                report_model.submitted_on)
            user_data[report_model.id] = {
                'scrubbed_by': report_model.scrubbed_by,
                'platform': report_model.platform,
                'ticket_id': report_model.ticket_id,
                'submitted_on': utils.get_human_readable_time_string(
                    submitted_on_msec),
                'local_timezone_offset_hrs': (
                    report_model.local_timezone_offset_hrs),
                'report_type': report_model.report_type,
                'category': report_model.category,
                'platform_version': report_model.platform_version
            }
        return user_data
Пример #12
0
 def test_to_dict_has_expected_value(self):
     task_entry = improvements_domain.TaskEntry(
         improvements_models.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
         improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
         improvements_models.TASK_TARGET_TYPE_STATE,
         feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
         improvements_models.TASK_STATUS_RESOLVED, self.owner_id,
         self.MOCK_DATE)
     self.assertEqual(
         task_entry.to_dict(), {
             'entity_type':
             'exploration',
             'entity_id':
             self.exp_id,
             'entity_version':
             1,
             'task_type':
             'high_bounce_rate',
             'target_type':
             'state',
             'target_id':
             'Introduction',
             'issue_description':
             'issue description',
             'status':
             'resolved',
             'resolver_username':
             self.OWNER_USERNAME,
             'resolver_profile_picture_data_url':
             (user_services.DEFAULT_IDENTICON_DATA_URL),
             'resolved_on_msecs':
             utils.get_time_in_millisecs(self.MOCK_DATE),
         })
Пример #13
0
 def test_export_data_nontrivial(self) -> None:
     user_data = (feedback_models.GeneralFeedbackThreadModel.export_data(
         self.USER_ID))
     feedback_id = '%s.%s.%s' % (self.ENTITY_TYPE, self.ENTITY_ID, 'random')
     test_data = {
         feedback_id: {
             'entity_type':
             self.ENTITY_TYPE,
             'entity_id':
             self.ENTITY_ID,
             'status':
             self.STATUS,
             'subject':
             self.SUBJECT,
             'has_suggestion':
             self.HAS_SUGGESTION,
             'summary':
             self.SUMMARY,
             'message_count':
             self.MESSAGE_COUNT,
             'last_updated_msec':
             utils.get_time_in_millisecs(
                 self.feedback_thread_model.last_updated)
         }
     }
     self.assertEqual(user_data, test_data)
Пример #14
0
    def test_get_suggestions_after_updating_suggestion_summary(self):
        self.login(self.EDITOR_EMAIL)

        response_dict = self.get_json(
            '%s/%s' %
            (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID_1)
        )
        thread_id = response_dict['feedback_thread_dicts'][0]['thread_id']
        thread_url = '%s/%s' % (
            feconf.LEARNER_DASHBOARD_FEEDBACK_THREAD_DATA_URL, thread_id)
        response_dict = self.get_json(thread_url)
        messages_summary = response_dict['message_summary_list'][0]

        self.assertEqual(
            messages_summary['author_username'], self.EDITOR_USERNAME)
        self.assertTrue(test_utils.check_image_png_or_webp(
            messages_summary['author_picture_data_url']))
        self.assertFalse(messages_summary.get('suggestion_html'))
        self.assertFalse(messages_summary.get('current_content_html'))
        self.assertFalse(messages_summary.get('description'))

        new_content = state_domain.SubtitledHtml(
            'content', '<p>new content html</p>').to_dict()
        change_cmd = {
            'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
            'property_name': exp_domain.STATE_PROPERTY_CONTENT,
            'state_name': 'Welcome!',
            'new_value': new_content
        }

        suggestion_models.GeneralSuggestionModel.create(
            feconf.SUGGESTION_TYPE_EDIT_STATE_CONTENT,
            feconf.ENTITY_TYPE_EXPLORATION, self.EXP_ID_1, 1,
            suggestion_models.STATUS_IN_REVIEW, self.editor_id, None,
            change_cmd, 'score category', thread_id, None)

        suggestion_thread = feedback_services.get_thread(thread_id)
        suggestion = suggestion_services.get_suggestion_by_id(thread_id)
        exploration = exp_fetchers.get_exploration_by_id(self.EXP_ID_1)
        current_content_html = (
            exploration.states[
                suggestion.change.state_name].content.html)
        response_dict = self.get_json(thread_url)
        messages_summary = response_dict['message_summary_list'][0]
        first_suggestion = feedback_services.get_messages(thread_id)[0]

        self.assertEqual(
            messages_summary['author_username'], self.EDITOR_USERNAME)
        self.assertTrue(test_utils.check_image_png_or_webp(
            messages_summary['author_picture_data_url']))
        self.assertEqual(
            utils.get_time_in_millisecs(first_suggestion.created_on),
            messages_summary['created_on_msecs'])
        self.assertEqual(
            messages_summary['suggestion_html'], '<p>new content html</p>')
        self.assertEqual(
            messages_summary['current_content_html'], current_content_html)
        self.assertEqual(
            messages_summary['description'], suggestion_thread.subject)
        self.logout()
Пример #15
0
    def to_dict(self) -> FeedbackMessageDict:
        """Returns a dict representation of this FeedbackMessage object.

        Returns:
            dict. Dict representation of the FeedbackMessage object.
        """
        return {
            'author_username': (
                user_services.get_username(
                    self.author_id)  # type: ignore[no-untyped-call]
                if self.author_id else None),
            'created_on_msecs':
            utils.get_time_in_millisecs(self.created_on),
            'entity_type':
            self.entity_type,
            'entity_id':
            self.entity_id,
            'message_id':
            self.message_id,
            'text':
            self.text,
            'updated_status':
            self.updated_status,
            'updated_subject':
            self.updated_subject
        }
Пример #16
0
 def test_get_time_in_millisecs(self) -> None:
     dt = datetime.datetime(2020, 6, 15)
     msecs = utils.get_time_in_millisecs(dt)
     self.assertEqual(
         dt,
         datetime.datetime.fromtimestamp(python_utils.divide(
             msecs, 1000.0)))  # type: ignore[no-untyped-call]
Пример #17
0
    def generate_id(cls, platform: str,
                    submitted_on_datetime: datetime.datetime) -> str:
        """Generates key for the instance of AppFeedbackReportModel class in the
        required format with the arguments provided.

        Args:
            platform: str. The platform the user is the report from.
            submitted_on_datetime: datetime.datetime. The datetime that the
                report was submitted on in UTC.

        Returns:
            str. The generated ID for this entity using platform,
            submitted_on_sec, and a random string, of the form
            '[platform].[submitted_on_msec].[random hash]'.
        """
        submitted_datetime_in_msec = utils.get_time_in_millisecs(
            submitted_on_datetime)
        for _ in python_utils.RANGE(base_models.MAX_RETRIES):
            random_hash = utils.convert_to_hash(
                python_utils.UNICODE(
                    utils.get_random_int(base_models.RAND_RANGE)),
                base_models.ID_LENGTH)
            new_id = '%s.%s.%s' % (platform, int(submitted_datetime_in_msec),
                                   random_hash)
            if not cls.get_by_id(new_id):
                return new_id
        raise Exception(
            'The id generator for AppFeedbackReportModel is producing too '
            'many collisions.')
Пример #18
0
    def setUp(self):
        super(AugmentedSkillSummaryTests, self).setUp()
        current_time = datetime.datetime.utcnow()
        self.time_in_millisecs = utils.get_time_in_millisecs(current_time)

        self.augmented_skill_summary = skill_domain.AugmentedSkillSummary(
            'skill_id', 'description', 'en', 1, 1, 1, ['topic1'], ['math'],
            current_time, current_time)
Пример #19
0
def _get_displayable_collection_summary_dicts(collection_summaries):
    """Gets a summary of collections in human readable form.

    Args:
        collection_summaries: list(CollectionSummary). List of collection
            summary domain object.

    Returns:
        list(dict). A list of exploration summary dicts in human readable form.
        Example:

        [ {
            'category': u'A category',
            'community_owned': False,
            'id': 'eid2',
            'language_code': 'en',
            'num_views': 0,
            'objective': u'An objective',
            'status': 'public',
            'tags': [],
            'thumbnail_bg_color': '#a33f40',
            'thumbnail_icon_url': self.get_static_asset_url(
                '/images/subjects/Lightbulb.svg'),
            'title': u'Exploration 2 Albert title',
        }, ]
    """
    displayable_collection_summaries = []
    for collection_summary in collection_summaries:
        if collection_summary and collection_summary.status != (
                rights_domain.ACTIVITY_STATUS_PRIVATE):
            displayable_collection_summaries.append({
                'id':
                collection_summary.id,
                'title':
                collection_summary.title,
                'category':
                collection_summary.category,
                'activity_type':
                constants.ACTIVITY_TYPE_COLLECTION,
                'objective':
                collection_summary.objective,
                'language_code':
                collection_summary.language_code,
                'tags':
                collection_summary.tags,
                'node_count':
                collection_summary.node_count,
                'last_updated_msec':
                utils.get_time_in_millisecs(
                    collection_summary.collection_model_last_updated),
                'thumbnail_icon_url':
                (utils.get_thumbnail_icon_url_for_category(
                    collection_summary.category)),
                'thumbnail_bg_color':
                utils.get_hex_color_for_category(collection_summary.category)
            })
    return displayable_collection_summaries
Пример #20
0
    def to_dict(self):
        """Returns a dict-representation of the task.

        Returns:
            dict. Contains the following keys:
                entity_type: str. The type of entity the task entry refers to.
                    For example, "exploration".
                entity_id: str. The ID of the entity the task entry refers to.
                    For example, an exploration ID.
                entity_version: int. The version of the entity the task entry
                    refers to. For example, an exploration's version.
                task_type: str. The type of task the task entry tracks.
                target_type: str. The type of sub-entity the task entry refers
                    to. For example, "state" when entity type is "exploration".
                target_id: str. The ID of the sub-entity the task entry refers
                    to. For example, the state name of an exploration.
                issue_description: str. The sentence generated by Oppia to
                    describe why the task was created.
                status: str. Tracks the state/progress of the task entry.
                resolver_username: str. Username of the user who resolved the
                    task when status is resolved. Otherwise None.
                resolver_profile_picture_data_url: str. Profile picture URL of
                    the user who resolved the task when status is resolved.
                    Otherwise None.
                resolved_on_msecs: float. Time in milliseconds since epoch at
                    which the task was resolved when status is resolved.
                    Otherwise None.
        """
        resolver_settings = (self.resolver_id
                             and user_services.get_user_settings(
                                 self.resolver_id, strict=True))
        return {
            'entity_type':
            self.entity_type,
            'entity_id':
            self.entity_id,
            'entity_version':
            self.entity_version,
            'task_type':
            self.task_type,
            'target_type':
            self.target_type,
            'target_id':
            self.target_id,
            'issue_description':
            self.issue_description,
            'status':
            self.status,
            'resolver_username': (resolver_settings
                                  and resolver_settings.username),
            'resolver_profile_picture_data_url':
            (resolver_settings and resolver_settings.profile_picture_data_url),
            'resolved_on_msecs':
            (self.resolved_on
             and utils.get_time_in_millisecs(self.resolved_on)),
        }
Пример #21
0
    def test_to_dict(self):
        """Test to verify to_dict method of the Question Summary
        object.
        """
        expected_object_dict = {
            'id':
            'question_1',
            'question_content':
            '<p>question content</p>',
            'interaction_id':
            'TextInput',
            'last_updated_msec':
            utils.get_time_in_millisecs(self.fake_date_updated),
            'created_on_msec':
            utils.get_time_in_millisecs(self.fake_date_created),
            'misconception_ids': ['skill1-1', 'skill2-2']
        }

        self.assertEqual(expected_object_dict, self.observed_object.to_dict())
Пример #22
0
    def to_dict(self) -> FeedbackMessageDict:
        """Returns a dict representation of this FeedbackMessage object.

        Returns:
            dict. Dict representation of the FeedbackMessage object.
        """
        return {
            'author_id': self.author_id,
            'created_on_msecs': utils.get_time_in_millisecs(self.created_on),
            'entity_type': self.entity_type,
            'entity_id': self.entity_id,
            'message_id': self.message_id,
            'text': self.text,
            'updated_status': self.updated_status,
            'updated_subject': self.updated_subject
        }
Пример #23
0
 def test_to_dict(self):
     fake_date = datetime.datetime(2016, 4, 10, 0, 0, 0, 0)
     expected_message_dict = {
         'author_username': self.OWNER_USERNAME,
         'created_on_msecs': utils.get_time_in_millisecs(fake_date),
         'entity_type': feconf.ENTITY_TYPE_EXPLORATION,
         'entity_id': self.EXP_ID,
         'message_id': self.MESSAGE_ID,
         'text': 'a message text',
         'updated_status': 'open',
         'updated_subject': 'an updated subject'
     }
     observed_message = feedback_domain.FeedbackMessage(
         self.FULL_MESSAGE_ID, self.THREAD_ID, self.MESSAGE_ID,
         self.owner_id, expected_message_dict['updated_status'],
         expected_message_dict['updated_subject'],
         expected_message_dict['text'], fake_date, fake_date, False)
     self.assertDictEqual(expected_message_dict, observed_message.to_dict())
Пример #24
0
    def setUp(self):
        super(SkillSummaryTests, self).setUp()
        current_time = datetime.datetime.utcnow()
        time_in_millisecs = utils.get_time_in_millisecs(current_time)
        self.skill_summary_dict = {
            'id': 'skill_id',
            'description': 'description',
            'language_code': 'en',
            'version': 1,
            'misconception_count': 1,
            'worked_examples_count': 1,
            'skill_model_created_on': time_in_millisecs,
            'skill_model_last_updated': time_in_millisecs
        }

        self.skill_summary = skill_domain.SkillSummary('skill_id',
                                                       'description', 'en', 1,
                                                       1, 1, current_time,
                                                       current_time)
Пример #25
0
 def test_export_data_nontrivial(self):
     user_data = blog_models.BlogPostModel.export_data(self.USER_ID)
     blog_post_id = 'blog_one'
     test_data = {
         blog_post_id: {
             'title':
             self.TITLE,
             'content':
             self.CONTENT,
             'url_fragment':
             'sample-url-fragment',
             'tags':
             self.TAGS,
             'thumbnail_filename':
             self.THUMBNAIL,
             'published_on':
             utils.get_time_in_millisecs(self.blog_post_model.published_on)
         }
     }
     self.assertEqual(user_data, test_data)
Пример #26
0
 def test_to_dict(self) -> None:
     fake_date = datetime.datetime(2016, 4, 10, 0, 0, 0, 0)
     expected_message_dict: feedback_domain.FeedbackMessageDict = {
         'author_username': self.OWNER_USERNAME,
         'created_on_msecs': utils.get_time_in_millisecs(fake_date),
         'entity_type': feconf.ENTITY_TYPE_EXPLORATION,
         'entity_id': self.EXP_ID,
         'message_id': self.MESSAGE_ID,
         'text': 'a message text',
         'updated_status': 'open',
         'updated_subject': 'an updated subject'
     }
     observed_message = feedback_domain.FeedbackMessage(
         self.FULL_MESSAGE_ID, self.THREAD_ID, self.MESSAGE_ID,
         self.owner_id, expected_message_dict['updated_status'],
         expected_message_dict['updated_subject'],
         expected_message_dict['text'], fake_date, fake_date, False)
     # Using type ignore[arg-type] here because assertDictEqual method
     # expects both arguments to be of type Dict[Any, Any].
     self.assertDictEqual(
         expected_message_dict, observed_message.to_dict()) # type: ignore[arg-type]
Пример #27
0
    def to_dict(self):
        """Returns dict representation of the FeedbackThreadSummary object.

        Returns:
            dict. Dict representation of the FeedbackThreadSummary object.
        """
        return {
            'status': self.status,
            'original_author_id': self.original_author_id,
            'last_updated_msecs':
            (utils.get_time_in_millisecs(self.last_updated)),
            'last_message_text': self.last_message_text,
            'total_message_count': self.total_message_count,
            'last_message_is_read': self.last_message_is_read,
            'second_last_message_is_read': self.second_last_message_is_read,
            'author_last_message': self.author_last_message,
            'author_second_last_message': self.author_second_last_message,
            'exploration_title': self.exploration_title,
            'exploration_id': self.exploration_id,
            'thread_id': self.thread_id,
        }
Пример #28
0
 def test_to_dict(self):
     fake_date = datetime.datetime(2016, 4, 10, 0, 0, 0, 0)
     expected_thread_dict = {
         'thread_id': self.THREAD_ID,
         'status': u'open',
         'state_name': u'a_state_name',
         'summary': None,
         'original_author_username': self.VIEWER_USERNAME,
         'message_count': 1,
         'subject': u'a subject',
         'last_updated_msecs': utils.get_time_in_millisecs(fake_date),
         'last_nonempty_message_text': 'last message',
         'last_nonempty_message_author': self.VIEWER_USERNAME,
     }
     observed_thread = feedback_domain.FeedbackThread(
         self.THREAD_ID, feconf.ENTITY_TYPE_EXPLORATION, self.EXP_ID,
         expected_thread_dict['state_name'], self.viewer_id,
         expected_thread_dict['status'], expected_thread_dict['subject'],
         expected_thread_dict['summary'], False, 1, fake_date, fake_date,
         'last message', self.viewer_id)
     self.assertDictEqual(expected_thread_dict, observed_thread.to_dict())
Пример #29
0
    def test_get_all_unscrubbed_expiring_report_models(self) -> None:
        expired_timestamp = datetime.datetime.utcnow() - (
            feconf.APP_FEEDBACK_REPORT_MAXIMUM_LIFESPAN +
            datetime.timedelta(days=10))
        expired_model = app_feedback_report_models.AppFeedbackReportModel(
            id='%s.%s.%s' % (
                self.PLATFORM_ANDROID,
                int(utils.get_time_in_millisecs(expired_timestamp)),
                'randomInteger123'),
            platform=self.PLATFORM_ANDROID,
            scrubbed_by=None,
            ticket_id='%s.%s.%s' % (
                'random_hash',
                int(self.TICKET_CREATION_TIMESTAMP_MSEC),
                '16CharString1234'),
            submitted_on=expired_timestamp,
            local_timezone_offset_hrs=0,
            report_type=self.REPORT_TYPE_SUGGESTION,
            category=self.CATEGORY_OTHER,
            platform_version=self.PLATFORM_VERSION,
            android_device_country_locale_code=(
                self.DEVICE_COUNTRY_LOCALE_CODE_INDIA),
            android_device_model=self.ANDROID_DEVICE_MODEL,
            android_sdk_version=self.ANDROID_SDK_VERSION,
            entry_point=self.ENTRY_POINT_NAVIGATION_DRAWER,
            text_language_code=self.TEXT_LANGUAGE_CODE_ENGLISH,
            audio_language_code=self.AUDIO_LANGUAGE_CODE_ENGLISH,
            android_report_info=self.ANDROID_REPORT_INFO,
            android_report_info_schema_version=(
                self.ANDROID_REPORT_INFO_SCHEMA_VERSION)
        )
        expired_model.created_on = expired_timestamp
        expired_model.put()

        model_class = app_feedback_report_models.AppFeedbackReportModel
        model_entities = model_class.get_all_unscrubbed_expiring_report_models()

        self.assertEqual(len(model_entities), 1)
        self.assertEqual(model_entities[0].id, expired_model.id)
Пример #30
0
 def test_to_dict_has_expected_value(self) -> None:
     # Data url for images/avatar/user_blue_72px.png.
     # Generated using utils.convert_png_to_data_url.
     task_entry = improvements_domain.TaskEntry(
         constants.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
         constants.TASK_TYPE_HIGH_BOUNCE_RATE,
         constants.TASK_TARGET_TYPE_STATE,
         feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
         constants.TASK_STATUS_RESOLVED, self.owner_id,
         self.MOCK_DATE)
     self.assertEqual(task_entry.to_dict(), {
         'entity_type': 'exploration',
         'entity_id': self.exp_id,
         'entity_version': 1,
         'task_type': 'high_bounce_rate',
         'target_type': 'state',
         'target_id': 'Introduction',
         'issue_description': 'issue description',
         'status': 'resolved',
         'resolver_username': None,
         'resolver_profile_picture_data_url': None,
         'resolved_on_msecs': utils.get_time_in_millisecs(self.MOCK_DATE),
     })