Example #1
0
    def test_get_all_explorations(self):
        """Test get_all_explorations()."""

        exploration = Exploration.get(
            exp_services.create_new(self.owner_id, "A title", "A category", "A exploration_id")
        )
        self.assertItemsEqual([e.id for e in exp_services.get_all_explorations()], [exploration.id])

        exploration2 = Exploration.get(
            exp_services.create_new(self.owner_id, "A new title", "A category", "A new exploration_id")
        )
        self.assertItemsEqual([e.id for e in exp_services.get_all_explorations()], [exploration.id, exploration2.id])
Example #2
0
 def tearDown(self):
     """Deletes all widgets and explorations."""
     InteractiveWidget.delete_all_widgets()
     explorations = exp_services.get_all_explorations()
     for exploration in explorations:
         exploration.delete()
     super(ExplorationDomainUnitTests, self).tearDown()
Example #3
0
    def get(self):
        """Handles GET requests."""
        if users.is_current_user_admin():
            explorations = exp_services.get_all_explorations()
            editable_exploration_ids = [e.id for e in explorations]
        elif self.user_id:
            explorations = exp_services.get_viewable_explorations(self.user_id)
            editable_exploration_ids = [
                e.id for e in exp_services.get_editable_explorations(
                    self.user_id)
            ]
        else:
            explorations = exp_services.get_public_explorations()
            editable_exploration_ids = []

        categories = collections.defaultdict(list)

        for exploration in explorations:
            categories[exploration.category].append({
                'can_edit': exploration.id in editable_exploration_ids,
                'can_fork': self.user_id and exploration.is_demo,
                'id': exploration.id,
                'image_id': exploration.image_id,
                'is_owner': (users.is_current_user_admin() or
                             exploration.is_owned_by(self.user_id)),
                'title': exploration.title,
            })

        self.values.update({
            'categories': categories,
        })
        self.render_json(self.values)
Example #4
0
    def get(self):
        """Handles GET requests."""
        if users.is_current_user_admin():
            exps = exp_services.get_all_explorations()
        else:
            exps = exp_services.get_editable_explorations(self.user_id)

        self.values.update({
            'explorations': [{
                'id': exp.id,
                'image_id': exp.image_id,
                'name': exp.title,
            } for exp in exps],
            'improvable': stats_services.get_top_ten_improvable_states(exps),
        })
        self.render_json(self.values)
Example #5
0
 def tearDown(self):
     self.user.delete()
     InteractiveWidget.delete_all_widgets()
     explorations = exp_services.get_all_explorations()
     for exploration in explorations:
         exploration.delete()
Example #6
0
 def tearDown(self):
     """Deletes the dummy users and any other widgets and explorations."""
     InteractiveWidget.delete_all_widgets()
     explorations = exp_services.get_all_explorations()
     for exploration in explorations:
         exploration.delete()