def test_cannot_get_with_unpublished_topic(self): topic_services.unpublish_topic(self.topic_id, self.admin_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): self.get_json( '%s/%s/%s' % ( feconf.SUBTOPIC_DATA_HANDLER, 'Name', 1), expected_status_int=404)
def test_cannot_unpublish_an_unpublished_topic(self): topic_rights = topic_services.get_topic_rights(self.TOPIC_ID) self.assertFalse(topic_rights.topic_is_published) with self.assertRaisesRegexp( Exception, 'The topic is already unpublished.'): topic_services.unpublish_topic(self.TOPIC_ID, self.user_id_admin)
def test_unpublish_topic_rejects_translation_suggestions(self): self.add_exploration_0_to_story() self.create_translation_suggestion_for_exploration_0_and_verify() topic_services.unpublish_topic(self.TOPIC_ID, self.admin_id) suggestion = suggestion_services.get_suggestion_by_id(self.THREAD_ID) self.assertEqual(suggestion.status, suggestion_models.STATUS_REJECTED)
def test_accessibility_of_story_viewer_in_unpublished_topic(self): topic_services.unpublish_topic(self.TOPIC_ID, self.admin_id) self.get_html_response( '/learn/staging/topic/story/%s' % self.STORY_URL_FRAGMENT, expected_status_int=404) self.login(self.ADMIN_EMAIL) self.get_html_response( '/learn/staging/topic/story/%s' % self.STORY_URL_FRAGMENT) self.logout()
def test_accessibility_of_story_viewer_in_unpublished_topic(self): topic_services.unpublish_topic(self.TOPIC_ID, self.admin_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): self.get_html_response('/learn/staging/topic/story/%s' % self.STORY_URL_FRAGMENT, expected_status_int=404) self.login(self.ADMIN_EMAIL) self.get_html_response('/learn/staging/topic/story/%s' % self.STORY_URL_FRAGMENT) self.logout()
def test_accessibility_of_story_viewer_in_unpublished_topic(self): topic_services.unpublish_topic(self.TOPIC_ID, self.admin_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): self.get_html_response( '%s/%s' % (feconf.STORY_VIEWER_URL_PREFIX, self.STORY_ID), expected_status_int=404) self.login(self.ADMIN_EMAIL) self.get_html_response( '%s/%s' % (feconf.STORY_VIEWER_URL_PREFIX, self.STORY_ID)) self.logout()
def test_unpublish_topic_deletes_exploration_opportunity(self): self.add_exploration_0_to_story() translation_opportunities, _, _ = ( opportunity_services.get_translation_opportunities('hi', None)) self.assertEqual(len(translation_opportunities), 1) topic_services.unpublish_topic(self.TOPIC_ID, self.admin_id) translation_opportunities, _, _ = ( opportunity_services.get_translation_opportunities('hi', None)) self.assertEqual(len(translation_opportunities), 0)
def test_initialize_twice_raises_unpublished_topic_exception(self): self.post_json('/initialize_android_test_data', {}, use_payload=False, csrf_token=None) topic = topic_fetchers.get_topic_by_name('Android test') topic_services.unpublish_topic(topic.id, feconf.SYSTEM_COMMITTER_ID) response = self.post_json('/initialize_android_test_data', {}, use_payload=False, csrf_token=None, expected_status_int=400) self.assertEqual(response['error'], 'The topic exists but is not published.')
def test_publish_topic_creates_exploration_opportunity(self): self.add_exploration_0_to_story() # Topic is already published, so unpublish first. topic_services.unpublish_topic(self.TOPIC_ID, self.admin_id) translation_opportunities, _, _ = ( opportunity_services.get_translation_opportunities('hi', None)) self.assertEqual(len(translation_opportunities), 0) topic_services.publish_topic(self.TOPIC_ID, self.admin_id) translation_opportunities, _, _ = ( opportunity_services.get_translation_opportunities('hi', None)) self.assertEqual(len(translation_opportunities), 1)
def test_publish_topic_does_not_create_exploration_opportunity_if_story_is_not_published( # pylint: disable=line-too-long self): self.add_exploration_0_to_story() # Story and topic are already published, so unpublish first. topic_services.unpublish_story(self.TOPIC_ID, self.STORY_ID, self.admin_id) topic_services.unpublish_topic(self.TOPIC_ID, self.admin_id) translation_opportunities, _, _ = ( opportunity_services.get_translation_opportunities('hi', None)) self.assertEqual(len(translation_opportunities), 0) topic_services.publish_topic(self.TOPIC_ID, self.admin_id) translation_opportunities, _, _ = ( opportunity_services.get_translation_opportunities('hi', None)) self.assertEqual(len(translation_opportunities), 0)
def put(self, topic_id): """Publishes or unpublishes a topic.""" topic = topic_fetchers.get_topic_by_id(topic_id, strict=False) if topic is None: raise self.PageNotFoundException publish_status = self.normalized_payload.get('publish_status') try: if publish_status: topic_services.publish_topic(topic_id, self.user_id) else: topic_services.unpublish_topic(topic_id, self.user_id) except Exception as e: raise self.UnauthorizedUserException(e) self.render_json(self.values)
def put(self, topic_id): """Publishes or unpublishes a topic.""" topic_domain.Topic.require_valid_topic_id(topic_id) publish_status = self.payload.get('publish_status') if not isinstance(publish_status, bool): raise self.InvalidInputException( 'Publish status should only be true or false.') try: if publish_status: topic_services.publish_topic(topic_id, self.user_id) else: topic_services.unpublish_topic(topic_id, self.user_id) except Exception as e: raise self.UnauthorizedUserException(e) self.render_json(self.values)
def put(self, topic_id): """Publishes or unpublishes a topic.""" topic = topic_fetchers.get_topic_by_id(topic_id, strict=False) if topic is None: raise self.PageNotFoundException publish_status = self.payload.get('publish_status') if not isinstance(publish_status, bool): raise self.InvalidInputException( 'Publish status should only be true or false.') try: if publish_status: topic_services.publish_topic(topic_id, self.user_id) else: topic_services.unpublish_topic(topic_id, self.user_id) except Exception as e: raise self.UnauthorizedUserException(e) self.render_json(self.values)
def test_publish_and_unpublish_topic(self): topic_rights = topic_services.get_topic_rights(self.TOPIC_ID) self.assertFalse(topic_rights.topic_is_published) topic_services.publish_topic(self.TOPIC_ID, self.user_id_admin) with self.assertRaisesRegexp( Exception, 'The user does not have enough rights to unpublish the topic.'): topic_services.unpublish_topic(self.TOPIC_ID, self.user_id_a) topic_rights = topic_services.get_topic_rights(self.TOPIC_ID) self.assertTrue(topic_rights.topic_is_published) topic_services.unpublish_topic(self.TOPIC_ID, self.user_id_admin) topic_rights = topic_services.get_topic_rights(self.TOPIC_ID) self.assertFalse(topic_rights.topic_is_published) with self.assertRaisesRegexp( Exception, 'The user does not have enough rights to publish the topic.'): topic_services.publish_topic(self.TOPIC_ID, self.user_id_a)
def test_cannot_get_with_unpublished_topic(self): topic_services.unpublish_topic(self.topic_id, self.admin_id) self.get_json( '%s/staging/%s/%s' % (feconf.SUBTOPIC_DATA_HANDLER, 'name', 'sub-url-frag-one'), expected_status_int=404)
def test_cannot_unpublish_topic_with_no_topic_rights(self): with self.assertRaisesRegexp( Exception, 'The given topic does not exist'): topic_services.unpublish_topic( 'invalid_topic_id', self.user_id_admin)