Example #1
0
    def test_unpublished_activity_is_removed_from_featured_list(self) -> None:
        rights_manager.publish_exploration(self.owner, self.EXP_ID_0) # type: ignore[no-untyped-call]
        rights_manager.publish_exploration(self.owner, self.EXP_ID_1) # type: ignore[no-untyped-call]
        rights_manager.publish_collection(self.owner, self.COL_ID_2) # type: ignore[no-untyped-call]
        activity_services.update_featured_activity_references([
            self._create_exploration_reference(self.EXP_ID_0),
            self._create_collection_reference(self.COL_ID_2)])

        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])

        # Unpublishing an unfeatured activity does not affect the featured
        # list.
        rights_manager.unpublish_exploration(self.moderator, self.EXP_ID_1) # type: ignore[no-untyped-call]
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])

        # Unpublishing a featured activity removes it from the featured list.
        rights_manager.unpublish_collection(self.moderator, self.COL_ID_2) # type: ignore[no-untyped-call]
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0)])

        rights_manager.unpublish_exploration(self.moderator, self.EXP_ID_0) # type: ignore[no-untyped-call]
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Example #2
0
    def test_deleted_activity_is_removed_from_featured_list(self):
        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_0)
        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_1)
        rights_manager.publish_collection(self.owner_id, self.COL_ID_2)
        activity_services.update_featured_activity_references([
            self._create_exploration_reference(self.EXP_ID_0),
            self._create_collection_reference(self.COL_ID_2)])

        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])

        # Deleting an unfeatured activity does not affect the featured list.
        exp_services.delete_exploration(self.owner_id, self.EXP_ID_1)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])

        # Deleting a featured activity removes it from the featured list.
        collection_services.delete_collection(self.owner_id, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0)])
        exp_services.delete_exploration(self.owner_id, self.EXP_ID_0)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Example #3
