示例#1
0
 def test_04_detect_verify_type_error(self):
     # create an invalid pmid and assert it is a pmid
     pmid = PMIDPlugin()
     bjid = {"id" : "a;lkdsjfjdsajadskja", "type" : "pmid"}
     record = models.MessageObject(bid=bjid)
     with self.assertRaises(models.LookupException):
         pmid.type_detect_verify(record)
 def test_07_canonicalise_error(self):
     pmid = PMIDPlugin()
     # create an invalid pmid and assert it is a pmid
     bjid = {"id" : "a;lkdsjfjdsajadskja", "type" : "pmid"}
     with self.assertRaises(model_exceptions.LookupException):
         pmid.canonicalise(bjid)
         
     bjid = {"key" : "value"}
     with self.assertRaises(model_exceptions.LookupException):
         pmid.canonicalise(bjid)
 def test_03_detect_verify_type_ignores(self):
     pmid = PMIDPlugin()
     
     bjid = {"id" : "whatever", "type" : "doi"}
     pmid.type_detect_verify(bjid)
     assert bjid['type'] == "doi"
     
     bjid = {"key" : "value"}
     pmid.type_detect_verify(bjid)
     assert not bjid.has_key("type")
示例#4
0
 def test_02_detect_verify_type_not_pmids(self):
     #Test the various erroneous PMID possibilities, which will include:
     #- less than 1 and more than 8 digits
     #- random strings (i.e. not just digits)
     pmid = PMIDPlugin()
     
     # some random digits
     bjid = {'id' : 'qp23u4ehjkjewfiuwqr'} # random numbers and digits
     record = models.MessageObject(bid=bjid)
     pmid.type_detect_verify(record)
     assert not bjid.has_key("type")
     
     bjid = {'id' : 'qp23u4.10238765.jewfiuwqr'} # has an 8 digit substring in it
         # (therefore also has a 1,2..7-digit substring in it)
     record = models.MessageObject(bid=bjid)
     pmid.type_detect_verify(record)
     assert not bjid.has_key("type")
     
     # less than 1 and more than 8 digits
     bjid = {'id' : ''} # well, less than 1 digit doesn't exist
         # and letters are covered elsewhere...
     record = models.MessageObject(bid=bjid)
     pmid.type_detect_verify(record)
     assert not bjid.has_key("type")
     
     bjid = {'id' : '123456789'}
     record = models.MessageObject(bid=bjid)
     pmid.type_detect_verify(record)
     assert not bjid.has_key("type")
 def test_05_canonicalise_real(self):
     pmid = PMIDPlugin()
     counter = 0
     for d in CANONICAL.keys():
         bjid = {'id' : d, 'type' : 'pmid'}
         pmid.canonicalise(bjid)
         assert bjid.has_key("canonical")
         assert bjid["canonical"] == CANONICAL[d]
         counter += 1
     assert counter == len(CANONICAL.keys())
     assert counter > 0
 def test_01_detect_verify_type_real_pmids(self):
     pmid = PMIDPlugin()
     counter = 0
     for d in PMIDS:
         bjid = {'id' : d}
         pmid.type_detect_verify(bjid)
         assert bjid.has_key("type")
         assert bjid["type"] == "pmid"
         counter += 1
     assert counter == len(PMIDS)
     assert counter > 0
示例#7
0
    def test_12_provider_resolve_fail_doi(self):
        old_get = util.http_get
        util.http_get = get_doi_fail
        pmid = PMIDPlugin()

        record = {"identifier" : {"id" : "23175652", "type" : "pmid", "canonical" : "pmid:23175652"}}
        record = models.MessageObject(record=record)

        with self.assertRaises(plugin.PluginException):
            pmid.detect_provider(record)

        util.http_get = old_get
示例#8
0
 def test_01_detect_verify_type_real_pmids(self):
     pmid = PMIDPlugin()
     counter = 0
     for d in PMIDS:
         bjid = {'id' : d}
         record = models.MessageObject(bid=bjid)
         pmid.type_detect_verify(record)
         assert bjid.has_key("type")
         assert bjid["type"] == "pmid"
         counter += 1
     assert counter == len(PMIDS)
     assert counter > 0
示例#9
0
 def test_07_canonicalise_error(self):
     pmid = PMIDPlugin()
     # create an invalid pmid and assert it is a pmid
     bjid = {"id" : "a;lkdsjfjdsajadskja", "type" : "pmid"}
     record = models.MessageObject(bid=bjid)
     with self.assertRaises(models.LookupException):
         pmid.canonicalise(record)
         
     bjid = {"key" : "value"}
     record = models.MessageObject(record={"identifier" : bjid})
     with self.assertRaises(models.LookupException):
         pmid.canonicalise(record)
示例#10
0
 def test_05_canonicalise_real(self):
     pmid = PMIDPlugin()
     counter = 0
     for d in CANONICAL.keys():
         bjid = {'id' : d, 'type' : 'pmid'}
         record = models.MessageObject(bid=bjid)
         pmid.canonicalise(record)
         assert bjid.has_key("canonical")
         assert bjid["canonical"] == CANONICAL[d]
         counter += 1
     assert counter == len(CANONICAL.keys())
     assert counter > 0
示例#11
0
 def test_03_detect_verify_type_ignores(self):
     pmid = PMIDPlugin()
     
     bjid = {"id" : "whatever", "type" : "doi"}
     record = models.MessageObject(bid=bjid)
     pmid.type_detect_verify(record)
     assert bjid['type'] == "doi"
     
     bjid = {"key" : "value"}
     record = models.MessageObject(record={"identifier" : bjid})
     pmid.type_detect_verify(record)
     assert not bjid.has_key("type")
