Exemplo n.º 1
0
class ResolverTests(TestCase):

    context = Context()

    OCLC_GATEWAY_URL = 'http://worldcatlibraries.org/registry/gateway'

    def test_default(self):
        r = find_resolver(self.context, '999.9.9.9')
        self.assertEqual(self.OCLC_GATEWAY_URL, r.base_url)

    def test_default_text(self):
        r = find_resolver(self.context, '999.9.9.9')
        self.assertEqual('Find in a library', r.link_text)

    def test_simple(self):
        # curtis.med.yale.edu
        r = find_resolver(self.context, '128.36.123.51')
        self.failIfEqual(self.OCLC_GATEWAY_URL, r.base_url)

    def test_yale(self):
        # NOTE: this will fail if YUL's resolver location changes
        r = find_resolver(self.context, '128.36.123.51')
        self.assertEqual('http://sfx.library.yale.edu/sfx_local', r.base_url)

    def test_umich(self):
        # NOTE: this will fail if UMich resolver location changes
        r = find_resolver(self.context, '141.211.2.202')
        self.assertEqual('http://sfx.lib.umich.edu:9003/sfx_locater',
                         r.base_url)
Exemplo n.º 2
0
class UserFunctionTests(TestCase):

    context = Context()

    def test_userset(self):
        set = user.UserSet()
        set.user_id = 6
        set.name = 'test'
        set.save(self.context)
        loaded_set = user.UserSet(self.context, set.uid)
        self.assertEquals(loaded_set.name, set.name)
Exemplo n.º 3
0
    def context(self):
        """After you've called parse_args() you should be able 
        to fetch a canary.context.Context object.

        context = cmdline.context()
        """
        if not self.options.config:
            self.guess_canary_config()

        from canary.context import CanaryConfig, Context
        config = CanaryConfig()
        config.read_file(self.options.config)
        return Context(config)
Exemplo n.º 4
0
class SearchTests(TestCase):

    context = Context()

    def test_context(self):
        self.assertEquals(isinstance(self.context, Context), True)

    def test_simple_search(self):
        try:
            search_index = SearchIndex(self.context)
            hits, searcher = search_index.search('test')
            for i, doc in hits:
                foo, bar = doc.get('uid'), hits.score(i)
            if searcher:
                searcher.close()
        except Exception, e:
            self.fail('Error searching: %s' % e)
Exemplo n.º 5
0
class ParserTests(TestCase):
    """A fixture for setting up common tangle of objects used during parsing.
    Hopefully this will change (or go away) as parsing is refactored.
    """

    context = Context()

    def __init__(self, name, source_name):
        TestCase.__init__(self, name)
        source_catalog = self.context.get_source_catalog()
        source = source_catalog.get_source_by_name(source_name)
        self.mapped_terms = source_catalog.get_mapped_terms(source.uid)
        self.parser = Parser(source)

    def parse(self, file_name):
        return self.parser.parse(file_name, self.mapped_terms, False)

    def parse_email(self, file_name):
        return self.parser.parse(file_name, self.mapped_terms, True)

    def get_mapped_metadata(self, record):
        return record.get_mapped_metadata(self.mapped_terms)
Exemplo n.º 6
0
#!/usr/bin/env python

# $Id$

from canary.context import Context
from canary.loader import QueuedRecord
from canary.study import Study

context = Context()
cursor = context.get_cursor()
cursor.execute("""
    SELECT studies.record_id, study_history.study_id, study_history.modified
    FROM study_history, studies
    WHERE study_history.message = 'Set record status to curated'
    AND study_history.study_id = studies.uid
    ORDER BY studies.record_id ASC, study_history.modified ASC
    """)

for row in cursor:
    print "record_id:%i; study_id:%i; curated:%s" % row
    # update either QUEUED_RECORDS or STUDIES with curated time
    # r = QueuedRecord(con,row[0])
    # r.date_curated = row[2]
    # r.save
    s = Study(context, row[1])
    s.date_curated = row[2]
    s.save(context)
Exemplo n.º 7
0
#!/usr/bin/env python

# $Id$


from canary.context import Context
from canary.loader import QueuedRecord
from canary.study import Study

context = Context()
cursor = context.get_cursor()
cursor.execute("""
    SELECT studies.record_id, study_history.study_id, study_history.modified
    FROM study_history, studies
    WHERE study_history.message = 'Set record status to curated'
    AND study_history.study_id = studies.uid
    ORDER BY studies.record_id ASC, study_history.modified ASC
    """)

for row in cursor:
    print "record_id:%i; study_id:%i; curated:%s" % row
    # update either QUEUED_RECORDS or STUDIES with curated time
    # r = QueuedRecord(con,row[0])
    # r.date_curated = row[2]
    # r.save
    s = Study(context, row[1])
    s.date_curated = row[2]
    s.save(context)

Exemplo n.º 8
0
    legend(
        (p_exp[0], p_coh[0], p_csec[0], p_desc[0], precords[0], pstudies[0]),
        ('Experimental', 'Cohort', 'Cross-Sectional', 'Descriptive',
         '# Studies Total', '# Records w/Linkage'))
    ##    legend((p_exp[0], p_desc[0], p_agg[0], p_csec[0], p_coh[0],
    ##        p_cc[0], p_dm[0], precords[0], pstudies[0]),
    ##        ('Experimental', 'Descriptive', 'Aggregate',
    ##        'Cross-Sectional', 'Cohort', 'Case-Control', 'Disease Model',

    #savefig(('%s' % token.replace(' ', '_')))
    show()
    cla()


if __name__ == '__main__':
    context = Context()
    search_index = SearchIndex(context)
    searches = (
        'Lead [exposure]',
        'Hantavirus [exposure]',
        'peromyscus [species]',
        'Michigan [location]',
        'DDT [exposure]',
        '2003 [year]',
        'cats and dogs',
        '"Burger J" [author]',
        'cross-sectional [methodology]',
        'case-control [methodology] and cattle [species]',
        'disease-model [methodology]',
        '"age factors" [risk_factors]',
        'Sarin [exposure]',
Exemplo n.º 9
0
class StatsTests (TestCase):

    context = Context()
    
    def setUp (self):
        # each test gets a new collector
        self.collector = StatCollector(self.context)
        # get some records for statistics generation once
        searcher = RecordSearcher(self.context)
        self.records = searcher.search('environment')

    def test_curators (self):
        handler = ArticleTypeHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_article_types (self):
        handler = ArticleTypeHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_methodology_samplings (self):
        handler = MethodologySamplingHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_methology_types (self):
        handler = MethodologyTypeHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_methology_timings (self):
        handler = MethodologyTimingHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_methology_controls (self):
        handler = MethodologyControlHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_exposure_routes (self):
        handler = ExposureRouteHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_exposures (self):
        handler = ExposureHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_risk_factors (self):
        handler = RiskFactorHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_outcomes (self):
        handler = OutcomeHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_species (self):
        handler = SpeciesHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)

    def test_locations (self):
        handler = LocationHandler()
        self.collector.add_handler(handler)
        self.collector.process(self.records)
        self.assertEquals(len(handler.stats.keys()) > 0, True)