Beispiel #1
0
 def test_to_dict(self):
     expected_object_dict = {
         'question_id': 'abc',
         'question_content': 'Question 1'
     }
     observed_object = question_domain.QuestionSummary('abc', 'Question 1')
     self.assertEqual(expected_object_dict, observed_object.to_dict())
Beispiel #2
0
def compute_summary_of_question(question):
    """Create a QuestionSummary domain object for a given Question domain
    object and return it.

    Args:
        question: Question. The question object for which the summary
            is to be computed.

    Returns:
        QuestionSummary. The computed summary for the given question.
    """
    question_content = question.question_state_data.content.html
    answer_groups = question.question_state_data.interaction.answer_groups
    misconception_ids = [
        answer_group.to_dict()['tagged_skill_misconception_id']
        for answer_group in answer_groups
        if answer_group.to_dict()['tagged_skill_misconception_id']
    ]
    misconception_ids.extend(question.inapplicable_misconception_ids)
    question_summary = question_domain.QuestionSummary(question.id,
                                                       question_content,
                                                       misconception_ids,
                                                       question.created_on,
                                                       question.last_updated)
    return question_summary
 def test_to_dict(self):
     expected_object_dict = {
         'question_id': 'abc',
         'question_title': 'hello'
     }
     observed_object = question_domain.QuestionSummary('abc', 'hello')
     self.assertEqual(expected_object_dict, observed_object.to_dict())
 def test_to_dict(self):
     expected_object_dict = {
         'question_id': 'col1.abc',
         'question_title': 'hello',
         'skill_names': ['skill1', 'skill2']
     }
     observed_object = question_domain.QuestionSummary(
         'col1.abc', 'hello', ['skill1', 'skill2'])
     self.assertEqual(expected_object_dict, observed_object.to_dict())
 def setUp(self):
     super(QuestionSummaryTest, self).setUp()
     self.fake_date_created = datetime.datetime(2018, 11, 17, 20, 2, 45, 0)
     self.fake_date_updated = datetime.datetime(2018, 11, 17, 20, 3, 14, 0)
     self.observed_object = question_domain.QuestionSummary(
         question_id='question_1',
         question_content='<p>question content</p>',
         question_model_created_on=self.fake_date_created,
         question_model_last_updated=self.fake_date_updated,
     )
Beispiel #6
0
 def setUp(self):
     super(QuestionSummaryTest, self).setUp()
     self.fake_date_created = datetime.datetime(2018, 11, 17, 20, 2, 45, 0)
     self.fake_date_updated = datetime.datetime(2018, 11, 17, 20, 3, 14, 0)
     self.observed_object = question_domain.QuestionSummary(
         question_id='question_1',
         question_content='<p>question content</p>',
         interaction_id='TextInput',
         question_model_created_on=self.fake_date_created,
         question_model_last_updated=self.fake_date_updated,
         misconception_ids=['skill1-1', 'skill2-2'])
 def test_to_dict(self):
     expected_object_dict = {
         'id': 'abc',
         'creator_id': 'creator_id',
         'last_updated': None,
         'created_on': None,
         'question_content': 'Question 1'
     }
     observed_object = question_domain.QuestionSummary(
         'creator_id', 'abc', 'Question 1')
     self.assertEqual(expected_object_dict, observed_object.to_dict())
def get_question_summary_from_model(question_summary_model):
    """Returns a domain object for an Oppia question summary given a
    question summary model.

    Args:
        question_summary_model: QuestionSummaryModel.

    Returns:
        QuestionSummary.
    """
    return question_domain.QuestionSummary(
        question_summary_model.id, question_summary_model.question_content,
        question_summary_model.question_model_created_on,
        question_summary_model.question_model_last_updated)
