Esempio n. 1
0
    def setUp(self):
        super(ModeratorEmailsTest, self).setUp()
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.EDITOR_ID = self.get_user_id_from_email(self.EDITOR_EMAIL)

        self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME)
        self.MODERATOR_ID = self.get_user_id_from_email(self.MODERATOR_EMAIL)
        self.set_moderators([self.MODERATOR_EMAIL])

        # The editor publishes an exploration.
        self.EXP_ID = 'eid'
        self.save_new_valid_exploration(
            self.EXP_ID, self.EDITOR_ID, title='My Exploration',
            end_state_name='END')
        rights_manager.publish_exploration(self.EDITOR_ID, self.EXP_ID)

        # Set the default email config.
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.ADMIN_ID = self.get_user_id_from_email(self.ADMIN_EMAIL)
        config_services.set_property(
            self.ADMIN_ID, 'publicize_exploration_email_html_body',
            'Default publicization email body')
        config_services.set_property(
            self.ADMIN_ID, 'unpublish_exploration_email_html_body',
            'Default unpublishing email body')
Esempio n. 2
0
    def test_published_explorations_are_visible_to_logged_in_users(self):
        rights_manager.publish_exploration(self.editor_id, self.EXP_ID)

        self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME)
        self.login(self.VIEWER_EMAIL)
        response = self.testapp.get("%s/%s" % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID), expect_errors=True)
        self.assertEqual(response.status_int, 200)
Esempio n. 3
0
    def test_deletion_rights_for_published_exploration(self):
        """Test rights management for deletion of published explorations."""
        PUBLISHED_EXP_ID = "published_eid"
        exploration = exp_domain.Exploration.create_default_exploration(PUBLISHED_EXP_ID, "A title", "A category")
        exp_services.save_new_exploration(self.owner_id, exploration)

        rights_manager.assign_role(self.owner_id, PUBLISHED_EXP_ID, self.editor_id, rights_manager.ROLE_EDITOR)
        rights_manager.publish_exploration(self.owner_id, PUBLISHED_EXP_ID)

        self.login(self.EDITOR_EMAIL)
        response = self.testapp.delete("/createhandler/data/%s" % PUBLISHED_EXP_ID, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.VIEWER_EMAIL)
        response = self.testapp.delete("/createhandler/data/%s" % PUBLISHED_EXP_ID, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.OWNER_EMAIL)
        response = self.testapp.delete("/createhandler/data/%s" % PUBLISHED_EXP_ID, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.ADMIN_EMAIL)
        response = self.testapp.delete("/createhandler/data/%s" % PUBLISHED_EXP_ID)
        self.assertEqual(response.status_int, 200)
        self.logout()
    def setUp(self):
        """Before each individual test, set up dummy explorations, users
        and admin."""
        super(RecommendationsServicesUnitTests, self).setUp()

        for name, user in self.USER_DATA.iteritems():
            user["id"] = self.get_user_id_from_email(user["email"])
            user_services.get_or_create_user(user["id"], user["email"])
            self.signup(user["email"], name)
            self.USER_DATA[name]["id"] = user["id"]

        self.EXP_DATA["exp_id_1"]["owner_id"] = self.USER_DATA["alice"]["id"]
        self.EXP_DATA["exp_id_2"]["owner_id"] = self.USER_DATA["alice"]["id"]
        self.EXP_DATA["exp_id_3"]["owner_id"] = self.USER_DATA["bob"]["id"]
        self.EXP_DATA["exp_id_4"]["owner_id"] = self.USER_DATA["charlie"]["id"]

        self.explorations = []
        for exp_id, exp in self.EXP_DATA.iteritems():
            self.save_new_valid_exploration(exp_id, exp["owner_id"], category=exp["category"])
            rights_manager.publish_exploration(exp["owner_id"], exp_id)

        self.ADMIN_ID = self.get_user_id_from_email(self.ADMIN_EMAIL)
        user_services.get_or_create_user(self.ADMIN_ID, self.ADMIN_EMAIL)
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.set_admins([self.ADMIN_EMAIL])
Esempio n. 5
0
    def test_managers_can_see_explorations(self):
        self.save_new_default_exploration(
            self.EXP_ID, self.owner_id, title=self.EXP_TITLE)
        self.set_admins([self.OWNER_EMAIL])

        self.login(self.OWNER_EMAIL)
        response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_manager.ACTIVITY_STATUS_PRIVATE)

        rights_manager.publish_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_manager.ACTIVITY_STATUS_PUBLIC)

        rights_manager.publicize_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_manager.ACTIVITY_STATUS_PUBLICIZED)
        self.logout()
    def setUp(self):
        """Before each individual test, set up dummy explorations, users
        and admin."""
        super(RecommendationsServicesUnitTests, self).setUp()

        for name, user in self.USER_DATA.iteritems():
            user['id'] = self.get_user_id_from_email(
                user['email'])
            user_services.get_or_create_user(user['id'], user['email'])
            self.signup(user['email'], name)
            self.USER_DATA[name]['id'] = user['id']

        self.EXP_DATA['exp_id_1']['owner_id'] = self.USER_DATA['alice']['id']
        self.EXP_DATA['exp_id_2']['owner_id'] = self.USER_DATA['alice']['id']
        self.EXP_DATA['exp_id_3']['owner_id'] = self.USER_DATA['bob']['id']
        self.EXP_DATA['exp_id_4']['owner_id'] = self.USER_DATA['charlie']['id']

        for exp_id, exp in self.EXP_DATA.iteritems():
            self.save_new_valid_exploration(
                exp_id, exp['owner_id'], category=exp['category'])
            rights_manager.publish_exploration(exp['owner_id'], exp_id)

        self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
        user_services.get_or_create_user(
            self.admin_id, self.ADMIN_EMAIL)
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.set_admins([self.ADMIN_USERNAME])
Esempio n. 7
0
    def test_deletion_rights_for_published_exploration(self):
        """Test rights management for deletion of published explorations."""
        published_exp_id = 'published_eid'
        exploration = exp_domain.Exploration.create_default_exploration(
            published_exp_id, 'A title', 'A category')
        exp_services.save_new_exploration(self.owner_id, exploration)

        rights_manager.assign_role_for_exploration(
            self.owner_id, published_exp_id, self.editor_id,
            rights_manager.ROLE_EDITOR)
        rights_manager.publish_exploration(self.owner_id, published_exp_id)

        self.login(self.EDITOR_EMAIL)
        response = self.testapp.delete(
            '/createhandler/data/%s' % published_exp_id, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.VIEWER_EMAIL)
        response = self.testapp.delete(
            '/createhandler/data/%s' % published_exp_id, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.OWNER_EMAIL)
        response = self.testapp.delete(
            '/createhandler/data/%s' % published_exp_id, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.ADMIN_EMAIL)
        response = self.testapp.delete(
            '/createhandler/data/%s' % published_exp_id)
        self.assertEqual(response.status_int, 200)
        self.logout()
