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_fetchers.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)
        csrf_token = self.get_new_csrf_token()

        # 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 post(self):
        """Handles POST requests."""
        title = self.payload.get('title', feconf.DEFAULT_EXPLORATION_TITLE)

        new_exploration_id = exp_fetchers.get_new_exploration_id()
        exploration = exp_domain.Exploration.create_default_exploration(
            new_exploration_id, title=title)
        exp_services.save_new_exploration(self.user_id, exploration)

        self.render_json({EXPLORATION_ID_KEY: new_exploration_id})
Exemple #3
0
    def test_can_search_exploration_with_exploration_id(self):
        self.set_collection_editors([self.OWNER_USERNAME])
        self.login(self.OWNER_EMAIL)
        exploration_id = exp_fetchers.get_new_exploration_id()
        self.save_new_valid_exploration(exploration_id, self.owner_id)
        rights_manager.publish_exploration(self.owner, exploration_id)
        exploration_id = base64.b64encode(exploration_id)

        self.get_json('/exploration/metadata_search?q=%s' % exploration_id)
        self.logout()
Exemple #4
0
    def test_can_search_exploration_with_exploration_id(self):
        self.set_collection_editors([self.OWNER_USERNAME])
        self.login(self.OWNER_EMAIL)
        exploration_id = exp_fetchers.get_new_exploration_id()
        self.save_new_valid_exploration(exploration_id, self.owner_id)
        rights_manager.publish_exploration(self.owner, exploration_id)
        # The b64encode accepts and returns bytes, so we first need to encode
        # the exploration_id to bytes, then decode the returned bytes back
        # to string.
        exploration_id = (base64.b64encode(
            exploration_id.encode('utf-8')).decode('utf-8'))

        self.get_json('/exploration/metadata_search?q=%s' % exploration_id)
        self.logout()
    def post(self):
        """Handles POST requests."""
        yaml_content = self.request.get('yaml_file')

        new_exploration_id = exp_fetchers.get_new_exploration_id()
        if constants.ALLOW_YAML_FILE_UPLOAD:
            exp_services.save_new_exploration_from_yaml_and_assets(
                self.user_id,
                yaml_content,
                new_exploration_id, [],
                strip_voiceovers=True)
            self.render_json({EXPLORATION_ID_KEY: new_exploration_id})
        else:
            raise self.InvalidInputException(
                'This server does not allow file uploads.')
    def setUp(self):
        super(MachineTranslationStateTextsHandlerTests, self).setUp()
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)

        self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL)
        self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)

        self.set_admins([self.ADMIN_USERNAME])

        self.exp_id = exp_fetchers.get_new_exploration_id()
        exp = self.save_new_valid_exploration(self.exp_id,
                                              self.owner_id,
                                              title='title',
                                              category='category',
                                              end_state_name='End State')

        self.publish_exploration(self.owner_id, exp.id)
Exemple #7
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.')
Exemple #8
0
    def test_library_handler_with_given_category_and_language_code(self):
        self.login(self.ADMIN_EMAIL)

        exp_id = exp_fetchers.get_new_exploration_id()
        self.save_new_valid_exploration(exp_id, self.admin_id)
        self.publish_exploration(self.admin_id, exp_id)
        exp_services.index_explorations_given_ids([exp_id])
        response_dict = self.get_json(
            feconf.LIBRARY_SEARCH_DATA_URL, params={
                'category': 'A category',
                'language_code': 'en'
            })
        activity_list = (
            summary_services.get_displayable_exp_summary_dicts_matching_ids(
                [exp_id]))

        self.assertEqual(response_dict['activity_list'], activity_list)

        self.logout()
Exemple #9
0
 def test_get_new_exploration_id(self):
     self.assertIsNotNone(
         exp_fetchers.get_new_exploration_id()
     )