def setUp(self): """Create exploration with two versions""" super(VersioningIntegrationTest, self).setUp() self.EXP_ID = '0' exp_services.load_demo(self.EXP_ID) rights_manager.release_ownership_of_exploration( feconf.SYSTEM_COMMITTER_ID, self.EXP_ID) self.login(self.EDITOR_EMAIL) self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) # In version 2, change the objective and the initial state content. exploration = exp_services.get_exploration_by_id(self.EXP_ID) exp_services.update_exploration( self.editor_id, self.EXP_ID, [{ 'cmd': 'edit_exploration_property', 'property_name': 'objective', 'new_value': 'the objective', }, { 'cmd': 'edit_state_property', 'property_name': 'content', 'state_name': exploration.init_state_name, 'new_value': [{'type': 'text', 'value': 'ABC'}], }], 'Change objective and init state content')
def post(self): """Handles POST requests.""" try: if self.payload.get('action') == 'reload_exploration': exploration_id = self.payload.get('explorationId') logging.info( '[ADMIN] %s reloaded exploration %s' % (self.user_id, exploration_id)) exp_services.delete_demo(unicode(exploration_id)) exp_services.load_demo(unicode(exploration_id)) elif self.payload.get('action') == 'save_config_properties': new_config_property_values = self.payload.get( 'new_config_property_values') logging.info('[ADMIN] %s saved config property values: %s' % (self.user_id, new_config_property_values)) for (name, value) in new_config_property_values.iteritems(): config_services.set_property(self.user_id, name, value) elif self.payload.get('action') == 'revert_config_property': config_property_id = self.payload.get('config_property_id') logging.info('[ADMIN] %s reverted config property: %s' % (self.user_id, config_property_id)) config_services.revert_property( self.user_id, config_property_id) elif self.payload.get('action') == 'refresh_computed_property': computed_property_name = self.payload.get( 'computed_property_name') config_domain.Registry.get_config_property( computed_property_name).refresh_default_value() self.render_json({}) except Exception as e: self.render_json({'error': unicode(e)}) raise
def setUp(self): """Before the test, create an exploration_dict.""" super(ClassifyHandlerTest, self).setUp() self.enable_string_classifier = self.swap( feconf, 'ENABLE_STRING_CLASSIFIER', True) # Reading YAML exploration into a dictionary. yaml_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../tests/data/string_classifier_test.yaml') with open(yaml_path, 'r') as yaml_file: self.yaml_content = yaml_file.read() self.login(self.VIEWER_EMAIL) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) # Load demo exploration. self.exp_id = '0' self.title = 'Testing String Classifier' self.category = 'Test' exp_services.delete_demo(self.exp_id) exp_services.load_demo(self.exp_id) # Creating the exploration domain object. self.exploration = exp_domain.Exploration.from_untitled_yaml( self.exp_id, self.title, self.category, self.yaml_content)
def test_give_feedback_handler(self): """Test giving feedback handler.""" self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) # Load demo exploration exp_id = '0' exp_services.delete_demo('0') exp_services.load_demo('0') # Viewer opens exploration self.login(self.VIEWER_EMAIL) exploration_dict = self.get_json( '%s/%s' % (feconf.EXPLORATION_INIT_URL_PREFIX, exp_id)) state_name_1 = exploration_dict['exploration']['init_state_name'] # Viewer gives 1st feedback self.post_json( '/explorehandler/give_feedback/%s' % exp_id, { 'state_name': state_name_1, 'feedback': 'This is a feedback message.', } ) self.logout()
def test_non_splash_page_demo_exploration(self): # Note: there is no difference between permissions for demo # explorations, whether or not they are on the splash page. exp_services.load_demo('3') rights_manager.release_ownership_of_exploration( feconf.SYSTEM_COMMITTER_ID, '3') self.assertTrue( rights_manager.Actor(self.user_id_a).can_play( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_a).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue(rights_manager.Actor( self.user_id_a).can_edit( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertFalse(rights_manager.Actor( self.user_id_a).can_delete( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_play( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue(rights_manager.Actor( self.user_id_admin).can_edit( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete( rights_manager.ACTIVITY_TYPE_EXPLORATION, '3'))
def setUp(self): """Create exploration with two versions""" super(VersioningIntegrationTest, self).setUp() self.EXP_ID = '0' exp_services.delete_demo(self.EXP_ID) exp_services.load_demo(self.EXP_ID) EDITOR_EMAIL = '*****@*****.**' self.register_editor(EDITOR_EMAIL) self.login(EDITOR_EMAIL) # In version 2, change the objective and the initial state content. exploration = exp_services.get_exploration_by_id(self.EXP_ID) exp_services.update_exploration( EDITOR_EMAIL, self.EXP_ID, [{ 'cmd': 'edit_exploration_property', 'property_name': 'objective', 'new_value': 'the objective', }, { 'cmd': 'edit_state_property', 'property_name': 'content', 'state_name': exploration.init_state_name, 'new_value': [{'type': 'text', 'value': 'ABC'}], }], 'Change objective and init state content')
def test_handler_for_recently_published_library_group_page(self): """Test library handler for recently published group page.""" response_dict = self.get_json( feconf.LIBRARY_GROUP_DATA_URL, {'group_name': feconf.LIBRARY_GROUP_RECENTLY_PUBLISHED}) self.assertDictContainsSubset({ 'is_admin': False, 'is_moderator': False, 'is_super_admin': False, 'activity_list': [], 'preferred_language_codes': ['en'], 'profile_picture_data_url': None, }, response_dict) # Load a public demo exploration. exp_services.load_demo('0') response_dict = self.get_json( feconf.LIBRARY_GROUP_DATA_URL, {'group_name': feconf.LIBRARY_GROUP_RECENTLY_PUBLISHED}) self.assertEqual(len(response_dict['activity_list']), 1) self.assertDictContainsSubset({ 'header_i18n_id': 'I18N_LIBRARY_GROUPS_RECENTLY_PUBLISHED', 'preferred_language_codes': ['en'], }, response_dict) self.assertDictContainsSubset({ 'id': '0', 'category': 'Welcome', 'title': 'Welcome to Oppia!', 'language_code': 'en', 'objective': 'become familiar with Oppia\'s capabilities', 'status': rights_manager.ACTIVITY_STATUS_PUBLIC, }, response_dict['activity_list'][0])
def setUp(self): """Create exploration with two versions""" super(VersioningIntegrationTest, self).setUp() self.EXP_ID = "0" exp_services.load_demo(self.EXP_ID) rights_manager.release_ownership_of_exploration(feconf.SYSTEM_COMMITTER_ID, self.EXP_ID) self.login(self.EDITOR_EMAIL) self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) # In version 2, change the objective and the initial state content. exploration = exp_services.get_exploration_by_id(self.EXP_ID) exp_services.update_exploration( self.editor_id, self.EXP_ID, [ {"cmd": "edit_exploration_property", "property_name": "objective", "new_value": "the objective"}, { "cmd": "edit_state_property", "property_name": "content", "state_name": exploration.init_state_name, "new_value": [{"type": "text", "value": "ABC"}], }, ], "Change objective and init state content", )
def test_demo_exploration(self): exp_services.load_demo('1') rights_manager.release_ownership_of_exploration( feconf.SYSTEM_COMMITTER_ID, '1') self.assertTrue( rights_manager.Actor(self.user_id_a).can_play( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_a).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_a).can_edit( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertFalse( rights_manager.Actor(self.user_id_a).can_delete( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_play( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_edit( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete( rights_manager.ACTIVITY_TYPE_EXPLORATION, '1'))
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()
def test_loading_and_validation_and_deletion_of_demo_explorations(self): """Test loading, validation and deletion of the demo explorations.""" self.assertEqual(exp_services.count_explorations(), 0) self.assertGreaterEqual( len(feconf.DEMO_EXPLORATIONS), 1, msg='There must be at least one demo exploration.') for ind in range(len(feconf.DEMO_EXPLORATIONS)): start_time = datetime.datetime.utcnow() exp_id = str(ind) exp_services.load_demo(exp_id) exploration = exp_services.get_exploration_by_id(exp_id) warnings = exploration.validate(strict=True) if warnings: raise Exception(warnings) duration = datetime.datetime.utcnow() - start_time processing_time = duration.seconds + duration.microseconds / 1E6 print 'Loaded and validated exploration %s (%.2f seconds)' % ( exploration.title.encode('utf-8'), processing_time) self.assertEqual( exp_services.count_explorations(), len(feconf.DEMO_EXPLORATIONS)) for ind in range(len(feconf.DEMO_EXPLORATIONS)): exp_services.delete_demo(str(ind)) self.assertEqual(exp_services.count_explorations(), 0)
def test_editor_page(self): """Test access to editor pages for the sample exploration.""" exp_services.delete_demo('0') exp_services.load_demo('0') # Check that non-editors can access, but not edit, the editor page. response = self.testapp.get('/create/0') self.assertEqual(response.status_int, 200) self.assertIn('Welcome to Oppia!', response.body) self.assert_cannot_edit(response.body) # Log in as an editor. self.login(self.EDITOR_EMAIL) # Check that it is now possible to access and edit the editor page. response = self.testapp.get('/create/0') self.assertIn('Welcome to Oppia!', response.body) self.assertEqual(response.status_int, 200) self.assert_can_edit(response.body) self.assertIn('Stats', response.body) self.assertIn('History', response.body) # Test that the value generator JS is included. self.assertIn('RandomSelector', response.body) self.logout()
def setUp(self): """Create exploration with two versions""" super(VersioningIntegrationTest, self).setUp() self.EXP_ID = "0" exp_services.load_demo(self.EXP_ID) self.login(self.EDITOR_EMAIL) # In version 2, change the objective and the initial state content. exploration = exp_services.get_exploration_by_id(self.EXP_ID) exp_services.update_exploration( self.EDITOR_EMAIL, self.EXP_ID, [ {"cmd": "edit_exploration_property", "property_name": "objective", "new_value": "the objective"}, { "cmd": "edit_state_property", "property_name": "content", "state_name": exploration.init_state_name, "new_value": [{"type": "text", "value": "ABC"}], }, ], "Change objective and init state content", )
def setUp(self): """Load a demo exploration and register self.EDITOR_EMAIL.""" super(ImageHandlerTest, self).setUp() exp_services.delete_demo('0') exp_services.load_demo('0') self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
def post(self): """Handles POST requests.""" try: if self.payload.get('action') == 'reload_exploration': exploration_id = self.payload.get('exploration_id') logging.info( '[ADMIN] %s reloaded exploration %s' % (self.user_id, exploration_id)) exp_services.delete_demo(unicode(exploration_id)) exp_services.load_demo(unicode(exploration_id)) elif self.payload.get('action') == 'clear_search_index': exp_services.clear_search_index() elif self.payload.get('action') == 'save_config_properties': new_config_property_values = self.payload.get( 'new_config_property_values') logging.info('[ADMIN] %s saved config property values: %s' % (self.user_id, new_config_property_values)) for (name, value) in new_config_property_values.iteritems(): config_services.set_property(self.user_id, name, value) elif self.payload.get('action') == 'revert_config_property': config_property_id = self.payload.get('config_property_id') logging.info('[ADMIN] %s reverted config property: %s' % (self.user_id, config_property_id)) config_services.revert_property( self.user_id, config_property_id) elif self.payload.get('action') == 'refresh_computed_property': computed_property_name = self.payload.get( 'computed_property_name') config_domain.Registry.get_config_property( computed_property_name).refresh_default_value() elif self.payload.get('action') == 'start_new_job': for klass in jobs_registry.ONE_OFF_JOB_MANAGERS: if klass.__name__ == self.payload.get('job_type'): klass.enqueue(klass.create_new()) break elif self.payload.get('action') == 'cancel_job': job_id = self.payload.get('job_id') job_type = self.payload.get('job_type') for klass in jobs_registry.ONE_OFF_JOB_MANAGERS: if klass.__name__ == job_type: klass.cancel(job_id, self.user_id) break elif self.payload.get('action') == 'start_computation': computation_type = self.payload.get('computation_type') for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS: if klass.__name__ == computation_type: klass.start_computation() break elif self.payload.get('action') == 'stop_computation': computation_type = self.payload.get('computation_type') for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS: if klass.__name__ == computation_type: klass.stop_computation(self.user_id) break self.render_json({}) except Exception as e: self.render_json({'error': unicode(e)}) raise
def test_add_new_state_error_cases(self): """Test the error cases for adding a new state to an exploration.""" exp_services.load_demo("0") CURRENT_VERSION = 1 self.login(self.EDITOR_EMAIL) response = self.testapp.get("/create/0") csrf_token = self.get_csrf_token_from_response(response) def _get_payload(new_state_name, version=None): result = { "change_list": [{"cmd": "add_state", "state_name": new_state_name}], "commit_message": "Add new state", } if version is not None: result["version"] = version return result def _put_and_expect_400_error(payload): return self.put_json( "/createhandler/data/0", payload, csrf_token, expect_errors=True, expected_status_int=400 ) # A request with no version number is invalid. response_dict = _put_and_expect_400_error(_get_payload("New state")) self.assertIn("a version must be specified", response_dict["error"]) # A request with the wrong version number is invalid. response_dict = _put_and_expect_400_error(_get_payload("New state", 123)) self.assertIn("which is too old", response_dict["error"]) # A request with an empty state name is invalid. response_dict = _put_and_expect_400_error(_get_payload("", CURRENT_VERSION)) self.assertIn("should be between 1 and 50", response_dict["error"]) # A request with a really long state name is invalid. response_dict = _put_and_expect_400_error(_get_payload("a" * 100, CURRENT_VERSION)) self.assertIn("should be between 1 and 50", response_dict["error"]) # A request with a state name containing invalid characters is # invalid. response_dict = _put_and_expect_400_error(_get_payload("[Bad State Name]", CURRENT_VERSION)) self.assertIn("Invalid character [", response_dict["error"]) # A name cannot have spaces at the front or back. response_dict = _put_and_expect_400_error(_get_payload(" aa", CURRENT_VERSION)) self.assertIn("start or end with whitespace", response_dict["error"]) response_dict = _put_and_expect_400_error(_get_payload("aa\t", CURRENT_VERSION)) self.assertIn("end with whitespace", response_dict["error"]) response_dict = _put_and_expect_400_error(_get_payload("\n", CURRENT_VERSION)) self.assertIn("end with whitespace", response_dict["error"]) # A name cannot have consecutive whitespace. response_dict = _put_and_expect_400_error(_get_payload("The B", CURRENT_VERSION)) self.assertIn("Adjacent whitespace", response_dict["error"]) response_dict = _put_and_expect_400_error(_get_payload("The\t\tB", CURRENT_VERSION)) self.assertIn("Adjacent whitespace", response_dict["error"]) self.logout()
def test_new_state_template(self): """Test the validity of the NEW_STATE_TEMPLATE.""" exp_services.load_demo("0") exploration = exp_services.get_exploration_by_id("0") exploration.add_states([feconf.DEFAULT_INIT_STATE_NAME]) new_state_dict = exploration.states[feconf.DEFAULT_INIT_STATE_NAME].to_dict() new_state_dict["unresolved_answers"] = {} self.assertEqual(new_state_dict, editor.NEW_STATE_TEMPLATE)
def setUp(self): super(FeedbackThreadIntegrationTests, self).setUp() self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.EDITOR_ID = self.get_user_id_from_email(self.EDITOR_EMAIL) # Load exploration 0. exp_services.delete_demo(self.EXP_ID) exp_services.load_demo(self.EXP_ID)
def setUp(self): """Load a demo exploration and register self.EDITOR_EMAIL.""" super(ImageHandlerTest, self).setUp() exp_services.delete_demo('0') exp_services.load_demo('0') rights_manager.release_ownership_of_exploration( feconf.SYSTEM_COMMITTER_ID, '0') self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
def test_new_state_template(self): """Test the validity of the NEW_STATE_TEMPLATE.""" exp_services.load_demo('0') exploration = exp_services.get_exploration_by_id('0') exploration.add_states([feconf.DEFAULT_INIT_STATE_NAME]) new_state_dict = exploration.export_state_to_frontend_dict( feconf.DEFAULT_INIT_STATE_NAME) new_state_dict['unresolved_answers'] = {} self.assertEqual(new_state_dict, editor.NEW_STATE_TEMPLATE)
def test_resolved_answers_handler(self): exp_services.load_demo("0") # In the reader perspective, submit the first multiple-choice answer, # then submit 'blah' once, 'blah2' twice and 'blah3' three times. # TODO(sll): Use the ExplorationPlayer in reader_test for this. exploration_dict = self.get_json("%s/0" % feconf.EXPLORATION_INIT_URL_PREFIX) self.assertEqual(exploration_dict["exploration"]["title"], "Welcome to Oppia!") state_name = exploration_dict["exploration"]["init_state_name"] result_dict = self.submit_answer("0", state_name, "0") state_name = result_dict["state_name"] self.submit_answer("0", state_name, "blah") for _ in range(2): self.submit_answer("0", state_name, "blah2") for _ in range(3): self.submit_answer("0", state_name, "blah3") # Log in as an editor. self.login(self.EDITOR_EMAIL) response = self.testapp.get("/create/0") csrf_token = self.get_csrf_token_from_response(response) url = str("/createhandler/resolved_answers/0/%s" % state_name) def _get_unresolved_answers(): return stats_domain.StateRuleAnswerLog.get("0", state_name, exp_domain.DEFAULT_RULESPEC_STR).answers self.assertEqual(_get_unresolved_answers(), {"blah": 1, "blah2": 2, "blah3": 3}) # An empty request should result in an error. response_dict = self.put_json( url, {"something_else": []}, csrf_token, expect_errors=True, expected_status_int=400 ) self.assertIn("Expected a list", response_dict["error"]) # A request of the wrong type should result in an error. response_dict = self.put_json( url, {"resolved_answers": "this_is_a_string"}, csrf_token, expect_errors=True, expected_status_int=400 ) self.assertIn("Expected a list", response_dict["error"]) # Trying to remove an answer that wasn't submitted has no effect. response_dict = self.put_json(url, {"resolved_answers": ["not_submitted_answer"]}, csrf_token) self.assertEqual(_get_unresolved_answers(), {"blah": 1, "blah2": 2, "blah3": 3}) # A successful request should remove the answer in question. response_dict = self.put_json(url, {"resolved_answers": ["blah"]}, csrf_token) self.assertEqual(_get_unresolved_answers(), {"blah2": 2, "blah3": 3}) # It is possible to remove more than one answer at a time. response_dict = self.put_json(url, {"resolved_answers": ["blah2", "blah3"]}, csrf_token) self.assertEqual(_get_unresolved_answers(), {}) self.logout()
def _reload_exploration(self, exploration_id): if feconf.DEV_MODE: logging.info( '[ADMIN] %s reloaded exploration %s' % (self.user_id, exploration_id)) exp_services.load_demo(unicode(exploration_id)) rights_manager.release_ownership_of_exploration( feconf.SYSTEM_COMMITTER_ID, unicode(exploration_id)) else: raise Exception('Cannot reload an exploration in production.')
def get(self): """Handles GET requests.""" if not exp_services.get_exploration_by_id('0', strict=False): exp_services.delete_demo('0') exp_services.load_demo('0') self.values.update({ 'gallery_login_url': user_services.create_login_url('/gallery'), }) self.render_template('pages/index.html')
def test_going_somewhere_else_while_signing_in_logs_user_out(self): exp_services.load_demo('0') self.login(self.EDITOR_EMAIL) response = self.testapp.get(feconf.SIGNUP_URL) self.assertEqual(response.status_int, 200) response = self.testapp.get('/create/0') self.assertEqual(response.status_int, 302) self.assertIn('Logout', response.headers['location']) self.assertIn('create', response.headers['location']) self.logout()
def test_library_handler_demo_exploration(self): """Test the library data handler on demo explorations.""" response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL) self.assertEqual({ 'is_super_admin': False, 'activity_list': [], 'search_cursor': None }, response_dict) # Load a public demo exploration. exp_services.load_demo('0') self.process_and_flush_pending_tasks() # 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': '0', 'category': 'Welcome', 'title': 'Welcome to Oppia!', 'language_code': 'en', 'objective': 'become familiar with Oppia\'s capabilities', 'status': rights_domain.ACTIVITY_STATUS_PUBLIC, }, response_dict['activity_list'][0]) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME]) # Change title and category. exp_services.update_exploration( self.editor_id, '0', [exp_domain.ExplorationChange({ 'cmd': 'edit_exploration_property', 'property_name': 'title', 'new_value': 'A new title!' }), exp_domain.ExplorationChange({ 'cmd': 'edit_exploration_property', 'property_name': 'category', 'new_value': 'A new category' })], 'Change title and category') self.process_and_flush_pending_tasks() # 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': '0', 'category': 'A new category', 'title': 'A new title!', 'language_code': 'en', 'objective': 'become familiar with Oppia\'s capabilities', 'status': rights_domain.ACTIVITY_STATUS_PUBLIC, }, response_dict['activity_list'][0])
def test_learn_gallery_handler(self): """Test access to the learners' gallery data handler.""" # Load a demo exploration. This is only in beta so it does not show # up in the learners' gallery. exp_services.load_demo('0') response_dict = self.get_json(feconf.LEARN_GALLERY_DATA_URL) self.assertEqual({ 'is_admin': False, 'is_moderator': False, 'is_super_admin': False, 'categories': {} }, response_dict)
def test_logout_page(self): """Tests for logout handler.""" exp_services.load_demo('0') # Logout with valid query arg. This test only validates that the login # cookies have expired after hitting the logout url. current_page = '/explore/0' response = self.get_html_response(current_page) response = self.get_html_response('/logout', expected_status_int=302) expiry_date = response.headers['Set-Cookie'].rsplit('=', 1) self.assertTrue( datetime.datetime.utcnow() > datetime.datetime.strptime( expiry_date[1], '%a, %d %b %Y %H:%M:%S GMT',))
def test_dependencies_loaded_in_exploration_editor(self): exp_services.load_demo('0') # Register and login as an editor. self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.login(self.EDITOR_EMAIL) # Skulpt is one of the dependencies and should be loaded in # the exploration editor page. response = self.get_html_response('/create/0') response.mustcontain('skulpt') self.logout()
def test_non_splash_page_demo_exploration(self): # Note: there is no difference between permissions for demo # explorations, whether or not they are on the splash page. exp_services.load_demo('3') self.assertTrue(rights_manager.Actor(self.user_id_a).can_view('3')) self.assertTrue(rights_manager.Actor(self.user_id_a).can_edit('3')) self.assertFalse(rights_manager.Actor(self.user_id_a).can_delete('3')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_view('3')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_edit('3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete('3'))
def test_logout_page(self): """Tests for logout handler.""" exp_services.load_demo('0') # Logout with valid query arg. This test only validates that the login # cookies have expired after hitting the logout url. current_page = '/explore/0' response = self.testapp.get(current_page) self.assertEqual(response.status_int, 200) response = self.testapp.get(current_user_services.create_logout_url( current_page)) expiry_date = response.headers['Set-Cookie'].rsplit('=', 1) self.assertTrue(datetime.datetime.now() > datetime.datetime.strptime( expiry_date[1], "%a, %d %b %Y %H:%M:%S GMT",))
def test_demo_exploration(self): exp_services.load_demo('1') self.assertTrue(rights_manager.Actor(self.user_id_a).can_play('1')) self.assertTrue(rights_manager.Actor(self.user_id_a).can_view('1')) self.assertTrue(rights_manager.Actor(self.user_id_a).can_edit('1')) self.assertFalse(rights_manager.Actor(self.user_id_a).can_delete('1')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_play('1')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_view('1')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_edit('1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete('1'))
def test_splash_page_demo_exploration(self): config_services.set_property(feconf.ADMIN_COMMITTER_ID, 'splash_page_exploration_id', '1') exp_services.load_demo('1') self.assertTrue(rights_manager.Actor(self.user_id_a).can_view('1')) self.assertTrue(rights_manager.Actor(self.user_id_a).can_edit('1')) self.assertFalse(rights_manager.Actor(self.user_id_a).can_delete('1')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_view('1')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_edit('1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete('1'))
def test_splash_page_demo_exploration(self): config_services.set_property( feconf.ADMIN_COMMITTER_ID, 'splash_page_exploration_id', '1') exp_services.load_demo('1') self.assertTrue(rights_manager.Actor(self.user_id_a).can_view('1')) self.assertTrue(rights_manager.Actor(self.user_id_a).can_edit('1')) self.assertFalse(rights_manager.Actor(self.user_id_a).can_delete('1')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_view('1')) self.assertTrue(rights_manager.Actor(self.user_id_admin).can_edit('1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete('1'))
def test_state_stats_for_default_exploration(self): exp_services.delete_demo('0') exp_services.load_demo('0') EXPLORATION_STATISTICS_URL = '/createhandler/statistics/0' # Check, from the editor perspective, that no stats have been recorded. self.register_editor('*****@*****.**') self.login('*****@*****.**') editor_exploration_dict = self.get_json(EXPLORATION_STATISTICS_URL) self.assertEqual(editor_exploration_dict['num_starts'], 0) self.assertEqual(editor_exploration_dict['num_completions'], 0) # Switch to the reader perspective. First submit the first # multiple-choice answer, then submit 'blah'. self.logout() exploration_dict = self.get_json( '%s/0' % feconf.EXPLORATION_INIT_URL_PREFIX) self.assertEqual(exploration_dict['title'], 'Welcome to Oppia!') state_name = exploration_dict['state_name'] exploration_dict = self.post_json( '%s/0/%s' % (feconf.EXPLORATION_TRANSITION_URL_PREFIX, state_name), { 'answer': '0', 'handler': 'submit', 'state_history': exploration_dict['state_history'], } ) state_name = exploration_dict['state_name'] self.post_json( '%s/0/%s' % (feconf.EXPLORATION_TRANSITION_URL_PREFIX, state_name), { 'answer': 'blah', 'handler': 'submit', 'state_history': exploration_dict['state_history'] } ) # Ensure that all events get propagated. self.process_and_flush_pending_tasks() # Now switch back to the editor perspective. self.login('*****@*****.**') editor_exploration_dict = self.get_json(EXPLORATION_STATISTICS_URL) self.assertEqual(editor_exploration_dict['num_starts'], 1) self.assertEqual(editor_exploration_dict['num_completions'], 0) # TODO(sll): Add more checks here. self.logout()
def test_learn_gallery_handler(self): """Test access to the learners' gallery data handler.""" # Load a demo exploration. This is only in beta so it does not show # up in the learners' gallery. exp_services.load_demo('0') response_dict = self.get_json(feconf.LEARN_GALLERY_DATA_URL) self.assertEqual( { 'is_admin': False, 'is_moderator': False, 'is_super_admin': False, 'categories': {} }, response_dict)
def test_deferred_tasks_handler_handles_tasks_correctly(self): exp_id = '15' self.login(self.VIEWER_EMAIL) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) exp_services.load_demo(exp_id) exploration = exp_fetchers.get_exploration_by_id(exp_id) exp_version = exploration.version state_name = 'Home' state_stats_mapping = { state_name: stats_domain.StateStats.create_default() } exploration_stats = stats_domain.ExplorationStats( exp_id, exp_version, 0, 0, 0, 0, 0, 0, state_stats_mapping) stats_services.create_stats_model(exploration_stats) aggregated_stats = { 'num_starts': 1, 'num_actual_starts': 1, 'num_completions': 1, 'state_stats_mapping': { 'Home': { 'total_hit_count': 1, 'first_hit_count': 1, 'total_answers_count': 1, 'useful_feedback_count': 1, 'num_times_solution_viewed': 1, 'num_completions': 1 } } } self.post_json('/explorehandler/stats_events/%s' % (exp_id), { 'aggregated_stats': aggregated_stats, 'exp_version': exp_version }) self.assertEqual( self.count_jobs_in_taskqueue(taskqueue_services.QUEUE_NAME_STATS), 1) self.process_and_flush_pending_tasks() # Check that the models are updated. exploration_stats = stats_services.get_exploration_stats_by_id( exp_id, exp_version) self.assertEqual(exploration_stats.num_starts_v2, 1) self.assertEqual(exploration_stats.num_actual_starts_v2, 1) self.assertEqual(exploration_stats.num_completions_v2, 1) self.assertEqual( exploration_stats.state_stats_mapping[state_name]. total_hit_count_v2, 1)
def test_library_index_handler_updates_featured_activity_summary_dict( self): """Test the handler for featured explorations.""" response_dict = self.get_json(feconf.LIBRARY_INDEX_DATA_URL) self.assertDictContainsSubset( { 'activity_summary_dicts_by_category': [], 'preferred_language_codes': ['en'], }, response_dict) # Load a demo. exp_services.load_demo('0') exploration_ref = activity_domain.ActivityReference( constants.ACTIVITY_TYPE_EXPLORATION, '0') activity_services.update_featured_activity_references( [exploration_ref]) response_dict = self.get_json(feconf.LIBRARY_INDEX_DATA_URL) self.assertEqual( len(response_dict['activity_summary_dicts_by_category']), 1) self.assertDictContainsSubset({ 'preferred_language_codes': ['en'], }, response_dict) activity_summary_dicts_by_category = ( response_dict['activity_summary_dicts_by_category'][0]) self.assertDictContainsSubset( { 'categories': [], 'header_i18n_id': (feconf.LIBRARY_CATEGORY_FEATURED_ACTIVITIES), 'has_full_results_page': False, 'full_results_url': None, }, activity_summary_dicts_by_category) activity_summary_dicts = ( activity_summary_dicts_by_category['activity_summary_dicts']) self.assertEqual(len(activity_summary_dicts), 1) self.assertDictContainsSubset( { 'id': '0', 'category': 'Welcome', 'title': 'Welcome to Oppia!', 'language_code': 'en', 'objective': 'become familiar with Oppia\'s capabilities', 'status': rights_domain.ACTIVITY_STATUS_PUBLIC, }, activity_summary_dicts[0])
def test_dependency_does_not_load_in_exploration_not_containing_it(self): exp_id = '0' exp_services.load_demo(exp_id) # Verify that exploration 0 does not have a Skulpt dependency. exploration = exp_services.get_exploration_by_id(exp_id) interaction_ids = exploration.get_interaction_ids() all_dependency_ids = (interaction_registry.Registry. get_deduplicated_dependency_ids(interaction_ids)) self.assertNotIn('skulpt', all_dependency_ids) # Thus, Skulpt is not loaded in the exploration reader. response = self.get_html_response('/explore/%s' % exp_id) response.mustcontain(no=['skulpt'])
def test_logout_page(self): """Tests for logout handler.""" exp_services.load_demo('0') # Logout with valid query arg. This test only validates that the login # cookies have expired after hitting the logout url. current_page = '/explore/0' response = self.testapp.get(current_page) self.assertEqual(response.status_int, 200) response = self.testapp.get( current_user_services.create_logout_url(current_page)) expiry_date = response.headers['Set-Cookie'].rsplit('=', 1) self.assertTrue(datetime.datetime.now() > datetime.datetime.strptime( expiry_date[1], "%a, %d %b %Y %H:%M:%S GMT", ))
def test_dependency_loads_in_exploration_containing_it(self): exp_id = '1' exp_services.load_demo(exp_id) # Verify that exploration 1 has a Skulpt dependency. exploration = exp_fetchers.get_exploration_by_id(exp_id) interaction_ids = exploration.get_interaction_ids() all_dependency_ids = (interaction_registry.Registry. get_deduplicated_dependency_ids(interaction_ids)) self.assertIn('skulpt', all_dependency_ids) # Thus, Skulpt is loaded in the exploration reader. response = self.get_html_response('/explore/%s' % exp_id) response.mustcontain('skulpt')
def setUp(self): super(LearnerDashboardFeedbackThreadHandlerTests, self).setUp() self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) # Load exploration 0. exp_services.load_demo(self.EXP_ID_1) self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) # Get the CSRF token and create a single thread with a single message. self.login(self.EDITOR_EMAIL) self.csrf_token = self.get_new_csrf_token() self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID_1), { 'subject': self._get_unicode_test_string('subject'), 'text': 'a sample message', }, csrf_token=self.csrf_token) self.logout()
def test_interactions_demo_exploration(self): exp_services.load_demo(self._DEMO_EXPLORATION_ID) exploration = exp_fetchers.get_exploration_by_id( self._DEMO_EXPLORATION_ID) all_interaction_ids = set( interaction_registry.Registry.get_all_interaction_ids()) observed_interaction_ids = set() for state in exploration.states.values(): observed_interaction_ids.add(state.interaction.id) missing_interaction_ids = ( all_interaction_ids - observed_interaction_ids) self.assertEqual(len(missing_interaction_ids), 0, msg=( 'Missing interaction IDs in demo exploration: %s' % missing_interaction_ids))
def setUp(self): super(AssetDevHandlerAudioTest, self).setUp() exp_services.delete_demo('0') self.system_user = user_services.get_system_user() exp_services.load_demo('0') rights_manager.release_ownership_of_exploration(self.system_user, '0') self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) mock_accepted_audio_extensions = { 'mp3': ['audio/mp3'], 'flac': ['audio/flac'] } self.accepted_audio_extensions_swap = self.swap( feconf, 'ACCEPTED_AUDIO_EXTENSIONS', mock_accepted_audio_extensions)
def test_dependency_does_not_load_in_exploration_not_containing_it(self): EXP_ID = '0' exp_services.load_demo(EXP_ID) # Verify that exploration 0 does not have a Skulpt dependency. exploration = exp_services.get_exploration_by_id(EXP_ID) interaction_ids = exploration.get_interaction_ids() all_dependency_ids = ( interaction_registry.Registry.get_deduplicated_dependency_ids( interaction_ids)) self.assertNotIn('skulpt', all_dependency_ids) # Thus, Skulpt is not loaded in the exploration reader. response = self.testapp.get('/explore/%s' % EXP_ID) self.assertEqual(response.status_int, 200) response.mustcontain(no=['skulpt'])
def test_dependency_loads_in_exploration_containing_it(self): EXP_ID = '1' exp_services.load_demo(EXP_ID) # Verify that exploration 1 has a jsrepl dependency. exploration = exp_services.get_exploration_by_id(EXP_ID) interaction_ids = exploration.get_interaction_ids() all_dependency_ids = ( interaction_registry.Registry.get_deduplicated_dependency_ids( interaction_ids)) self.assertIn('jsrepl', all_dependency_ids) # Thus, jsrepl is loaded in the exploration reader. response = self.testapp.get('/explore/%s' % EXP_ID) self.assertEqual(response.status_int, 200) response.mustcontain('jsrepl')
def _get_splash_page(self): if SPLASH_PAGE_EXPLORATION_ID.value: splash_exp_id = SPLASH_PAGE_EXPLORATION_ID.value if not exp_services.get_exploration_by_id( splash_exp_id, strict=False): exp_services.delete_demo(splash_exp_id) exp_services.load_demo(splash_exp_id) self.values.update({ 'BANNER_ALT_TEXT': BANNER_ALT_TEXT.value, 'SITE_FORUM_URL': pages.SITE_FORUM_URL.value, 'SITE_NAME': pages.SITE_NAME.value, 'SPLASH_PAGE_EXPLORATION_ID': SPLASH_PAGE_EXPLORATION_ID.value, 'SPLASH_PAGE_EXPLORATION_VERSION': ( SPLASH_PAGE_EXPLORATION_VERSION.value), }) self.render_template('pages/splash.html')
def test_non_splash_page_demo_exploration(self): # Note: there is no difference between permissions for demo # explorations, whether or not they are on the splash page. exp_services.load_demo('3') rights_manager.release_ownership_of_exploration( feconf.SYSTEM_COMMITTER_ID, '3') self.assertTrue( rights_manager.Actor(self.user_id_a).can_play( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_a).can_view( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_a).can_edit( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertFalse( rights_manager.Actor(self.user_id_a).can_delete( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_play( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_view( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_edit( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_play( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_view( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_edit( feconf.ACTIVITY_TYPE_EXPLORATION, '3')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_delete( feconf.ACTIVITY_TYPE_EXPLORATION, '3'))
def setUp(self): super(LearnerDashboardFeedbackThreadHandlerTest, self).setUp() self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) # Load exploration 0. exp_services.load_demo(self.EXP_ID_1) # Get the CSRF token and create a single thread with a single message. self.login(self.EDITOR_EMAIL) response = self.testapp.get('/create/%s' % self.EXP_ID_1) self.csrf_token = self.get_csrf_token_from_response(response) self.post_json( '%s/%s' % (feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID_1), { 'state_name': self._get_unicode_test_string('statename'), 'subject': self._get_unicode_test_string('subject'), 'text': 'a sample message', }, self.csrf_token) self.logout()
def _reload_exploration(self, exploration_id): """Reloads the exploration in dev_mode corresponding to the given exploration id. Args: exploration_id: str. The exploration id. Raises: Exception: Cannot reload an exploration in production. """ if constants.DEV_MODE: logging.info('[ADMIN] %s reloaded exploration %s' % (self.user_id, exploration_id)) exp_services.load_demo(unicode(exploration_id)) rights_manager.release_ownership_of_exploration( user_services.get_system_user(), unicode(exploration_id)) else: raise Exception('Cannot reload an exploration in production.')
def test_library_index_handler_update_top_rated_activity_summary_dict( self): """Test the handler for top rated explorations.""" response_dict = self.get_json(feconf.LIBRARY_INDEX_DATA_URL) self.assertDictContainsSubset( { 'activity_summary_dicts_by_category': [], 'preferred_language_codes': ['en'], }, response_dict) # Load a demo. exp_services.load_demo('0') rating_services.assign_rating_to_exploration('user', '0', 2) response_dict = self.get_json(feconf.LIBRARY_INDEX_DATA_URL) self.assertEqual( len(response_dict['activity_summary_dicts_by_category']), 1) self.assertDictContainsSubset({ 'preferred_language_codes': ['en'], }, response_dict) activity_summary_dicts_by_category = ( response_dict['activity_summary_dicts_by_category'][0]) self.assertDictContainsSubset( { 'categories': [], 'header_i18n_id': (feconf.LIBRARY_CATEGORY_TOP_RATED_EXPLORATIONS), 'has_full_results_page': True, 'full_results_url': feconf.LIBRARY_TOP_RATED_URL, 'protractor_id': 'top-rated', }, activity_summary_dicts_by_category) activity_summary_dicts = ( activity_summary_dicts_by_category['activity_summary_dicts']) self.assertEqual(len(activity_summary_dicts), 1) self.assertDictContainsSubset( { 'id': '0', 'category': 'Welcome', 'title': 'Welcome to Oppia!', 'language_code': 'en', 'objective': 'become familiar with Oppia\'s capabilities', 'status': rights_domain.ACTIVITY_STATUS_PUBLIC, }, activity_summary_dicts[0])
def test_demo_exploration(self): exp_services.load_demo('1') rights_manager.release_ownership_of_exploration( feconf.SYSTEM_COMMITTER_ID, '1') self.assertTrue( rights_manager.Actor(self.user_id_a).can_play( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_a).can_view( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_a).can_edit( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertFalse( rights_manager.Actor(self.user_id_a).can_delete( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_play( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_view( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_edit( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_admin).can_delete( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_play( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_view( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_edit( feconf.ACTIVITY_TYPE_EXPLORATION, '1')) self.assertTrue( rights_manager.Actor(self.user_id_moderator).can_delete( feconf.ACTIVITY_TYPE_EXPLORATION, '1'))
def setUp(self): super(FeedbackThreadPermissionsTests, self).setUp() self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) # Load exploration 0. exp_services.delete_demo(self.EXP_ID) exp_services.load_demo(self.EXP_ID) # Get the CSRF token and create a single thread with a single message. # The corresponding user has already registered as an editor, and has a # username. self.login(self.EDITOR_EMAIL) self.csrf_token = self.get_new_csrf_token() self.post_json('%s/%s' % ( feconf.FEEDBACK_THREADLIST_URL_PREFIX, self.EXP_ID ), { 'subject': self._get_unicode_test_string('subject'), 'text': self._get_unicode_test_string('text'), }, csrf_token=self.csrf_token) self.logout()
def test_versioning_for_default_exploration(self): EXP_ID = '0' exp_services.delete_demo(EXP_ID) exp_services.load_demo(EXP_ID) # In version 2, change the initial state content. exploration = exp_services.get_exploration_by_id(EXP_ID) exp_services.update_exploration( '*****@*****.**', EXP_ID, [{ 'cmd': 'edit_state_property', 'property_name': 'content', 'state_name': exploration.init_state_name, 'new_value': [{ 'type': 'text', 'value': 'ABC' }], }], 'Change init state content') # The latest version contains 'ABC'. reader_dict = self.get_json( '%s/%s' % (feconf.EXPLORATION_INIT_URL_PREFIX, EXP_ID)) self.assertIn('ABC', reader_dict['init_html']) self.assertNotIn('Hi, welcome to Oppia!', reader_dict['init_html']) # v1 contains 'Hi, welcome to Oppia!'. reader_dict = self.get_json( '%s/%s?v=1' % (feconf.EXPLORATION_INIT_URL_PREFIX, EXP_ID)) self.assertIn('Hi, welcome to Oppia!', reader_dict['init_html']) self.assertNotIn('ABC', reader_dict['init_html']) # v2 contains 'ABC'. reader_dict = self.get_json( '%s/%s?v=2' % (feconf.EXPLORATION_INIT_URL_PREFIX, EXP_ID)) self.assertIn('ABC', reader_dict['init_html']) self.assertNotIn('Hi, welcome to Oppia!', reader_dict['init_html']) # v3 does not exist. response = self.testapp.get( '%s/%s?v=3' % (feconf.EXPLORATION_INIT_URL_PREFIX, EXP_ID), expect_errors=True) self.assertEqual(response.status_int, 404)
def test_non_splash_page_demo_exploration(self): # Note: there is no difference between permissions for demo # explorations, whether or not they are on the splash page. exp_services.load_demo('3') rights_manager.release_ownership_of_exploration(self.system_user, '3') exp_rights = rights_manager.get_exploration_rights('3') self.assertTrue( rights_manager.check_can_access_activity(self.user_a, exp_rights)) self.assertTrue( rights_manager.check_can_edit_activity(self.user_a, exp_rights)) self.assertTrue( rights_manager.check_can_translate_activity( self.user_a, exp_rights)) self.assertFalse( rights_manager.check_can_delete_activity(self.user_a, exp_rights)) self.assertTrue( rights_manager.check_can_access_activity(self.user_admin, exp_rights)) self.assertTrue( rights_manager.check_can_edit_activity(self.user_admin, exp_rights)) self.assertTrue( rights_manager.check_can_translate_activity( self.user_admin, exp_rights)) self.assertTrue( rights_manager.check_can_delete_activity(self.user_admin, exp_rights)) self.assertTrue( rights_manager.check_can_access_activity(self.user_moderator, exp_rights)) self.assertTrue( rights_manager.check_can_edit_activity(self.user_moderator, exp_rights)) self.assertTrue( rights_manager.check_can_translate_activity( self.user_moderator, exp_rights)) self.assertTrue( rights_manager.check_can_delete_activity(self.user_moderator, exp_rights))
def test_creation_of_state_classifier_mapping(self): super(ExplorationStateClassifierMappingTests, self).setUp() exploration_id = '15' self.login(self.VIEWER_EMAIL) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) exp_services.delete_demo(exploration_id) # We enable ENABLE_ML_CLASSIFIERS so that the subsequent call to # save_exploration handles job creation for trainable states. # Since only one demo exploration has a trainable state, we modify our # values for MIN_ASSIGNED_LABELS and MIN_TOTAL_TRAINING_EXAMPLES to let # the classifier_demo_exploration.yaml be trainable. This is # completely for testing purposes. with self.swap(feconf, 'ENABLE_ML_CLASSIFIERS', True): with self.swap(feconf, 'MIN_TOTAL_TRAINING_EXAMPLES', 5): with self.swap(feconf, 'MIN_ASSIGNED_LABELS', 1): exp_services.load_demo(exploration_id) # Retrieve job_id of created job (because of save_exp). all_jobs = classifier_models.ClassifierTrainingJobModel.get_all() self.assertEqual(all_jobs.count(), 1) for job in all_jobs: job_id = job.id classifier_services.store_classifier_data(job_id, {}) expected_state_classifier_mapping = { 'text': { 'algorithm_id': 'LDAStringClassifier', 'classifier_data': {}, 'data_schema_version': 1 } } # Call the handler. exploration_dict = self.get_json( '%s/%s' % (feconf.EXPLORATION_INIT_URL_PREFIX, exploration_id)) retrieved_state_classifier_mapping = exploration_dict[ 'state_classifier_mapping'] self.assertEqual(expected_state_classifier_mapping, retrieved_state_classifier_mapping)
def init_player(self, exploration_id, expected_title, expected_response): """Starts a reader session and gets the first state from the server. `expected_response` will be interpreted as a regex string. """ exp_services.delete_demo(exploration_id) exp_services.load_demo(exploration_id) self.exp_id = exploration_id # pylint: disable=attribute-defined-outside-init reader_dict = self.get_json( '%s/%s' % (feconf.EXPLORATION_INIT_URL_PREFIX, self.exp_id)) self.last_state_name = reader_dict['exploration']['init_state_name'] # pylint: disable=attribute-defined-outside-init init_state_data = ( reader_dict['exploration']['states'][self.last_state_name]) init_content = init_state_data['content'][0]['value'] self.assertRegexpMatches(init_content, expected_response) self.assertEqual(reader_dict['exploration']['title'], expected_title)
def init_player(self, exploration_id, expected_title, expected_response): """Starts a reader session and gets the first state from the server. `expected_response` will be interpreted as a regex string. """ exp_services.delete_demo(exploration_id) exp_services.load_demo(exploration_id) self.EXP_ID = exploration_id reader_dict = self.get_json( '%s/%s' % (feconf.EXPLORATION_INIT_URL_PREFIX, self.EXP_ID)) self.last_params = reader_dict['params'] self.last_state_name = reader_dict['state_name'] self.state_history = [self.last_state_name] self.assertEqual(reader_dict['state_history'], self.state_history) self.assertRegexpMatches(reader_dict['init_html'], expected_response) self.assertEqual(reader_dict['title'], expected_title)