Esempio n. 8
0
    def test_no_username_shown_for_logged_out_learners(self):
        NEW_EXP_ID = 'new_eid'
        exploration = exp_domain.Exploration.create_default_exploration(
            NEW_EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.EDITOR_ID, exploration)
        rights_manager.publish_exploration(self.EDITOR_ID, NEW_EXP_ID)

        response = self.testapp.get('/create/%s' % NEW_EXP_ID)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(
            '/explorehandler/give_feedback/%s' % NEW_EXP_ID,
            {
                'state_name': None,
                'subject': 'Test thread',
                'feedback': 'Test thread text',
                'include_author': False,
            }, csrf_token)

        response_dict = self.get_json(
            '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, NEW_EXP_ID))
        threadlist = response_dict['threads']
        self.assertIsNone(threadlist[0]['original_author_username'])

        response_dict = self.get_json('%s/%s/%s' % (
            feconf.FEEDBACK_THREAD_URL_PREFIX, NEW_EXP_ID,
            threadlist[0]['thread_id']))
        self.assertIsNone(response_dict['messages'][0]['author_username'])
Esempio n. 9
0
    def test_collaborators_can_see_explorations(self):
        self.save_new_default_exploration(
            self.EXP_ID, self.owner_id, title=self.EXP_TITLE)
        rights_manager.assign_role_for_exploration(
            self.owner_id, self.EXP_ID, self.collaborator_id,
            rights_manager.ROLE_EDITOR)
        self.set_admins([self.OWNER_USERNAME])

        self.login(self.COLLABORATOR_EMAIL)
        response = self.get_json(feconf.DASHBOARD_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_manager.ACTIVITY_STATUS_PRIVATE)

        rights_manager.publish_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(feconf.DASHBOARD_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_manager.ACTIVITY_STATUS_PUBLIC)

        rights_manager.publicize_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(feconf.DASHBOARD_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_manager.ACTIVITY_STATUS_PUBLICIZED)

        self.logout()
Esempio n. 10
0
    def test_community_owned_exploration(self):
        with self.swap(
                subscription_services, 'subscribe_to_thread', self._null_fn
            ), self.swap(
                subscription_services, 'subscribe_to_exploration',
                self._null_fn):
            # User A adds user B as an editor to the exploration.
            rights_manager.assign_role_for_exploration(
                self.user_a_id, self.EXP_ID_1, self.user_b_id,
                rights_manager.ROLE_EDITOR)
            # The exploration becomes community-owned.
            rights_manager.publish_exploration(self.user_a_id, self.EXP_ID_1)
            rights_manager.release_ownership_of_exploration(
                self.user_a_id, self.EXP_ID_1)
            # User C edits the exploration.
            exp_services.update_exploration(
                self.user_c_id, self.EXP_ID_1, [], 'Update exploration')

        self._run_one_off_job()

        # User A and user B are subscribed to the exploration; user C is not.
        user_a_subscriptions_model = user_models.UserSubscriptionsModel.get(
            self.user_a_id)
        user_b_subscriptions_model = user_models.UserSubscriptionsModel.get(
            self.user_b_id)
        user_c_subscriptions_model = user_models.UserSubscriptionsModel.get(
            self.user_c_id, strict=False)

        self.assertEqual(
            user_a_subscriptions_model.activity_ids, [self.EXP_ID_1])
        self.assertEqual(
            user_b_subscriptions_model.activity_ids, [self.EXP_ID_1])
        self.assertEqual(user_c_subscriptions_model, None)
Esempio n. 11
0
    def setUp(self):
        super(FlagExplorationHandlerTests, self).setUp()

        # Register users.
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.signup(self.NEW_USER_EMAIL, self.NEW_USER_USERNAME)
        self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME)

        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
        self.new_user_id = self.get_user_id_from_email(self.NEW_USER_EMAIL)
        self.moderator_id = self.get_user_id_from_email(self.MODERATOR_EMAIL)
        self.set_moderators([self.MODERATOR_USERNAME])

        # Load exploration 0.
        exp_services.load_demo(self.EXP_ID)

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

        # Create exploration.
        self.save_new_valid_exploration(
            self.EXP_ID,
            self.editor_id,
            title="Welcome to Oppia!",
            category="This is just a spam category",
            objective="Test a spam exploration.",
        )
        self.can_send_emails_ctx = self.swap(feconf, "CAN_SEND_EMAILS", True)
        rights_manager.publish_exploration(self.editor_id, self.EXP_ID)
        self.logout()
Esempio n. 12
0
    def test_published_explorations_are_visible_to_logged_out_users(self):
        rights_manager.publish_exploration(self.editor_id, self.EXP_ID)

        response = self.testapp.get(
            '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID),
            expect_errors=True)
        self.assertEqual(response.status_int, 200)
    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(), [])
Esempio n. 14
0
    def test_edited(self):
        # Check that the profile page for a user who has created
        # a single exploration shows 0 created and 1 edited exploration.
        self.signup(self.EMAIL_A, self.USERNAME_A)
        user_a_id = self.get_user_id_from_email(self.EMAIL_A)

        self.signup(self.EMAIL_B, self.USERNAME_B)
        user_b_id = self.get_user_id_from_email(self.EMAIL_B)

        self.save_new_valid_exploration(
            self.EXP_ID_1, user_a_id, end_state_name='End')
        rights_manager.publish_exploration(user_a_id, self.EXP_ID_1)

        exp_services.update_exploration(user_b_id, self.EXP_ID_1, [{
            'cmd': 'edit_exploration_property',
            'property_name': 'objective',
            'new_value': 'the objective'
        }], 'Test edit')

        response_dict = self.get_json(
            '/profilehandler/data/%s' % self.USERNAME_B)
        self.assertEqual(len(
            response_dict['created_exp_summary_dicts']), 0)
        self.assertEqual(len(
            response_dict['edited_exp_summary_dicts']), 1)
        self.assertEqual(
            response_dict['edited_exp_summary_dicts'][0]['id'],
            self.EXP_ID_1)
        self.assertEqual(
            response_dict['edited_exp_summary_dicts'][0]['objective'],
            'the objective')
    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(), [])
Esempio n. 16
0
    def test_no_username_shown_for_nonregistered_users(self):
        NEW_EXP_ID = 'new_eid'
        exploration = exp_domain.Exploration.create_default_exploration(
            NEW_EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.EDITOR_ID, exploration)
        rights_manager.publish_exploration(self.EDITOR_ID, NEW_EXP_ID)

        self.login('*****@*****.**')
        response = self.testapp.get('/create/%s' % NEW_EXP_ID)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(
            '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, NEW_EXP_ID),
            {
                'state_name': None,
                'subject': 'Test thread',
                'text': 'Test thread text',
            }, csrf_token)

        response_dict = self.get_json(
            '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, NEW_EXP_ID))
        threadlist = response_dict['threads']
        self.assertIsNone(threadlist[0]['original_author_username'])

        response_dict = self.get_json('%s/%s/%s' % (
            feconf.FEEDBACK_THREAD_URL_PREFIX, NEW_EXP_ID,
            threadlist[0]['thread_id']))
        self.assertIsNone(response_dict['messages'][0]['author_username'])

        self.logout()
Esempio n. 17
0
def load_demo(exploration_id):
    """Loads a demo exploration.

    The resulting exploration will have version 2 (one for its initial
    creation and one for its subsequent modification.)
    """
    # TODO(sll): Speed this method up. It is too slow.
    delete_demo(exploration_id)

    if not (0 <= int(exploration_id) < len(feconf.DEMO_EXPLORATIONS)):
        raise Exception('Invalid demo exploration id %s' % exploration_id)

    exploration_info = feconf.DEMO_EXPLORATIONS[int(exploration_id)]

    if len(exploration_info) == 3:
        (exp_filename, title, category) = exploration_info
    else:
        raise Exception('Invalid demo exploration: %s' % exploration_info)

    yaml_content, assets_list = get_demo_exploration_components(exp_filename)
    save_new_exploration_from_yaml_and_assets(
        feconf.ADMIN_COMMITTER_ID, yaml_content, title, category,
        exploration_id, assets_list)

    rights_manager.publish_exploration(
        feconf.ADMIN_COMMITTER_ID, exploration_id)
    # Release ownership of all explorations.
    rights_manager.release_ownership(
        feconf.ADMIN_COMMITTER_ID, exploration_id)

    logging.info('Exploration with id %s was loaded.' % exploration_id)
Esempio n. 18
0
    def setUp(self):
        """Populate the database of explorations and their summaries.

        The sequence of events is:
        - (1) Albert creates EXP_ID_1.
        - (2) Albert creates EXP_ID_2.
        - (3) Albert publishes EXP_ID_1.
        - (4) Albert publishes EXP_ID_2.
        - (5) Admin user is set up.
        """

        super(FeaturedExplorationDisplayableSummariesTest, self).setUp()

        self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
        self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL)
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME)

        self.save_new_valid_exploration(
            self.EXP_ID_1, self.albert_id, language_code=self.LANGUAGE_CODE_ES)
        self.save_new_valid_exploration(self.EXP_ID_2, self.albert_id)

        rights_manager.publish_exploration(self.albert_id, self.EXP_ID_1)
        rights_manager.publish_exploration(self.albert_id, self.EXP_ID_2)

        self.set_admins([self.ADMIN_USERNAME])