Beispiel #9
0
def compute_summary_of_question(question):
    """Create a QuestionSummary domain object for a given Question domain
    object and return it.

    Args:
        question: Question. The question object for which the summary
            is to be computed.

    Returns:
        QuestionSummary. The computed summary for the given question.
    """
    question_content = question.question_state_data.content.html
    question_summary = question_domain.QuestionSummary(
        question.id, question_content,
        question.created_on, question.last_updated)
    return question_summary
Beispiel #10
0
def get_question_summary_from_model(question_summary_model):
    """Returns a domain object for an Oppia question summary given a
    question summary model.

    Args:
        question_summary_model: QuestionSummaryModel. The QuestionSummary model
            object to fetch corresponding QuestionSummary domain object.

    Returns:
        QuestionSummary. The domain object corresponding to the given question
        summary model.
    """
    return question_domain.QuestionSummary(
        question_summary_model.id, question_summary_model.question_content,
        question_summary_model.question_model_created_on,
        question_summary_model.question_model_last_updated)
Beispiel #11
0
    def test_manager_get(self):
        """Tests get method of question manager handler."""
        question_id = question_services.add_question(
            self.owner_id, self.question)
        self.question = question_services.get_question_by_id(question_id)
        question_services.add_question_id_to_skill(
            self.question.question_id, self.question.collection_id,
            self.skill_id, self.owner_id)

        self.login(self.NEW_USER_EMAIL)
        payload = {}
        payload['collection_id'] = self.collection_id
        response_json = self.get_json(
            '%s' % feconf.QUESTION_MANAGER_URL, payload,
            expect_errors=False)
        expected_question_summary = question_domain.QuestionSummary(
            self.question.question_id, self.question.title, ['test'])
        self.assertIn(
            expected_question_summary.to_dict(),
            response_json['question_summary_dicts'])

        response = self.testapp.get(
            '%s/batch' % feconf.QUESTION_MANAGER_URL,
            expect_errors=True)
        self.assertEqual(response.status_int, 404)

        del payload['collection_id']
        response = self.testapp.get(
            '%s/batch' % feconf.QUESTION_MANAGER_URL, payload,
            expect_errors=True)
        self.assertEqual(response.status_int, 404)

        self.logout()
        self.login(self.random_email)
        payload['collection_id'] = self.collection_id
        response = self.testapp.get(
            '%s' % feconf.QUESTION_MANAGER_URL, payload,
            expect_errors=True)
        self.assertEqual(response.status_int, 401)
Beispiel #12
0
    def test_to_dict(self):
        """Test to verify to_dict method of the Question Summary
        object.
        """
        fake_date_created = datetime.datetime(2018, 11, 17, 20, 2, 45, 0)
        fake_date_updated = datetime.datetime(2018, 11, 17, 20, 3, 14, 0)
        expected_object_dict = {
            'id': 'question_1',
            'creator_id': 'user_1',
            'question_content': u'question content',
            'last_updated_msec': utils.get_time_in_millisecs(fake_date_updated),
            'created_on_msec': utils.get_time_in_millisecs(fake_date_created),
        }

        observed_object = question_domain.QuestionSummary(
            creator_id='user_1',
            question_id='question_1',
            question_content='question content',
            question_model_created_on=fake_date_created,
            question_model_last_updated=fake_date_updated,
        )

        self.assertEqual(expected_object_dict, observed_object.to_dict())
Beispiel #13
0
def get_question_summaries_for_collection(collection_id):
    """Gets a list of question summaries for a collection.

    Args:
        collection_id: str. ID of the collection.

    Returns:
        list(QuestionSummary). A list of Question Summary objects.
    """
    collection = collection_services.get_collection_by_id(collection_id)
    questions_to_skill_names = collections.defaultdict(list)
    for skill in collection.skills.values():
        for question_id in skill.question_ids:
            questions_to_skill_names[question_id].append(skill.name)
    questions = get_questions_by_ids(questions_to_skill_names.keys())

    question_summaries = []
    for question in questions:
        question_summaries.append(
            question_domain.QuestionSummary(
                question.question_id, question.title,
                (questions_to_skill_names[question.question_id])))
    return question_summaries