def test_get(self): 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.login(self.ADMIN_EMAIL, is_super_admin=True) topic_id_1 = topic_services.get_new_topic_id() topic_id_2 = topic_services.get_new_topic_id() private_topic = topic_domain.Topic.create_default_topic( topic_id_1, 'private_topic_name', 'private-topic-name', 'description') topic_services.save_new_topic(admin_id, private_topic) public_topic = topic_domain.Topic.create_default_topic( topic_id_2, 'public_topic_name', 'public-topic-name', 'description') public_topic.thumbnail_filename = 'Topic.svg' public_topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) topic_services.save_new_topic(admin_id, public_topic) topic_services.publish_topic(topic_id_2, admin_id) csrf_token = self.get_new_csrf_token() new_config_value = [{ 'name': 'math', 'topic_ids': [topic_id_1, topic_id_2], 'course_details': 'Course details for classroom.', 'topic_list_intro': 'Topics covered for classroom', 'url_fragment': 'math', }] payload = { 'action': 'save_config_properties', 'new_config_property_values': { config_domain.CLASSROOM_PAGES_DATA.name: (new_config_value), } } self.post_json('/adminhandler', payload, csrf_token=csrf_token) self.logout() json_response = self.get_json('%s/%s' % (feconf.CLASSROOM_DATA_HANDLER, 'math')) topic_summary_dict = ( topic_services.get_topic_summary_by_id(topic_id_2).to_dict()) expected_dict = { 'name': 'math', 'topic_summary_dicts': [topic_summary_dict], 'course_details': 'Course details for classroom.', 'topic_list_intro': 'Topics covered for classroom' } self.assertDictContainsSubset(expected_dict, json_response)
def test_update_topic(self): topic_services.assign_role(self.user_admin, self.user_a, topic_domain.ROLE_MANAGER, self.TOPIC_ID) # Test whether an admin can edit a topic. changelist = [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_UPDATE_TOPIC_PROPERTY, 'property_name': topic_domain.TOPIC_PROPERTY_DESCRIPTION, 'old_value': 'Description', 'new_value': 'New Description' }) ] topic_services.update_topic(self.user_id_admin, self.TOPIC_ID, changelist, 'Updated Description.') topic = topic_services.get_topic_by_id(self.TOPIC_ID) topic_summary = topic_services.get_topic_summary_by_id(self.TOPIC_ID) self.assertEqual(topic.description, 'New Description') self.assertEqual(topic.version, 2) self.assertEqual(topic_summary.version, 2) # Test whether a topic_manager can edit a topic. changelist = [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_UPDATE_TOPIC_PROPERTY, 'property_name': topic_domain.TOPIC_PROPERTY_NAME, 'old_value': 'Name', 'new_value': 'New Name' }) ] topic_services.update_topic(self.user_id_a, self.TOPIC_ID, changelist, 'Updated Name.') topic = topic_services.get_topic_by_id(self.TOPIC_ID) topic_summary = topic_services.get_topic_summary_by_id(self.TOPIC_ID) self.assertEqual(topic.name, 'New Name') self.assertEqual(topic.version, 3) self.assertEqual(topic_summary.name, 'New Name') self.assertEqual(topic_summary.version, 3)
def test_get(self): 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.login(self.ADMIN_EMAIL, is_super_admin=True) topic_id_1 = topic_services.get_new_topic_id() topic_id_2 = topic_services.get_new_topic_id() private_topic = topic_domain.Topic.create_default_topic( topic_id_1, 'private_topic_name', 'abbrev', 'description') topic_services.save_new_topic(admin_id, private_topic) public_topic = topic_domain.Topic.create_default_topic( topic_id_2, 'public_topic_name', 'abbrev', 'description') public_topic.thumbnail_filename = 'Topic.svg' public_topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) topic_services.save_new_topic(admin_id, public_topic) topic_services.publish_topic(topic_id_2, admin_id) csrf_token = self.get_new_csrf_token() new_config_value = [{ 'name': 'math', 'topic_ids': [topic_id_1, topic_id_2] }] payload = { 'action': 'save_config_properties', 'new_config_property_values': { config_domain.TOPIC_IDS_FOR_CLASSROOM_PAGES.name: ( new_config_value), } } self.post_json('/adminhandler', payload, csrf_token=csrf_token) self.logout() with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): json_response = self.get_json( '%s/%s' % (feconf.CLASSROOM_DATA_HANDLER, 'math')) topic_summary_dict = ( topic_services.get_topic_summary_by_id(topic_id_2).to_dict()) expected_dict = { 'topic_summary_dicts': [topic_summary_dict] } self.assertDictContainsSubset(expected_dict, json_response)