Esempio n. 19
0
    def test_deletion_rights_for_published_exploration(self):
        """Test rights management for deletion of published explorations."""
        PUBLISHED_EXP_ID = 'published_eid'
        exploration = exp_domain.Exploration.create_default_exploration(
            PUBLISHED_EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.owner_id, exploration)

        rights_manager.assign_role(
            self.owner_id, PUBLISHED_EXP_ID, self.editor_id,
            rights_manager.ROLE_EDITOR)
        rights_manager.publish_exploration(self.owner_id, PUBLISHED_EXP_ID)

        self.login(self.editor_email)
        response = self.testapp.delete(
            '/createhandler/data/%s' % PUBLISHED_EXP_ID, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.viewer_email)
        response = self.testapp.delete(
            '/createhandler/data/%s' % PUBLISHED_EXP_ID, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.owner_email)
        response = self.testapp.delete(
            '/createhandler/data/%s' % PUBLISHED_EXP_ID, expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.admin_email)
        response = self.testapp.delete(
            '/createhandler/data/%s' % PUBLISHED_EXP_ID)
        self.assertEqual(response.status_int, 200)
        self.logout()
Esempio n. 20
0
    def test_collaborators_can_see_explorations_on_dashboard(self):
        self.save_new_default_exploration(
            self.EXP_ID, self.OWNER_ID, title=self.EXP_TITLE)
        rights_manager.assign_role(
            self.OWNER_ID, self.EXP_ID, self.COLLABORATOR_ID,
            rights_manager.ROLE_EDITOR)
        self.set_admins([self.OWNER_EMAIL])

        self.login(self.COLLABORATOR_EMAIL)
        response = self.get_json('/dashboardhandler/data')
        self.assertEqual(len(response['explorations']), 1)
        self.assertIn(self.EXP_ID, response['explorations'])
        self.assertEqual(
            response['explorations'][self.EXP_ID]['rights']['status'],
            rights_manager.EXPLORATION_STATUS_PRIVATE)

        rights_manager.publish_exploration(self.OWNER_ID, self.EXP_ID)
        response = self.get_json('/dashboardhandler/data')
        self.assertEqual(len(response['explorations']), 1)
        self.assertIn(self.EXP_ID, response['explorations'])
        self.assertEqual(
            response['explorations'][self.EXP_ID]['rights']['status'],
            rights_manager.EXPLORATION_STATUS_PUBLIC)

        rights_manager.publicize_exploration(self.OWNER_ID, self.EXP_ID)
        response = self.get_json('/dashboardhandler/data')
        self.assertEqual(len(response['explorations']), 1)
        self.assertIn(self.EXP_ID, response['explorations'])
        self.assertEqual(
            response['explorations'][self.EXP_ID]['rights']['status'],
            rights_manager.EXPLORATION_STATUS_PUBLICIZED)

        self.logout()
