Beispiel #1
0
    def test_citations_fetch_all(self):
        art = models.Article(**{
            'doi': self.doi,
            'pmid': self.pmid,
            'pmcid': self.pmcid
        })
        art.save()

        fixture = join(self.fixture_dir,
                       'pm-citation-request-response-09560.json')
        expected_body_content = json.load(open(fixture, 'r'))
        responses.add(
            responses.GET, citations.PM_URL, **{
                'json': expected_body_content,
                'status': 200,
                'content_type': 'application/json'
            })

        expected_citations = len(
            expected_body_content['linksets'][0]['linksetdbs'][0]['links'])
        expected = [{
            'source':
            'pubmed',
            'pmcid':
            self.pmcid,
            'num':
            expected_citations,
            'source_id':
            'https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4559886/'
        }]

        results = citations.citations_for_all_articles()
        self.assertEqual(results, expected)
Beispiel #2
0
    def test_count_response(self):
        art = models.Article(**{
            'doi': self.doi,
            'pmid': self.pmid,
            'pmcid': self.pmcid
        })
        art.save()

        msid = 9560

        fixture = join(self.fixture_dir,
                       'pm-citation-request-response-09560.json')
        expected_body_content = json.load(open(fixture, 'r'))

        responses.add(
            responses.GET, citations.PM_URL, **{
                'json': expected_body_content,
                'status': 200,
                'content_type': 'application/json'
            })

        expected = [{
            'pmcid': 'PMC4559886',
            'source': 'pubmed',
            'source_id':
            'https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4559886/',
            'num': 17
        }]

        self.assertEqual(citations.count_for_msid(msid), expected)
        self.assertEqual(citations.count_for_doi(self.doi), expected)
Beispiel #3
0
 def test_resolve_pmcid_preexisting(self):
     "test that no lookup for a pmcid is done if Article already has such an id"
     art = models.Article(**{
         'doi': '10.7554/eLife.09560',
         'pmid': None,
         'pmcid': 'NOTAPMCID',
     })
     art.save()
     given = citations.resolve_pmcid(art)
     expected = 'NOTAPMCID'
     self.assertEqual(expected, given)
     models.Article.objects.get(pmcid=expected)
Beispiel #4
0
    def test_resolve_pmcid(self):
        "test that a pmid and pmcid can be fetched if an article is missing theirs"
        art = models.Article(**{
            'doi': '10.7554/eLife.09560',
            'pmid': None,
            'pmcid': None
        })
        art.save()

        fixture = join(self.fixture_dir, 'pm-fetch-pmids-response.json')
        expected_body_content = json.load(open(fixture, 'r'))
        responses.add(
            responses.GET, citations.PMID_URL, **{
                'json': expected_body_content,
                'status': 200,
                'content_type': 'application/json'
            })

        given = citations.resolve_pmcid(art)
        expected = 'PMC4559886'
        self.assertEqual(expected, given)
        models.Article.objects.get(pmcid=expected)
Beispiel #5
0
 def test_doi_validator_with_models_invalid(self):
     invalid_art = models.Article(doi='00.0000/foo.bar')
     self.assertRaises(ValidationError, invalid_art.save)
Beispiel #6
0
 def test_doi_validator_with_models(self):
     valid_art = models.Article(doi=settings.DOI_PREFIX + '/foo.bar')
     valid_art.save() # no validation error