Пример #1
0
    def test_getRelationships(self):
        # add relations to retrieve
        self.rest_api.addRelationship(
            self.pid, "info:fedora/%s" % self.pid, unicode(modelns.hasModel), "info:fedora/pid:123", False
        )
        self.rest_api.addRelationship(self.pid, "info:fedora/%s" % self.pid, self.rel_owner, "johndoe", True)

        data, url = self.rest_api.getRelationships(self.pid)
        graph = parse_rdf(data, url)

        # check total number: fedora-system cmodel + two just added
        self.assertEqual(3, len(list(graph)))
        # newly added triples should be included in the graph
        self.assert_((URIRef("info:fedora/%s" % self.pid), modelns.hasModel, URIRef("info:fedora/pid:123")) in graph)

        self.assertEqual(
            "johndoe", graph.value(subject=URIRef("info:fedora/%s" % self.pid), predicate=URIRef(self.rel_owner))
        )

        # get rels for a single predicate
        data, url = self.rest_api.getRelationships(self.pid, predicate=self.rel_owner)
        graph = parse_rdf(data, url)
        # should include just the one we asked for
        self.assertEqual(1, len(list(graph)))

        self.assertEqual(
            "johndoe", graph.value(subject=URIRef("info:fedora/%s" % self.pid), predicate=URIRef(self.rel_owner))
        )
Пример #2
0
    def test_getRelationships(self):
        # add relations to retrieve
        self.rest_api.addRelationship(self.pid, 'info:fedora/%s' % self.pid,
                                      force_text(modelns.hasModel),
                                      "info:fedora/pid:123", False)
        self.rest_api.addRelationship(self.pid, 'info:fedora/%s' % self.pid,
                                      self.rel_owner, "johndoe", True)

        r = self.rest_api.getRelationships(self.pid)
        graph = parse_rdf(r.content, r.url)

        # check total number: fedora-system cmodel + two just added
        self.assertEqual(3, len(list(graph)))
        # newly added triples should be included in the graph
        self.assert_((URIRef('info:fedora/%s' % self.pid), modelns.hasModel,
                      URIRef('info:fedora/pid:123')) in graph)

        self.assertEqual(
            'johndoe',
            str(
                graph.value(subject=URIRef('info:fedora/%s' % self.pid),
                            predicate=URIRef(self.rel_owner))))

        # get rels for a single predicate
        r = self.rest_api.getRelationships(self.pid, predicate=self.rel_owner)
        graph = parse_rdf(r.content, r.url)
        # should include just the one we asked for
        self.assertEqual(1, len(list(graph)))

        self.assertEqual(
            'johndoe',
            str(
                graph.value(subject=URIRef('info:fedora/%s' % self.pid),
                            predicate=URIRef(self.rel_owner))))
Пример #3
0
    def _query(self, format, http_args, flush=None):
        # if flush parameter was not specified, use class setting
        if flush is None:
            flush = self.RISEARCH_FLUSH_ON_QUERY
        http_args['flush'] = 'true' if flush else 'false'

        # log the actual query so it's easier to see what's happening
        logger.debug('risearch query type=%(type)s language=%(lang)s format=%(format)s flush=%(flush)s\n%(query)s' % \
            http_args)

        url = 'risearch'
        try:
            r = self.get(url, params=http_args)
            data, abs_url = r.content, r.url
            # parse the result according to requested format
            if format == 'N-Triples':
                return parse_rdf(data, abs_url, format='n3')
            elif format == 'CSV':
                # reader expects a file or a list; for now, just split the string
                # TODO: when we can return url contents as file-like objects, use that
                return csv.DictReader(data.split('\n'))
            elif format == 'count':
                return int(data)

            # should we return the response as fallback?
        except RequestFailed, f:
            if 'Unrecognized query language' in f.detail:
                raise UnrecognizedQueryLanguage(f.detail)
            # could also see 'Unsupported output format'
            else:
                raise f