Esempio n. 21
0
    def test_changing_viewability_of_exploration(self):
        exp = exp_domain.Exploration.create_default_exploration(
            self.EXP_ID, title='A title', category='A category')
        exp_services.save_new_exploration(self.user_id_a, exp)

        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        self.assertTrue(rights_manager.Actor(
            self.user_id_a).can_change_private_viewability(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertFalse(rights_manager.Actor(
            self.user_id_b).can_change_private_viewability(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertTrue(rights_manager.Actor(
            self.user_id_admin).can_change_private_viewability(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        with self.assertRaisesRegexp(Exception, 'already the current value'):
            rights_manager.set_private_viewability_of_exploration(
                self.user_id_a, self.EXP_ID, False)
        with self.assertRaisesRegexp(Exception, 'cannot be changed'):
            rights_manager.set_private_viewability_of_exploration(
                self.user_id_b, self.EXP_ID, True)

        rights_manager.set_private_viewability_of_exploration(
            self.user_id_a, self.EXP_ID, True)
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertTrue(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        rights_manager.set_private_viewability_of_exploration(
            self.user_id_a, self.EXP_ID, False)
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        rights_manager.publish_exploration(self.user_id_a, self.EXP_ID)
        self.assertFalse(rights_manager.Actor(
            self.user_id_a).can_change_private_viewability(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        rights_manager.unpublish_exploration(self.user_id_admin, self.EXP_ID)
        self.assertTrue(rights_manager.Actor(
            self.user_id_a).can_change_private_viewability(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertFalse(rights_manager.Actor(
            self.user_id_b).can_change_private_viewability(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertTrue(rights_manager.Actor(
            self.user_id_admin).can_change_private_viewability(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
Esempio n. 22
0
    def test_cannot_delete_published_exploration(self):
        exp = exp_domain.Exploration.create_default_exploration(
            self.EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.user_id_a, exp)

        rights_manager.publish_exploration(self.user_id_a, self.EXP_ID)
        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_delete(self.EXP_ID))
Esempio n. 23
0
 def reduce(exp_id, list_of_exps):
     for stringified_exp in list_of_exps:
         exploration = exp_domain.Exploration.from_untitled_yaml(
             exp_id, 'Copy', 'Copies', stringified_exp)
         exp_services.save_new_exploration(
             feconf.SYSTEM_COMMITTER_ID, exploration)
         rights_manager.publish_exploration(
             feconf.SYSTEM_COMMITTER_ID, exp_id)
Esempio n. 24
0
    def test_published_explorations_are_visible_to_anyone(self):
        rights_manager.publish_exploration(self.first_editor_id, self.EXP_ID)

        response = self.testapp.get(
            '%s/%s' % (feconf.EXPLORATION_URL_PREFIX, self.EXP_ID),
            expect_errors=True)
        self.assertEqual(response.status_int, 200)
        self.assertNotIn('This is a preview', response.body)
    def reduce(exp_id, list_of_exps):
        from core.domain import exp_services
        from core.domain import rights_manager

        for stringified_exp in list_of_exps:
            exploration = exp_domain.Exploration.from_yaml(exp_id, "Copy", "Copies", stringified_exp)
            exp_services.save_new_exploration(feconf.SYSTEM_COMMITTER_ID, exploration)
            rights_manager.publish_exploration(feconf.SYSTEM_COMMITTER_ID, exp_id)
Esempio n. 26
0
    def setUp(self):
        super(FeaturedActivitiesHandlerTest, self).setUp()
        self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME)
        self.set_moderators([self.MODERATOR_USERNAME])

        self.save_new_valid_exploration(self.EXP_ID_1, self.ALBERT_ID)
        rights_manager.publish_exploration(self.ALBERT_ID, self.EXP_ID_1)

        self.save_new_valid_exploration(self.EXP_ID_2, self.ALBERT_ID)
Esempio n. 27
0
    def test_demand_commit_message(self):
        """Check published explorations demand commit messages"""
        rights_manager.publish_exploration(self.OWNER_ID, self.EXP_ID)

        with self.assertRaisesRegexp(
                ValueError, 'Exploration is public so expected a commit '
                            'message but received none.'):
            exp_services.update_exploration(
                self.OWNER_ID, self.EXP_ID, _get_change_list(
                    self.init_state_name, 'widget_sticky', False), '')
    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)])
    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(), [])
Esempio n. 30
0
    def test_record_commit_message(self):
        """Check published explorations record commit messages."""
        rights_manager.publish_exploration(self.OWNER_ID, self.EXP_ID)

        exp_services.update_exploration(
            self.OWNER_ID, self.EXP_ID, _get_change_list(
                self.init_state_name, 'widget_sticky', False), 'A message')

        self.assertEqual(
            exp_services.get_exploration_snapshots_metadata(
                self.EXP_ID, 1)[0]['commit_message'],
            'A message')
Esempio n. 31
0
    def test_first_published_time_of_exploration_that_is_unpublished(self):
        """This tests that, if an exploration is published, unpublished, and
        then published again, the job uses the first publication time as the
        value for first_published_msec.
        """
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
        self.set_admins([self.ADMIN_USERNAME])

        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
        owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
        owner = user_services.UserActionsInfo(owner_id)
        admin = user_services.UserActionsInfo(admin_id)

        self.save_new_valid_exploration(
            self.EXP_ID, owner_id, end_state_name='End')
        rights_manager.publish_exploration(owner, self.EXP_ID)
        job_class = exp_jobs_one_off.ExplorationFirstPublishedOneOffJob
        job_id = job_class.create_new()
        exp_jobs_one_off.ExplorationFirstPublishedOneOffJob.enqueue(job_id)
        self.process_and_flush_pending_tasks()
        exploration_rights = rights_manager.get_exploration_rights(self.EXP_ID)

        # Test to see whether first_published_msec was correctly updated.
        exp_first_published = exploration_rights.first_published_msec
        exp_rights_model = exp_models.ExplorationRightsModel.get(self.EXP_ID)
        last_updated_time_msec = utils.get_time_in_millisecs(
            exp_rights_model.last_updated)
        self.assertLess(
            exp_first_published, last_updated_time_msec)

        rights_manager.unpublish_exploration(admin, self.EXP_ID)
        rights_manager.publish_exploration(owner, self.EXP_ID)
        job_id = job_class.create_new()
        exp_jobs_one_off.ExplorationFirstPublishedOneOffJob.enqueue(job_id)
        self.process_and_flush_pending_tasks()

        # Test to see whether first_published_msec remains the same despite the
        # republication.
        exploration_rights = rights_manager.get_exploration_rights(self.EXP_ID)
        self.assertEqual(
            exp_first_published, exploration_rights.first_published_msec)
Esempio n. 32
0
    def setUp(self) -> None:
        super(ActivityRightsTests, self).setUp()
        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
        self.owner_id = self.get_user_id_from_email(
            self.OWNER_EMAIL)  # type: ignore[no-untyped-call]
        self.owner = user_services.get_user_actions_info(
            self.owner_id)  # type: ignore[no-untyped-call]
        self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME)
        self.viewer_id = self.get_user_id_from_email(
            self.VIEWER_EMAIL)  # type: ignore[no-untyped-call]
        self.viewer = user_services.get_user_actions_info(
            self.viewer_id)  # type: ignore[no-untyped-call]

        self.exp_id = 'exp_id'
        self.save_new_valid_exploration(
            self.exp_id, self.owner_id)  # type: ignore[no-untyped-call]
        rights_manager.publish_exploration(
            self.owner, self.exp_id)  # type: ignore[no-untyped-call]
        self.activity_rights = rights_manager.get_exploration_rights(  # type: ignore[no-untyped-call]
            self.exp_id)
Esempio n. 33
0
    def test_can_only_delete_unpublished_explorations(self):
        exp = exp_domain.Exploration.create_default_exploration(
            self.EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.user_id_a, exp)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        rights_manager.publish_exploration(self.user_id_a, self.EXP_ID)

        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        rights_manager.unpublish_exploration(self.user_id_admin, self.EXP_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_delete(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
Esempio n. 34
0
 def setUp(self):
     super(EditExplorationTest, self).setUp()
     self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
     self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME)
     self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
     self.signup(self.user_email, self.username)
     self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
     self.set_moderators([self.MODERATOR_USERNAME])
     self.set_admins([self.ADMIN_USERNAME])
     self.set_banned_users([self.username])
     self.owner = user_services.UserActionsInfo(self.owner_id)
     self.testapp = webtest.TestApp(webapp2.WSGIApplication(
         [webapp2.Route('/mock/<exploration_id>', self.MockHandler)],
         debug=feconf.DEBUG,
     ))
     self.save_new_valid_exploration(
         self.published_exp_id, self.owner_id)
     self.save_new_valid_exploration(
         self.private_exp_id, self.owner_id)
     rights_manager.publish_exploration(self.owner, self.published_exp_id)
Esempio n. 35
0
    def test_created(self):
        # Check that the profile page for a user who has created
        # a single exploration shows 1 created and 1 edited exploration.
        self.signup(self.EMAIL_A, self.USERNAME_A)
        user_a_id = self.get_user_id_from_email(self.EMAIL_A)
        user_a = user_services.UserActionsInfo(user_a_id)
        self.save_new_valid_exploration(self.EXP_ID_1,
                                        user_a_id,
                                        end_state_name='End')
        rights_manager.publish_exploration(user_a, self.EXP_ID_1)

        response_dict = self.get_json('/profilehandler/data/%s' %
                                      self.USERNAME_A)

        self.assertEqual(len(response_dict['created_exp_summary_dicts']), 1)
        self.assertEqual(len(response_dict['edited_exp_summary_dicts']), 1)
        self.assertEqual(response_dict['created_exp_summary_dicts'][0]['id'],
                         self.EXP_ID_1)
        self.assertEqual(response_dict['edited_exp_summary_dicts'][0]['id'],
                         self.EXP_ID_1)
Esempio n. 36
0
    def test_viewer_cannot_see_explorations_on_dashboard(self):
        self.save_new_default_exploration(self.EXP_ID,
                                          self.OWNER_ID,
                                          title=self.EXP_TITLE)
        rights_manager.assign_role(self.OWNER_ID, self.EXP_ID, self.VIEWER_ID,
                                   rights_manager.ROLE_VIEWER)

        self.login(self.VIEWER_EMAIL)
        response = self.get_json('/dashboardhandler/data')
        self.assertEqual(response['explorations'], {})

        rights_manager.publish_exploration(self.OWNER_ID, self.EXP_ID)
        response = self.get_json('/dashboardhandler/data')
        self.assertEqual(response['explorations'], {})

        self.set_admins([self.OWNER_EMAIL])
        rights_manager.publicize_exploration(self.OWNER_ID, self.EXP_ID)
        response = self.get_json('/dashboardhandler/data')
        self.assertEqual(response['explorations'], {})
        self.logout()
Esempio n. 37
0
    def test_can_only_delete_unpublished_explorations(self):
        exp = exp_domain.Exploration.create_default_exploration(
            self.EXP_ID, title='A title', category='A category')
        exp_services.save_new_exploration(self.user_id_a, exp)
        exp_rights = rights_manager.get_exploration_rights(self.EXP_ID)

        self.assertTrue(rights_manager.check_can_delete_activity(
            self.user_a, exp_rights))

        rights_manager.publish_exploration(self.user_a, self.EXP_ID)
        exp_rights = rights_manager.get_exploration_rights(self.EXP_ID)

        self.assertFalse(rights_manager.check_can_delete_activity(
            self.user_a, exp_rights))

        rights_manager.unpublish_exploration(self.user_admin, self.EXP_ID)
        exp_rights = rights_manager.get_exploration_rights(self.EXP_ID)

        self.assertTrue(rights_manager.check_can_delete_activity(
            self.user_a, exp_rights))
    def setUp(self):
        """Before each individual test, set up dummy explorations and users."""
        super(RecommendationsServicesUnitTests, self).setUp()

        for name, user in self.USER_DATA.items():
            self.signup(user['email'], name)
            user['id'] = self.get_user_id_from_email(user['email'])
            self.USER_DATA[name]['id'] = user['id']

        self.EXP_DATA['exp_id_1']['owner_id'] = self.USER_DATA['alice']['id']
        self.EXP_DATA['exp_id_2']['owner_id'] = self.USER_DATA['alice']['id']
        self.EXP_DATA['exp_id_3']['owner_id'] = self.USER_DATA['bob']['id']
        self.EXP_DATA['exp_id_4']['owner_id'] = self.USER_DATA['charlie']['id']

        for exp_id, exp in self.EXP_DATA.items():
            self.save_new_valid_exploration(exp_id,
                                            exp['owner_id'],
                                            category=exp['category'])
            owner = user_services.get_user_actions_info(exp['owner_id'])
            rights_manager.publish_exploration(owner, exp_id)
Esempio n. 39
0
    def test_viewer_cannot_see_explorations(self):
        self.save_new_default_exploration(
            self.EXP_ID, self.owner_id, title=self.EXP_TITLE)
        rights_manager.assign_role_for_exploration(
            self.owner_id, self.EXP_ID, self.viewer_id,
            rights_manager.ROLE_VIEWER)
        self.set_admins([self.OWNER_USERNAME])

        self.login(self.VIEWER_EMAIL)
        response = self.get_json(feconf.DASHBOARD_DATA_URL)
        self.assertEqual(response['explorations_list'], [])

        rights_manager.publish_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(feconf.DASHBOARD_DATA_URL)
        self.assertEqual(response['explorations_list'], [])

        rights_manager.publicize_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(feconf.DASHBOARD_DATA_URL)
        self.assertEqual(response['explorations_list'], [])
        self.logout()
Esempio n. 40
0
    def test_managers_can_see_explorations(self):
        self.save_new_default_exploration(
            self.EXP_ID, self.owner_id, title=self.EXP_TITLE)
        self.set_admins([self.OWNER_USERNAME])

        self.login(self.OWNER_EMAIL)
        response = self.get_json(feconf.CREATOR_DASHBOARD_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_domain.ACTIVITY_STATUS_PRIVATE)

        rights_manager.publish_exploration(self.owner, self.EXP_ID)
        response = self.get_json(feconf.CREATOR_DASHBOARD_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(
            response['explorations_list'][0]['status'],
            rights_domain.ACTIVITY_STATUS_PUBLIC)

        self.logout()
Esempio n. 41
0
    def test_deleted_activity_is_removed_from_featured_list_multiple(
            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]
        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(  # type: ignore[no-untyped-call]
            self.owner_id, [self.EXP_ID_0, self.EXP_ID_1])
        self._compare_lists(
            activity_services.get_featured_activity_references(), [])
Esempio n. 42
0
    def setUp(self):
        super(FeedbackThreadTests, self).setUp()

        self.signup(self.OWNER_EMAIL_1, self.OWNER_USERNAME_1)
        self.signup(self.OWNER_EMAIL_2, self.OWNER_USERNAME_2)
        self.signup(self.USER_EMAIL, self.USER_USERNAME)
        self.owner_id_1 = self.get_user_id_from_email(self.OWNER_EMAIL_1)
        self.owner_id_2 = self.get_user_id_from_email(self.OWNER_EMAIL_2)
        self.user_id = self.get_user_id_from_email(self.USER_EMAIL)
        self.owner_2 = user_services.UserActionsInfo(self.owner_id_2)

        # Create an exploration.
        self.save_new_valid_exploration(self.EXP_ID,
                                        self.owner_id_1,
                                        title=self.EXP_TITLE,
                                        category='Architecture',
                                        language_code='en')

        rights_manager.create_new_exploration_rights(self.EXP_ID,
                                                     self.owner_id_2)
        rights_manager.publish_exploration(self.owner_2, self.EXP_ID)
Esempio n. 43
0
    def setUp(self):
        """Completes the sign-up process for self.VOICE_ARTIST_EMAIL."""
        super(VoiceArtistManagementTests, self).setUp()
        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
        self.signup(self.VOICE_ARTIST_EMAIL, self.VOICE_ARTIST_USERNAME)
        self.signup(self.VOICEOVER_ADMIN_EMAIL, self.VOICEOVER_ADMIN_USERNAME)

        self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
        self.voice_artist_id = self.get_user_id_from_email(
            self.VOICE_ARTIST_EMAIL)
        self.voiceover_admin_id = self.get_user_id_from_email(
            self.VOICEOVER_ADMIN_EMAIL)
        self.owner = user_services.get_user_actions_info(self.owner_id)
        self.save_new_valid_exploration(self.published_exp_id_1, self.owner_id)
        self.save_new_valid_exploration(self.published_exp_id_2, self.owner_id)
        self.save_new_valid_exploration(self.private_exp_id_1, self.owner_id)
        self.save_new_valid_exploration(self.private_exp_id_2, self.owner_id)
        rights_manager.publish_exploration(self.owner, self.published_exp_id_1)
        rights_manager.publish_exploration(self.owner, self.published_exp_id_2)
        user_services.update_user_role(self.voiceover_admin_id,
                                       feconf.ROLE_ID_VOICEOVER_ADMIN)
Esempio n. 44
0
    def setUp(self):
        """Populate the database of explorations and their summaries.

        The sequence of events is:
        - (1) Albert creates EXP_ID_1.
        - (2) Bob edits the title of EXP_ID_1.
        - (3) Albert creates EXP_ID_2.
        - (4) Albert edits the title of EXP_ID_1.
        - (5) Albert edits the title of EXP_ID_2.
        - (6) Bob reverts Albert's last edit to EXP_ID_1.
        - Bob tries to publish EXP_ID_2, and is denied access.
        - (7) Albert publishes EXP_ID_2.
        - (8) Albert creates EXP_ID_3
        - (9) Albert publishes EXP_ID_3
        - (10) Albert deletes EXP_ID_3
        """
        super(ExplorationDisplayableSummaries, self).setUp()

        self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL)
        self.bob_id = self.get_user_id_from_email(self.BOB_EMAIL)
        self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME)
        self.signup(self.BOB_EMAIL, self.BOB_NAME)

        self.save_new_valid_exploration(self.EXP_ID_1, self.albert_id)

        exp_services.update_exploration(
            self.bob_id, self.EXP_ID_1, [{
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration 1 title'
            }], 'Changed title.')

        self.save_new_valid_exploration(self.EXP_ID_2, self.albert_id)

        exp_services.update_exploration(
            self.albert_id, self.EXP_ID_1, [{
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration 1 Albert title'
            }], 'Changed title to Albert1 title.')

        exp_services.update_exploration(
            self.albert_id, self.EXP_ID_2, [{
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration 2 Albert title'
            }], 'Changed title to Albert2 title.')

        exp_services.revert_exploration(self.bob_id, self.EXP_ID_1, 3, 2)

        with self.assertRaisesRegexp(
            Exception, 'This exploration cannot be published'
            ):
            rights_manager.publish_exploration(self.bob_id, self.EXP_ID_2)

        rights_manager.publish_exploration(self.albert_id, self.EXP_ID_2)

        self.save_new_valid_exploration(self.EXP_ID_3, self.albert_id)
        rights_manager.publish_exploration(self.albert_id, self.EXP_ID_3)
        exp_services.delete_exploration(self.albert_id, self.EXP_ID_3)
Esempio n. 45
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(), [])
    def test_get_learner_dict_when_referencing_inaccessible_explorations(self):
        self.save_new_default_collection(self.COLLECTION_ID, self.owner_id)
        self.save_new_valid_exploration(self.EXP_ID, self.editor_id)
        collection_services.update_collection(
            self.owner_id, self.COLLECTION_ID, [{
                'cmd': collection_domain.CMD_ADD_COLLECTION_NODE,
                'exploration_id': self.EXP_ID
            }], 'Added another creator\'s private exploration')

        # A collection cannot access someone else's private exploration.
        rights_manager.publish_collection(self.owner, self.COLLECTION_ID)
        with self.assertRaisesRegex(
            utils.ValidationError,
            'Expected collection to only reference valid explorations, but '
            'found an exploration with ID: exploration_id'):
            summary_services.get_learner_collection_dict_by_id(
                self.COLLECTION_ID, self.owner)

        # After the exploration is published, the dict can now be created.
        rights_manager.publish_exploration(self.editor, self.EXP_ID)
        summary_services.get_learner_collection_dict_by_id(
            self.COLLECTION_ID, self.owner)
Esempio n. 47
0
    def test_deletion_rights_for_published_exploration(self):
        """Test rights management for deletion of published explorations."""
        PUBLISHED_EXP_ID = 'published_eid'
        exploration = exp_domain.Exploration.create_default_exploration(
            PUBLISHED_EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.owner_id, exploration)

        rights_manager.assign_role_for_exploration(self.owner_id,
                                                   PUBLISHED_EXP_ID,
                                                   self.editor_id,
                                                   rights_manager.ROLE_EDITOR)
        rights_manager.publish_exploration(self.owner_id, PUBLISHED_EXP_ID)

        self.login(self.EDITOR_EMAIL)
        response = self.testapp.delete('/createhandler/data/%s' %
                                       PUBLISHED_EXP_ID,
                                       expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.VIEWER_EMAIL)
        response = self.testapp.delete('/createhandler/data/%s' %
                                       PUBLISHED_EXP_ID,
                                       expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.OWNER_EMAIL)
        response = self.testapp.delete('/createhandler/data/%s' %
                                       PUBLISHED_EXP_ID,
                                       expect_errors=True)
        self.assertEqual(response.status_int, 401)
        self.logout()

        self.login(self.ADMIN_EMAIL)
        response = self.testapp.delete('/createhandler/data/%s' %
                                       PUBLISHED_EXP_ID)
        self.assertEqual(response.status_int, 200)
        self.logout()
Esempio n. 48
0
    def _generate_dummy_explorations(
            self, num_dummy_exps_to_generate, num_dummy_exps_to_publish):
        """Generates and publishes the given number of dummy explorations.

        Args:
            num_dummy_exps_to_generate: int. Count of dummy explorations to
                be generated.
            num_dummy_exps_to_publish: int. Count of explorations to
                be published.

        Raises:
            Exception. Environment is not DEVMODE.
        """

        if constants.DEV_MODE:
            logging.info(
                '[ADMIN] %s generated %s number of dummy explorations' %
                (self.user_id, num_dummy_exps_to_generate))
            possible_titles = ['Hulk Neuroscience', 'Quantum Starks',
                               'Wonder Anatomy',
                               'Elvish, language of "Lord of the Rings',
                               'The Science of Superheroes']
            exploration_ids_to_publish = []
            for i in python_utils.RANGE(num_dummy_exps_to_generate):
                title = random.choice(possible_titles)
                category = random.choice(constants.SEARCH_DROPDOWN_CATEGORIES)
                new_exploration_id = exp_fetchers.get_new_exploration_id()
                exploration = exp_domain.Exploration.create_default_exploration(
                    new_exploration_id, title=title, category=category,
                    objective='Dummy Objective')
                exp_services.save_new_exploration(self.user_id, exploration)
                if i <= num_dummy_exps_to_publish - 1:
                    exploration_ids_to_publish.append(new_exploration_id)
                    rights_manager.publish_exploration(
                        self.user, new_exploration_id)
            exp_services.index_explorations_given_ids(
                exploration_ids_to_publish)
        else:
            raise Exception('Cannot generate dummy explorations in production.')
Esempio n. 49
0
    def test_can_not_publish_collection_with_invalid_payload_version(self):
        self.set_collection_editors([self.OWNER_USERNAME])

        # Login as owner and try to publish a collection with a public
        # exploration.
        self.login(self.OWNER_EMAIL)
        collection_id = collection_services.get_new_collection_id()
        exploration_id = exp_services.get_new_exploration_id()
        self.save_new_valid_exploration(exploration_id, self.owner_id)
        self.save_new_valid_collection(collection_id,
                                       self.owner_id,
                                       exploration_id=exploration_id)
        rights_manager.publish_exploration(self.owner, exploration_id)
        response = self.get_html_response(
            '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID))
        csrf_token = self.get_csrf_token_from_response(response)

        # Raises error as version is None.
        response_dict = self.put_json('/collection_editor_handler/publish/%s' %
                                      collection_id, {'version': None},
                                      csrf_token=csrf_token,
                                      expected_status_int=400)

        self.assertEqual(response_dict['error'],
                         'Invalid POST request: a version must be specified.')

        # Raises error as version from payload does not match the collection
        # version.
        response_dict = self.put_json('/collection_editor_handler/publish/%s' %
                                      collection_id, {'version': 2},
                                      csrf_token=csrf_token,
                                      expected_status_int=400)

        self.assertEqual(
            response_dict['error'],
            'Trying to update version 1 of collection from version 2, '
            'which is too old. Please reload the page and try again.')

        self.logout()
    def setUp(self):
        super(SuggestionMigrationOneOffJobTest, 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.editor = user_services.UserActionsInfo(self.editor_id)

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

        # Create exploration.
        self.save_new_valid_exploration(self.EXP_ID,
                                        self.editor_id,
                                        title='Exploration for suggestions',
                                        category='Algebra',
                                        objective='Test a suggestion.')

        exploration = exp_services.get_exploration_by_id(self.EXP_ID)
        init_state = exploration.states[exploration.init_state_name]
        init_interaction = init_state.interaction
        init_interaction.default_outcome.dest = exploration.init_state_name
        exploration.add_states(['State 1'])

        self.old_content = exp_domain.SubtitledHtml('content',
                                                    'old content').to_dict()

        # Create content in State A with a single audio subtitle.
        exploration.states['State 1'].update_content(self.old_content)
        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)
Esempio n. 51
0
    def test_publishing_and_unpublishing_exploration(self):
        exp = exp_domain.Exploration.create_default_exploration(
            self.EXP_ID, title='A title', category='A category')
        exp_services.save_new_exploration(self.user_id_a, exp)

        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_play(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        rights_manager.publish_exploration(self.user_id_a, self.EXP_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_b).can_play(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertTrue(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_a).can_unpublish(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))

        rights_manager.unpublish_exploration(self.user_id_admin, self.EXP_ID)

        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_play(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertTrue(
            rights_manager.Actor(self.user_id_a).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_play(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
        self.assertFalse(
            rights_manager.Actor(self.user_id_b).can_view(
                rights_manager.ACTIVITY_TYPE_EXPLORATION, self.EXP_ID))
    def test_get_learner_dict_with_private_exp_fails_validation(self):
        self.save_new_valid_collection(
            self.COLLECTION_ID, self.owner_id, exploration_id=self.EXP_ID)

        # Since both the collection and exploration are private, the learner
        # dict can be created.
        summary_services.get_learner_collection_dict_by_id(
            self.COLLECTION_ID, self.owner)

        # A public collection referencing a private exploration is bad, however.
        rights_manager.publish_collection(self.owner, self.COLLECTION_ID)
        with self.assertRaisesRegex(
            utils.ValidationError,
            'Cannot reference a private exploration within a public '
            'collection, exploration ID: exploration_id'):
            summary_services.get_learner_collection_dict_by_id(
                self.COLLECTION_ID, self.owner)

        # After the exploration is published, the learner dict can be crated
        # again.
        rights_manager.publish_exploration(self.owner, self.EXP_ID)
        summary_services.get_learner_collection_dict_by_id(
            self.COLLECTION_ID, self.owner)
Esempio n. 53
0
 def setUp(self):
     super(CheckCanUnpublishActivityTest, self).setUp()
     self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
     self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
     self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME)
     self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
     self.moderator_id = self.get_user_id_from_email(self.MODERATOR_EMAIL)
     self.set_admins([self.ADMIN_USERNAME])
     self.set_moderators([self.MODERATOR_USERNAME])
     self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
     self.admin = user_services.UserActionsInfo(self.admin_id)
     self.owner = user_services.UserActionsInfo(self.owner_id)
     self.moderator = user_services.UserActionsInfo(self.moderator_id)
     self.save_new_valid_exploration(self.published_exp_id, self.owner_id)
     self.save_new_valid_exploration(self.private_exp_id, self.owner_id)
     self.save_new_valid_collection(self.published_col_id,
                                    self.owner_id,
                                    exploration_id=self.published_col_id)
     self.save_new_valid_collection(self.private_col_id,
                                    self.owner_id,
                                    exploration_id=self.private_col_id)
     rights_manager.publish_exploration(self.owner, self.published_exp_id)
     rights_manager.publish_collection(self.owner, self.published_col_id)
Esempio n. 54
0
    def setUp(self):
        super(ModeratorEmailsTest, self).setUp()
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)

        self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME)
        self.set_moderators([self.MODERATOR_EMAIL])

        # The editor publishes an exploration.
        self.save_new_valid_exploration(
            self.EXP_ID, self.editor_id, title='My Exploration',
            end_state_name='END')
        rights_manager.publish_exploration(self.editor_id, self.EXP_ID)

        # Set the default email config.
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
        config_services.set_property(
            self.admin_id, 'publicize_exploration_email_html_body',
            'Default publicization email body')
        config_services.set_property(
            self.admin_id, 'unpublish_exploration_email_html_body',
            'Default unpublishing email body')
Esempio n. 55
0
    def test_managers_can_see_explorations(self):
        self.save_new_default_exploration(self.EXP_ID,
                                          self.owner_id,
                                          title=self.EXP_TITLE)
        self.set_admins([self.OWNER_EMAIL])

        self.login(self.OWNER_EMAIL)
        response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(response['explorations_list'][0]['status'],
                         rights_manager.EXPLORATION_STATUS_PRIVATE)

        rights_manager.publish_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(response['explorations_list'][0]['status'],
                         rights_manager.EXPLORATION_STATUS_PUBLIC)

        rights_manager.publicize_exploration(self.owner_id, self.EXP_ID)
        response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
        self.assertEqual(len(response['explorations_list']), 1)
        self.assertEqual(response['explorations_list'][0]['status'],
                         rights_manager.EXPLORATION_STATUS_PUBLICIZED)
        self.logout()
    def setUp(self):
        super(CollectionNodeMetadataDictsTest, self).setUp()

        self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME)
        self.signup(self.BOB_EMAIL, self.BOB_NAME)
        self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL)
        self.bob_id = self.get_user_id_from_email(self.BOB_EMAIL)

        self.albert = user_services.get_user_actions_info(self.albert_id)
        self.bob = user_services.get_user_actions_info(self.bob_id)

        self.save_new_valid_exploration(
            self.EXP_ID1, self.albert_id,
            title='Exploration 1 Albert title',
            objective='An objective 1')

        self.save_new_valid_exploration(
            self.EXP_ID2, self.albert_id,
            title='Exploration 2 Albert title',
            objective='An objective 2')

        self.save_new_valid_exploration(
            self.EXP_ID3, self.albert_id,
            title='Exploration 3 Albert title',
            objective='An objective 3')

        self.save_new_valid_exploration(
            self.EXP_ID4, self.bob_id,
            title='Exploration 4 Bob title',
            objective='An objective 4')

        self.save_new_valid_exploration(
            self.EXP_ID5, self.albert_id,
            title='Exploration 5 Albert title',
            objective='An objective 5')

        rights_manager.publish_exploration(self.albert, self.EXP_ID1)
        rights_manager.publish_exploration(self.albert, self.EXP_ID2)
        rights_manager.publish_exploration(self.albert, self.EXP_ID3)
        rights_manager.publish_exploration(self.bob, self.EXP_ID4)

        exp_services.index_explorations_given_ids([
            self.EXP_ID1, self.EXP_ID2, self.EXP_ID3,
            self.EXP_ID4])
Esempio n. 57
0
    def setUp(self):
        """Populate the database of explorations and their summaries.

        The sequence of events is:
        - (1) Albert creates EXP_ID_1.
        - (2) Albert creates EXP_ID_2.
        - (3) Albert creates EXP_ID_3.
        - (4) Albert publishes EXP_ID_1.
        - (5) Albert publishes EXP_ID_2.
        - (6) Albert publishes EXP_ID_3.
        - (7) Admin user is set up.
        """

        super(RecentlyPublishedExplorationDisplayableSummariesTest,
              self).setUp()

        self.signup(self.CURRICULUM_ADMIN_EMAIL,
                    self.CURRICULUM_ADMIN_USERNAME)
        self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME)
        self.admin_id = self.get_user_id_from_email(
            self.CURRICULUM_ADMIN_EMAIL)
        self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL)
        self.albert = user_services.get_user_actions_info(self.albert_id)

        self.save_new_valid_exploration(self.EXP_ID_1,
                                        self.albert_id,
                                        end_state_name='End')
        self.save_new_valid_exploration(self.EXP_ID_2,
                                        self.albert_id,
                                        end_state_name='End')
        self.save_new_valid_exploration(self.EXP_ID_3,
                                        self.albert_id,
                                        end_state_name='End')

        rights_manager.publish_exploration(self.albert, self.EXP_ID_2)
        rights_manager.publish_exploration(self.albert, self.EXP_ID_1)
        rights_manager.publish_exploration(self.albert, self.EXP_ID_3)

        self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME])
    def setUp(self):
        """Populate the database of explorations and their summaries.

        The sequence of events is:
        - (1) Albert creates EXP_ID_1.
        - (2) Bob edits the title of EXP_ID_1.
        - (3) Albert creates EXP_ID_2.
        - (4) Albert edits the title of EXP_ID_1.
        - (5) Albert edits the title of EXP_ID_2.
        - (6) Bob reverts Albert's last edit to EXP_ID_1.
        - Bob tries to publish EXP_ID_2, and is denied access.
        - (7) Albert publishes EXP_ID_2.
        - (8) Albert creates EXP_ID_3
        - (9) Albert publishes EXP_ID_3
        - (10) Albert deletes EXP_ID_3

        - (1) User_3 (has a profile_picture) creates EXP_ID_4.
        - (2) User_4 edits the title of EXP_ID_4.
        - (3) User_4 edits the title of EXP_ID_4.
        """

        super(ExplorationDisplayableSummariesTest, self).setUp()

        self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME)
        self.signup(self.BOB_EMAIL, self.BOB_NAME)

        self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL)
        self.bob_id = self.get_user_id_from_email(self.BOB_EMAIL)

        self.albert = user_services.get_user_actions_info(self.albert_id)
        self.bob = user_services.get_user_actions_info(self.bob_id)

        self.save_new_valid_exploration(self.EXP_ID_1, self.albert_id)

        exp_services.update_exploration(
            self.bob_id, self.EXP_ID_1, [exp_domain.ExplorationChange({
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration 1 title'
            })], 'Changed title.')

        self.save_new_valid_exploration(self.EXP_ID_2, self.albert_id)

        exp_services.update_exploration(
            self.albert_id, self.EXP_ID_1, [exp_domain.ExplorationChange({
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration 1 Albert title'
            })], 'Changed title to Albert1 title.')

        exp_services.update_exploration(
            self.albert_id, self.EXP_ID_2, [exp_domain.ExplorationChange({
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration 2 Albert title'
            })], 'Changed title to Albert2 title.')

        exp_services.revert_exploration(self.bob_id, self.EXP_ID_1, 3, 2)

        with self.assertRaisesRegex(
            Exception, 'This exploration cannot be published'
            ):
            rights_manager.publish_exploration(self.bob, self.EXP_ID_2)

        rights_manager.publish_exploration(self.albert, self.EXP_ID_2)

        self.save_new_valid_exploration(self.EXP_ID_3, self.albert_id)
        rights_manager.publish_exploration(self.albert, self.EXP_ID_3)
        exp_services.delete_exploration(self.albert_id, self.EXP_ID_3)
        self.signup(self.USER_C_EMAIL, self.USER_C_NAME)
        self.signup(self.USER_D_EMAIL, self.USER_D_NAME)
        self.user_c_id = self.get_user_id_from_email(self.USER_C_EMAIL)
        self.user_d_id = self.get_user_id_from_email(self.USER_D_EMAIL)
        user_services.update_profile_picture_data_url(
            self.user_c_id, self.USER_C_PROFILE_PICTURE)

        self.save_new_valid_exploration(self.EXP_ID_4, self.user_c_id)
        exp_services.update_exploration(
            self.user_d_id, self.EXP_ID_4, [exp_domain.ExplorationChange({
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration updated title'
            })], 'Changed title once.')

        exp_services.update_exploration(
            self.user_d_id, self.EXP_ID_4, [exp_domain.ExplorationChange({
                'cmd': 'edit_exploration_property',
                'property_name': 'title',
                'new_value': 'Exploration updated title again'
            })], 'Changed title twice.')

        self.save_new_valid_exploration(self.EXP_ID_5, self.bob_id)
Esempio n. 59
0
    def test_library_handler_for_created_explorations(self):
        """Test the library data handler for manually created explorations."""
        self.set_admins([self.ADMIN_USERNAME])

        self.login(self.ADMIN_EMAIL)
        response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL)
        self.assertDictContainsSubset(
            {
                'is_admin': True,
                'is_moderator': True,
                'is_super_admin': False,
                'activity_list': [],
                'user_email': self.ADMIN_EMAIL,
                'username': self.ADMIN_USERNAME,
                'search_cursor': None,
            }, response_dict)

        # Create exploration A.
        exploration = self.save_new_valid_exploration('A',
                                                      self.admin_id,
                                                      title='Title A',
                                                      category='Category A',
                                                      objective='Objective A')
        exp_services._save_exploration(  # pylint: disable=protected-access
            self.admin_id, exploration, 'Exploration A', [])

        # Test that the private exploration isn't displayed.
        response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL)
        self.assertEqual(response_dict['activity_list'], [])

        # Create exploration B.
        exploration = self.save_new_valid_exploration('B',
                                                      self.admin_id,
                                                      title='Title B',
                                                      category='Category B',
                                                      objective='Objective B')
        exp_services._save_exploration(  # pylint: disable=protected-access
            self.admin_id, exploration, 'Exploration B', [])
        rights_manager.publish_exploration(self.admin, 'B')

        # Publish exploration A.
        rights_manager.publish_exploration(self.admin, 'A')

        exp_services.index_explorations_given_ids(['A', 'B'])

        # Load the search results with an empty query.
        response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL)
        self.assertEqual(len(response_dict['activity_list']), 2)
        self.assertDictContainsSubset(
            {
                'id': 'B',
                'category': 'Category B',
                'title': 'Title B',
                'language_code': 'en',
                'objective': 'Objective B',
                'status': rights_manager.ACTIVITY_STATUS_PUBLIC,
            }, response_dict['activity_list'][1])
        self.assertDictContainsSubset(
            {
                'id': 'A',
                'category': 'Category A',
                'title': 'Title A',
                'language_code': 'en',
                'objective': 'Objective A',
                'status': rights_manager.ACTIVITY_STATUS_PUBLIC,
            }, response_dict['activity_list'][0])

        # Delete exploration A.
        exp_services.delete_exploration(self.admin_id, 'A')

        # Load the search results with an empty query.
        response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL)
        self.assertEqual(len(response_dict['activity_list']), 1)
        self.assertDictContainsSubset(
            {
                'id': 'B',
                'category': 'Category B',
                'title': 'Title B',
                'language_code': 'en',
                'objective': 'Objective B',
                'status': rights_manager.ACTIVITY_STATUS_PUBLIC,
            }, response_dict['activity_list'][0])
