Esempio n. 1
0
    def test_yaml_methods(self):
        """Test the as_yaml() and create_from_yaml() methods."""
        exploration = Exploration.create(
            self.user, 'A title', 'A category', 'A different exploration_id')
        exploration.add_state('New state')
        yaml_file = exploration.as_yaml()
        self.assertEqual(yaml_file, """Activity 1:
  content: []
  param_changes: []
  widget:
    handlers:
    - name: submit
      rules:
      - dest: Activity 1
        feedback: []
        inputs: {}
        name: Default
        param_changes: []
    params: {}
    sticky: false
    widget_id: Continue
New state:
  content: []
  param_changes: []
  widget:
    handlers:
    - name: submit
      rules:
      - dest: New state
        feedback: []
        inputs: {}
        name: Default
        param_changes: []
    params: {}
    sticky: false
    widget_id: Continue
""")

        exploration2 = Exploration.create_from_yaml(
            yaml_file, self.user, 'Title', 'Category')
        self.assertEqual(len(exploration2.states), 2)
        self.assertEqual(exploration2.as_yaml(), yaml_file)

        self.assertEqual(Exploration.query().count(), 2)

        with self.assertRaises(Exception):
            Exploration.create_from_yaml(
                'No_initial_state_name', self.user, 'Title', 'category')

        with self.assertRaises(Exception):
            Exploration.create_from_yaml(
                'Invalid\ninit_state_name:\nMore stuff',
                self.user, 'Title', 'category')

        with self.assertRaises(Exception):
            Exploration.create_from_yaml(
                'State1:\n(\nInvalid yaml', self.user, 'Title', 'category')

        # Check that no new exploration was created.
        self.assertEqual(Exploration.query().count(), 2)
Esempio n. 2
0
    def test_loading_and_deletion_of_demo_explorations(self):
        """Test loading and deletion of the demo explorations."""
        self.assertEqual(Exploration.query().count(), 0)

        Exploration.load_demo_explorations()
        self.assertEqual(Exploration.query().count(), 6)

        Exploration.delete_demo_explorations()
        self.assertEqual(Exploration.query().count(), 0)
Esempio n. 3
0
    def get(self):
        """Handles GET requests."""
        explorations = Exploration.query().filter(
            Exploration.is_public == True).fetch(100)

        # Don't use the first exploration; users will have seen that already
        # on the main page.
        selected_exploration = utils.get_random_choice(explorations[1:])

        self.redirect('/learn/%s' % selected_exploration.id)
Esempio n. 4
0
def get_viewable_explorations(user):
    """Returns a list of explorations viewable by the given user."""
    return Exploration.query().filter(
        ndb.OR(Exploration.is_public == True, Exploration.editors == user)
    )