Пример #4
0
    def _query(self, format, http_args, flush=None):
        # if flush parameter was not specified, use class setting
        if flush is None:
            flush = self.RISEARCH_FLUSH_ON_QUERY
        http_args['flush'] = 'true' if flush else 'false'

        risearch_url = 'risearch?'
        rel_url = risearch_url + urlencode(http_args)
        try:
            data, abs_url = self.read(rel_url)
            # parse the result according to requested format
            if format == 'N-Triples':
                return parse_rdf(data, abs_url, format='n3')
            elif format == 'CSV':
                # reader expects a file or a list; for now, just split the string
                # TODO: when we can return url contents as file-like objects, use that
                return csv.DictReader(data.split('\n'))
            elif format == 'count':
                return int(data)

            # should we return the response as fallback?
        except RequestFailed, f:
            if 'Unrecognized query language' in f.detail:
                raise UnrecognizedQueryLanguage(f.detail)
            # could also see 'Unsupported output format'
            else:
                raise f
Пример #5
0
 def _query(self, format, http_args, flush=None):
     # if flush parameter was not specified, use class setting
     if flush is None:
         flush = self.RISEARCH_FLUSH_ON_QUERY
     http_args['flush'] = 'true' if flush else 'false'
     
     risearch_url = 'risearch?'
     rel_url = risearch_url + urlencode(http_args)
     try:
         data, abs_url = self.read(rel_url)
         # parse the result according to requested format
         if format == 'N-Triples':
             return parse_rdf(data, abs_url, format='n3')
         elif format == 'CSV':
             # reader expects a file or a list; for now, just split the string
             # TODO: when we can return url contents as file-like objects, use that
             return csv.DictReader(data.split('\n'))
         elif format == 'count':
             return int(data)
         
         # should we return the response as fallback? 
     except RequestFailed, f:
         if 'Unrecognized query language' in f.detail:
             raise UnrecognizedQueryLanguage(f.detail)
         # could also see 'Unsupported output format' 
         else:
             raise f
Пример #6
0
    def _query(self, format, http_args, flush=None):
        # if flush parameter was not specified, use class setting
        if flush is None:
            flush = self.RISEARCH_FLUSH_ON_QUERY
        http_args['flush'] = 'true' if flush else 'false'

        # log the actual query so it's easier to see what's happening
        logger.debug('risearch query type=%(type)s language=%(lang)s format=%(format)s flush=%(flush)s\n%(query)s' % \
            http_args)

        url = 'risearch'
        try:
            response = self.get(url, params=http_args)
            data, abs_url = response.content, response.url
            # parse the result according to requested format
            if format == 'N-Triples':
                return parse_rdf(data, abs_url, format='n3')
            elif format == 'CSV':
                # reader expects a file or a list; for now, just split the string
                # TODO: when we can return url contents as file-like objects, use that
                return csv.DictReader(response.text.split('\n'))
            elif format == 'count':
                return int(data)

            # should we return the response as fallback?
        except RequestFailed as err:
            if 'Unrecognized query language' in err.detail:
                raise UnrecognizedQueryLanguage(err.detail)
            # could also see 'Unsupported output format'
            else:
                raise err
Пример #7
0
    def _query(self, format, http_args, flush=None):
        # if flush parameter was not specified, use class setting
        if flush is None:
            flush = self.RISEARCH_FLUSH_ON_QUERY
        http_args['flush'] = 'true' if flush else 'false'

        # log the actual query so it's easier to see what's happening
        logger.debug('risearch query type=%(type)s language=%(lang)s format=%(format)s flush=%(flush)s\n%(query)s' % \
            http_args)

        url = 'risearch'
        try:
            start = time.time()
            response = self.get(url, params=http_args)
            data, abs_url = response.content, response.url
            total_time = time.time() - start
            # parse the result according to requested format
            if api_called is not None:
                api_called.send(sender=self.__class__, time_taken=total_time,
                                method='risearch', url='', response=response,
                                args=[], kwargs={'format': format,
                                                 'http_args': http_args,
                                                 'flush': flush})
            if format == 'N-Triples':
                return parse_rdf(data, abs_url, format='n3')
            elif format == 'CSV':
                # reader expects a file or a list; for now, just split the string
                # TODO: when we can return url contents as file-like objects, use that
                return csv.DictReader(response.text.split('\n'))
            elif format == 'count':
                return int(data)

            # should we return the response as fallback?
        except RequestFailed as err:
            if 'Unrecognized query language' in err.detail:
                raise UnrecognizedQueryLanguage(err.detail)
            # could also see 'Unsupported output format'
            else:
                raise err