Esempio n. 60
0
    def _run_batch_job_once_and_verify_output(
            self,
            exp_specs,
            default_title='A title',
            default_category='A category',
            default_status=rights_manager.ACTIVITY_STATUS_PUBLIC):
        """Run batch job for creating exploration summaries once and verify its
        output. exp_specs is a list of dicts with exploration specifications.
        Allowed keys are category, status, title. If a key is not specified,
        the default value is used.
        """
        with self.swap(jobs_registry, 'ONE_OFF_JOB_MANAGERS',
                       self.ONE_OFF_JOB_MANAGERS_FOR_TESTS):

            default_spec = {
                'title': default_title,
                'category': default_category,
                'status': default_status
            }

            self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
            self.login(self.ADMIN_EMAIL)
            admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
            self.set_admins([self.ADMIN_USERNAME])
            admin = user_services.UserActionsInfo(admin_id)

            # Create and delete an exploration (to make sure job handles
            # deleted explorations correctly).
            exp_id = '100'
            self.save_new_valid_exploration(exp_id,
                                            admin_id,
                                            title=default_spec['title'],
                                            category=default_spec['category'])
            exploration = exp_services.get_exploration_by_id(exp_id)
            exp_services.delete_exploration(admin_id, exp_id)

            # Get dummy explorations.
            num_exps = len(exp_specs)
            expected_job_output = {}

            for ind in range(num_exps):
                exp_id = str(ind)
                spec = default_spec
                spec.update(exp_specs[ind])
                self.save_new_valid_exploration(exp_id,
                                                admin_id,
                                                title=spec['title'],
                                                category=spec['category'])
                exploration = exp_services.get_exploration_by_id(exp_id)

                # Publish exploration.
                if spec['status'] == rights_manager.ACTIVITY_STATUS_PUBLIC:
                    rights_manager.publish_exploration(admin, exp_id)

                # Do not include user_id here, so all explorations are not
                # editable for now (will be updated depending on user_id
                # in galleries).
                exp_rights_model = exp_models.ExplorationRightsModel.get(
                    exp_id)

                exploration = exp_services.get_exploration_by_id(exp_id)
                exploration_model_last_updated = exploration.last_updated
                exploration_model_created_on = exploration.created_on
                first_published_msec = (exp_rights_model.first_published_msec)

                # Manually create the expected summary specifying title,
                # category, etc.
                expected_job_output[exp_id] = exp_domain.ExplorationSummary(
                    exp_id, spec['title'], spec['category'],
                    exploration.objective, exploration.language_code,
                    exploration.tags, feconf.get_empty_ratings(),
                    feconf.EMPTY_SCALED_AVERAGE_RATING, spec['status'],
                    exp_rights_model.community_owned,
                    exp_rights_model.owner_ids, exp_rights_model.editor_ids,
                    exp_rights_model.translator_ids,
                    exp_rights_model.viewer_ids, [admin_id], {admin_id: 1},
                    exploration.version, exploration_model_created_on,
                    exploration_model_last_updated, first_published_msec)

                # Note: Calling constructor for fields that are not required
                # and have no default value does not work, because
                # unspecified fields will be empty list in
                # expected_job_output but will be unspecified in
                # actual_job_output.
                if exploration.tags:
                    expected_job_output[exp_id].tags = exploration.tags
                if exp_rights_model.owner_ids:
                    expected_job_output[exp_id].owner_ids = (
                        exp_rights_model.owner_ids)
                if exp_rights_model.editor_ids:
                    expected_job_output[exp_id].editor_ids = (
                        exp_rights_model.editor_ids)
                if exp_rights_model.translator_ids:
                    expected_job_output[exp_id].translator_ids = (
                        exp_rights_model.translator_ids)
                if exp_rights_model.viewer_ids:
                    expected_job_output[exp_id].viewer_ids = (
                        exp_rights_model.viewer_ids)
                if exploration.version:
                    expected_job_output[exp_id].version = (exploration.version)

            # Run batch job.
            job_id = (
                exp_jobs_one_off.ExpSummariesCreationOneOffJob.create_new())
            exp_jobs_one_off.ExpSummariesCreationOneOffJob.enqueue(job_id)
            self.process_and_flush_pending_tasks()

            # Get and check job output.
            actual_job_output = exp_services.get_all_exploration_summaries()
            self.assertEqual(actual_job_output.keys(),
                             expected_job_output.keys())

            # Note: 'exploration_model_last_updated' is not expected to be the
            # same, because it is now read from the version model representing
            # the exploration's history snapshot, and not the ExplorationModel.
            simple_props = [
                'id', 'title', 'category', 'objective', 'language_code',
                'tags', 'ratings', 'status', 'community_owned', 'owner_ids',
                'editor_ids', 'translator_ids', 'viewer_ids',
                'contributor_ids', 'contributors_summary', 'version',
                'exploration_model_created_on'
            ]
            for exp_id in actual_job_output:
                for prop in simple_props:
                    self.assertEqual(
                        getattr(actual_job_output[exp_id], prop),
                        getattr(expected_job_output[exp_id], prop))