Exemple #1
0
    def teardown_databases(self, old_config, *args, **kwargs):
        """
        After all tests
        """
        # close the session
        session.close()

        # free the connection
        engine.dispose()

        # default django teardown performs destruction of the test base
        super(GargTestRunner, self).teardown_databases(old_config, *args, **kwargs)
    def delete(self, request, node_id):

        if not request.user.is_authenticated():
            # can't use @requires_auth because of positional 'self' within class
            return HttpResponse('Unauthorized', status=401)

        parameters, query, count = _query_nodes(request, node_id)
        if not len(query):
            raise Http404()
        try:
            result = session.execute(delete(Node).where(Node.id == node_id))
            session.commit()
        finally:
            session.close()
        return JsonHttpResponse({'deleted': result.rowcount})
    def delete(self, request, corpus_id):
        """
        DELETE http://localhost:8000/api/nodes/2/favorites?docs=53,54
        (will delete docs 53 and 54 from the favorites of corpus 2)
        """
        if not request.user.is_authenticated():
            # can't use @requires_auth because of positional 'self' within class
            return HttpResponse('Unauthorized', status=401)

        # user is ok
        fav_node = self._get_fav_node(corpus_id)

        response = {}

        if fav_node == None:
            response = {
                'warning':
                'No favorites node is defined for this corpus (\'%s\')' %
                self.corpus.name,
                'count_removed':
                0
            }
        else:
            req_params = validate(get_parameters(request), {
                'docs': list,
                'default': ""
            })
            nodeids_to_delete = [
                int(did) for did in req_params['docs'].split(',')
            ]
            try:
                # it deletes from favourites but not from DB
                result = session.execute(
                    delete(NodeNode).where(
                        NodeNode.node1_id == fav_node.id).where(
                            NodeNode.node2_id.in_(nodeids_to_delete)))
                session.commit()
                response = {'count_removed': result.rowcount}
            finally:
                session.close()
        return JsonHttpResponse(response)
    def delete(self, request):
        """Removes the list of nodes corresponding to the query.
        TODO : Should be a delete method!
        """
        if not request.user.is_authenticated():
            # can't use @requires_auth because of positional 'self' within class
            return HttpResponse('Unauthorized', status=401)

        parameters = get_parameters(request)
        parameters = validate(parameters, {'ids': list})
        try:
            node_ids = [int(n) for n in parameters['ids'].split(',')]
        except:
            raise ValidationException(
                '"ids" needs integers separated by comma.')
        try:
            result = session.execute(delete(Node).where(Node.id.in_(node_ids)))
            session.commit()
        finally:
            session.close()
        return JsonHttpResponse({'deleted': result.rowcount})