示例#12
0
 def test_10_provider_resolve_from_icon(self):
     old_get = requests.get
     requests.get = get_icon
     pmid = PMIDPlugin()
     
     record = {"identifier" : {"id" : "23175652", "type" : "pmid", "canonical" : "pmid:23175652"}}
     
     pmid.provider_resolver(record)
     assert "provider" in record
     assert "url" in record["provider"]
     assert record['provider']["url"][0] == "http://jb.asm.org/cgi/pmidlookup?view=long&pmid=23175652", record['provider']["url"][0]
     
     requests.get = old_get
示例#13
0
 def test_09_provider_resolve_doi(self):
     old_get = requests.get
     requests.get = get_doi
     pmid = PMIDPlugin()
     
     record = {"identifier" : {"id" : "23175652", "type" : "pmid", "canonical" : "pmid:23175652"}}
     
     pmid.provider_resolver(record)
     assert "provider" in record
     assert "url" in record["provider"]
     assert record['provider']["url"][0] == "http://jb.asm.org/content/195/3/502", record['provider']['url']
     assert record["provider"]["doi"] == "doi:10.1128/JB.01321-12"
     
     requests.get = old_get
示例#14
0
 def test_11_provider_resolve_from_resources(self):
     old_get = requests.get
     requests.get = get_linkout
     pmid = PMIDPlugin()
     
     record = {"identifier" : {"id" : "1234567", "type" : "pmid", "canonical" : "pmid:1234567"}}
     
     pmid.provider_resolver(record)
     assert "provider" in record
     assert "url" in record["provider"]
     assert "http://www.nlm.nih.gov/medlineplus/menopause.html" in record["provider"]["url"], record["provider"]["url"]
     assert "http://toxnet.nlm.nih.gov/cgi-bin/sis/search/r?dbs+hsdb:@term+@rn+50-28-2" in record["provider"]["url"], record["provider"]["url"]
     assert len(record['provider']['url']) == 2
     
     requests.get = old_get
示例#15
0
 def test_10_provider_resolve_from_icon(self):
     old_get = util.http_get
     util.http_get = get_icon
     pmid = PMIDPlugin()
     
     record = {"identifier" : {"id" : "23175652", "type" : "pmid", "canonical" : "pmid:23175652"}}
     record = models.MessageObject(record=record)
     
     pmid.detect_provider(record)
     
     record = record.record
     assert "provider" in record
     assert "url" in record["provider"]
     assert record['provider']["url"][0] == "http://jb.asm.org/cgi/pmidlookup?view=long&pmid=23175652", record['provider']["url"][0]
     
     util.http_get = old_get
示例#16
0
 def test_09_provider_resolve_doi(self):
     old_get = util.http_get
     util.http_get = get_doi
     pmid = PMIDPlugin()
     
     record = {"identifier" : {"id" : "23175652", "type" : "pmid", "canonical" : "pmid:23175652"}}
     record = models.MessageObject(record=record)
     
     pmid.detect_provider(record)
     
     record = record.record
     assert "provider" in record
     assert "url" in record["provider"]
     assert record['provider']["url"][0] == "http://jb.asm.org/content/195/3/502", record['provider']['url']
     assert record["provider"]["doi"] == "doi:10.1128/JB.01321-12"
     
     util.http_get = old_get
示例#17
0
 def test_08_provider_resolve_not_relevant(self):
     pmid = PMIDPlugin()
     record = {}
     
     pmid.provider_resolver(record)
     assert len(record.keys()) == 0
     
     record['identifier'] = {}
     pmid.provider_resolver(record)
     assert len(record['identifier'].keys()) == 0
     
     record['identifier']['id'] = "123"
     record['identifier']['type'] = "doi"
     record['identifier']['canonical'] = "doi:123"
     pmid.provider_resolver(record)
     assert not "provider" in record
     
     record['identifier']['type'] = "pmid"
     del record['identifier']['canonical']
     pmid.provider_resolver(record)
     assert not "provider" in record
示例#18
0
    def test_08_provider_resolve_not_relevant(self):
        pmid = PMIDPlugin()
        record = models.MessageObject()
        
        pmid.detect_provider(record)
        assert len(record.record.keys()) == 0

        record.id = "123"
        record.identifier_type = "doi"
        record.canonical = "doi:123"
        pmid.detect_provider(record)
        assert not "provider" in record.record

        record.identifier_type = "pmid"
        record.canonical = None
        pmid.detect_provider(record)
        assert not "provider" in record.record
示例#19
0
 def test_06_canonicalise_ignore(self):
     pmid = PMIDPlugin()
     bjid = {"id" : "whatever", "type" : "doi"}
     record = models.MessageObject(bid=bjid)
     pmid.canonicalise(record)
     assert not bjid.has_key("canonical")
示例#20
0
 def test_06_canonicalise_ignore(self):
     pmid = PMIDPlugin()
     bjid = {"id" : "whatever", "type" : "doi"}
     pmid.canonicalise(bjid)
     assert not bjid.has_key("canonical")
示例#21
0
 def test_04_detect_verify_type_error(self):
     # create an invalid pmid and assert it is a pmid
     pmid = PMIDPlugin()
     bjid = {"id" : "a;lkdsjfjdsajadskja", "type" : "pmid"}
     with self.assertRaises(model_exceptions.LookupException):
         pmid.type_detect_verify(bjid)