0
    def test_update_featured_refs_clears_existing_featured_activities(self):
        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_0)
        activity_services.update_featured_activity_references([
            self._create_exploration_reference(self.EXP_ID_0)])
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0)])

        activity_services.update_featured_activity_references([])
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
    def test_publish_activity_does_not_affect_featured_list(self):
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        rights_manager.publish_exploration(self.owner, self.EXP_ID_0)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        rights_manager.publish_collection(self.owner, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Example #5
0
    def test_publish_activity_does_not_affect_featured_list(self) -> None:
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        rights_manager.publish_exploration(self.owner, self.EXP_ID_0) # type: ignore[no-untyped-call]
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        rights_manager.publish_collection(self.owner, self.COL_ID_2) # type: ignore[no-untyped-call]
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Example #6
0
    def test_update_featured_refs_correctly_promotes_activities(self) -> None:
        rights_manager.publish_exploration(self.owner, self.EXP_ID_0) # type: ignore[no-untyped-call]
        rights_manager.publish_collection(self.owner, self.COL_ID_2) # type: ignore[no-untyped-call]
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        activity_services.update_featured_activity_references([
            self._create_exploration_reference(self.EXP_ID_0),
            self._create_collection_reference(self.COL_ID_2)])
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])
Example #7
0
    def test_update_featured_refs_correctly_promotes_activities(self):
        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_0)
        rights_manager.publish_collection(self.owner_id, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        activity_services.update_featured_activity_references([
            self._create_exploration_reference(self.EXP_ID_0),
            self._create_collection_reference(self.COL_ID_2)])
        self._compare_lists(
            activity_services.get_featured_activity_references(), [
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_collection_reference(self.COL_ID_2)])
    def test_update_featured_refs_clears_existing_featured_activities(
            self) -> None:
        rights_manager.publish_exploration(
            self.owner, self.EXP_ID_0)  # type: ignore[no-untyped-call]
        activity_services.update_featured_activity_references(
            [self._create_exploration_reference(self.EXP_ID_0)])
        self._compare_lists(
            activity_services.get_featured_activity_references(),
            [self._create_exploration_reference(self.EXP_ID_0)])

        activity_services.update_featured_activity_references([])
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Example #9
0
def get_featured_activity_summary_dicts(language_codes):
    """Returns a list of featured activities with the given language codes.

    The return value is sorted according to the list stored in the datastore.
    """
    activity_references = activity_services.get_featured_activity_references()
    exploration_ids, collection_ids = activity_services.split_by_type(
        activity_references)

    exp_summary_dicts = get_displayable_exp_summary_dicts_matching_ids(
        exploration_ids)
    col_summary_dicts = get_displayable_collection_summary_dicts_matching_ids(
        collection_ids)

    summary_dicts_by_id = {
        feconf.ACTIVITY_TYPE_EXPLORATION: {
            summary_dict['id']: summary_dict
            for summary_dict in exp_summary_dicts
        },
        feconf.ACTIVITY_TYPE_COLLECTION: {
            summary_dict['id']: summary_dict
            for summary_dict in col_summary_dicts
        },
    }

    featured_summary_dicts = []
    for reference in activity_references:
        if reference.id in summary_dicts_by_id[reference.type]:
            summary_dict = summary_dicts_by_id[reference.type][reference.id]
            if summary_dict and summary_dict['language_code'] in language_codes:
                featured_summary_dicts.append(summary_dict)
    return featured_summary_dicts
Example #10
0
def get_featured_activity_summary_dicts(language_codes):
    """Returns a list of featured activities with the given language codes.

    The return value is sorted according to the list stored in the datastore.
    """
    activity_references = activity_services.get_featured_activity_references()
    exploration_ids, collection_ids = activity_services.split_by_type(
        activity_references)

    exp_summary_dicts = get_displayable_exp_summary_dicts_matching_ids(
        exploration_ids)
    col_summary_dicts = get_displayable_collection_summary_dicts_matching_ids(
        collection_ids)

    summary_dicts_by_id = {
        feconf.ACTIVITY_TYPE_EXPLORATION: {
            summary_dict['id']: summary_dict
            for summary_dict in exp_summary_dicts
        },
        feconf.ACTIVITY_TYPE_COLLECTION: {
            summary_dict['id']: summary_dict
            for summary_dict in col_summary_dicts
        },
    }

    featured_summary_dicts = []
    for reference in activity_references:
        if reference.id in summary_dicts_by_id[reference.type]:
            summary_dict = summary_dicts_by_id[reference.type][reference.id]
            if summary_dict and summary_dict['language_code'] in language_codes:
                featured_summary_dicts.append(summary_dict)
    return featured_summary_dicts
Example #11
0
 def get(self):
     """Handles GET requests."""
     self.render_json({
         'featured_activity_references': [
             activity_reference.to_dict() for activity_reference in
             activity_services.get_featured_activity_references()
         ],
     })
Example #12
0
 def get(self):
     """Handles GET requests."""
     self.render_json({
         'featured_activity_references': [
             activity_reference.to_dict() for activity_reference in
             activity_services.get_featured_activity_references()
         ],
     })
Example #13
0
    def test_deleted_activity_is_removed_from_featured_list_multiple(self):
        rights_manager.publish_exploration(self.owner, self.EXP_ID_0)
        rights_manager.publish_exploration(self.owner, self.EXP_ID_1)
        exploration_references = [
            self._create_exploration_reference(self.EXP_ID_0),
            self._create_exploration_reference(self.EXP_ID_1)]
        activity_services.update_featured_activity_references(
            exploration_references)

        self._compare_lists(
            activity_services.get_featured_activity_references(),
            exploration_references)

        exp_services.delete_explorations(
            self.owner_id, [self.EXP_ID_0, self.EXP_ID_1])
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
    def test_publish_or_publicize_activity_does_not_affect_featured_list(self):
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_0)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
        rights_manager.publicize_exploration(self.moderator_id, self.EXP_ID_0)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
        rights_manager.unpublicize_exploration(
            self.moderator_id, self.EXP_ID_0)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        rights_manager.publish_collection(self.owner_id, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
        rights_manager.publicize_collection(self.moderator_id, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
        rights_manager.unpublicize_collection(
            self.moderator_id, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Example #15
0
    def test_updating_with_duplicate_refs_raises_exception(self) -> None:
        rights_manager.publish_exploration(self.owner, self.EXP_ID_0) # type: ignore[no-untyped-call]
        rights_manager.publish_collection(self.owner, self.COL_ID_2) # type: ignore[no-untyped-call]
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        with self.assertRaisesRegex(Exception, 'should not have duplicates'): # type: ignore[no-untyped-call]
            activity_services.update_featured_activity_references([
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_exploration_reference(self.EXP_ID_0)])
Example #16
0
    def test_updating_with_duplicate_refs_raises_exception(self):
        rights_manager.publish_exploration(self.owner_id, self.EXP_ID_0)
        rights_manager.publish_collection(self.owner_id, self.COL_ID_2)
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])

        with self.assertRaisesRegexp(Exception, 'should not have duplicates'):
            activity_services.update_featured_activity_references([
                self._create_exploration_reference(self.EXP_ID_0),
                self._create_exploration_reference(self.EXP_ID_0)])
Example #17
0
def get_featured_activity_summary_dicts(language_codes):
    """Returns a list of featured activities with the given language codes.
    The return value is sorted according to the list stored in the datastore.

    Args:
        language_codes: list(str). A list of language codes. Only explorations
            with these languages will be returned.

    Return:
        list(dict). Each dict in this list represents a featured activity.
        For example:

        [ {
            'status': 'public',
            'thumbnail_bg_color': '#a33f40',
            'community_owned': False,
            'tags': [],
            'thumbnail_icon_url': self.get_static_asset_url(
                '/images/subjects/Lightbulb.svg'),
            'language_code': feconf.DEFAULT_LANGUAGE_CODE,
            'id': 'eid2',
            'category': 'A category',
            'ratings': feconf.get_empty_ratings(),
            'title': 'A title',
            'num_views': 0,
            'objective': 'An objective',
        }, ]
    """
    activity_references = activity_services.get_featured_activity_references()
    exploration_ids, collection_ids = activity_services.split_by_type(
        activity_references)

    exp_summary_dicts = get_displayable_exp_summary_dicts_matching_ids(
        exploration_ids)
    col_summary_dicts = get_displayable_collection_summary_dicts_matching_ids(
        collection_ids)

    summary_dicts_by_id = {
        feconf.ACTIVITY_TYPE_EXPLORATION: {
            summary_dict['id']: summary_dict
            for summary_dict in exp_summary_dicts
        },
        feconf.ACTIVITY_TYPE_COLLECTION: {
            summary_dict['id']: summary_dict
            for summary_dict in col_summary_dicts
        },
    }

    featured_summary_dicts = []
    for reference in activity_references:
        if reference.id in summary_dicts_by_id[reference.type]:
            summary_dict = summary_dicts_by_id[reference.type][reference.id]
            if summary_dict and summary_dict['language_code'] in language_codes:
                featured_summary_dicts.append(summary_dict)
    return featured_summary_dicts
Example #18
0
def get_featured_activity_summary_dicts(language_codes):
    """Returns a list of featured activities with the given language codes.
    The return value is sorted according to the list stored in the datastore.

    Args:
        language_codes: list(str). A list of language codes. Only explorations
            with these languages will be returned.

    Returns:
        list(dict). Each dict in this list represents a featured activity.
        For example:

        [ {
            'status': 'public',
            'thumbnail_bg_color': '#a33f40',
            'community_owned': False,
            'tags': [],
            'thumbnail_icon_url': self.get_static_asset_url(
                '/images/subjects/Lightbulb.svg'),
            'language_code': constants.DEFAULT_LANGUAGE_CODE,
            'id': 'eid2',
            'category': 'A category',
            'ratings': feconf.get_empty_ratings(),
            'title': 'A title',
            'num_views': 0,
            'objective': 'An objective',
        }, ]
    """
    activity_references = activity_services.get_featured_activity_references()
    exploration_ids, collection_ids = activity_services.split_by_type(
        activity_references)

    exp_summary_dicts = get_displayable_exp_summary_dicts_matching_ids(
        exploration_ids)
    col_summary_dicts = get_displayable_collection_summary_dicts_matching_ids(
        collection_ids)

    summary_dicts_by_id = {
        constants.ACTIVITY_TYPE_EXPLORATION: {
            summary_dict['id']: summary_dict
            for summary_dict in exp_summary_dicts
        },
        constants.ACTIVITY_TYPE_COLLECTION: {
            summary_dict['id']: summary_dict
            for summary_dict in col_summary_dicts
        },
    }

    featured_summary_dicts = []
    for reference in activity_references:
        if reference.id in summary_dicts_by_id[reference.type]:
            summary_dict = summary_dicts_by_id[reference.type][reference.id]
            if summary_dict and summary_dict['language_code'] in language_codes:
                featured_summary_dicts.append(summary_dict)
    return featured_summary_dicts