File: test_doi.py

package info (click to toggle)
finalcif 137%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 43,544 kB
  • sloc: python: 49,119; cpp: 67; sh: 51; makefile: 22
file content (71 lines) | stat: -rw-r--r-- 2,931 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import unittest
from unittest import TestCase

from finalcif.cif.cod.doi import resolve_doi, get_names_from_doi

doi_data = {
    'author': [{'ORCID'              : 'http://orcid.org/0000-0003-0970-9780',
                'affiliation'        : [],
                'authenticated-orcid': True,
                'family'             : 'Kratzert',
                'given'              : 'Daniel',
                'sequence'           : 'first'},
               {'ORCID'              : 'http://orcid.org/0000-0002-7182-4387',
                'affiliation'        : [],
                'authenticated-orcid': True,
                'family'             : 'Krossing',
                'given'              : 'Ingo',
                'sequence'           : 'additional'}],
}


@unittest.skip('Fails because of network errors')
class TestDOI(TestCase):
    def setUp(self) -> None:
        if os.environ.get('NO_NETWORK'):
            self.skipTest('No network available.')
        self.doi = resolve_doi('10.1107/S1600576718004508')

    def test_resolve_doi_doi(self):
        self.assertEqual('2018', self.doi['_journal_year'])

    def test_authors(self):
        self.assertEqual('Kratzert, Daniel', self.doi['_publ_author_name'][0])

    def test_get_names_from_doi(self):
        self.assertEqual(['Kratzert, Daniel', 'Krossing, Ingo'], get_names_from_doi(doi_data))


@unittest.skip('Fails because of network errors')
class TestDOIOld(TestCase):
    def setUp(self) -> None:
        if os.environ.get('NO_NETWORK'):
            self.skipTest('No network available.')

    def test_resolve_doi_online(self):
        result = {'_journal_name_full' : 'Inorganic Chemistry',
                  '_publ_author_name'  : ['Le Bail, A.', 'Marcos, M. D.', 'Amoros, P.'],
                  '_journal_page_first': '2607',
                  '_publ_section_title': 'Ab Initio Crystal Structure Determination of '
                                         'VO(H2PO2)2.cntdot.H2O from X-ray and Neutron Powder '
                                         'Diffraction Data. A Monodimensional Vanadium(IV) '
                                         'Hypophosphite',
                  '_journal_year'      : '1994'}
        self.assertEqual(result, resolve_doi('http://doi.org/10.1021/ic00090a021'))

    def test_empty_url(self):
        result = {'_journal_name_full' : '',
                  '_journal_page_first': '',
                  '_journal_year'      : '',
                  '_publ_author_name'  : [],
                  '_publ_section_title': ''}
        self.assertEqual(result, resolve_doi(''))

    def test_invalid_url(self):
        result = {'_journal_name_full' : '',
                  '_journal_page_first': '',
                  '_journal_year'      : '',
                  '_publ_author_name'  : [],
                  '_publ_section_title': ''}
        self.assertEqual(result, resolve_doi('http://doi.org/10.1021/ic00090a02'))