Exemplo n.º 1
0
def test_orcid_validator_accepts_existing_orcids(mock_member_api):
    mock_orcid_api = MockOrcidAPI({
        'num-found':
        1,
        'result': [
            {
                'orcid-identifier': {
                    'host': 'orcid.org',
                    'path': '0000-0003-1032-3957',
                    'uri': 'http://orcid.org/0000-0003-1032-3957',
                },
            },
        ],
    })
    mock_member_api.return_value = mock_orcid_api

    config = {
        'ORCID_APP_CREDENTIALS': {
            'consumer_key': 'consumer_key',
            'consumer_secret': 'consumer_secret',
        }
    }

    with patch.dict(current_app.config, config):
        field = MockField(u'0000-0003-1032-3957')

        assert ORCIDValidator(None, field) is None
Exemplo n.º 2
0
def test_orcid_validator_accepts_everything_when_orcid_is_not_configured(
        mock_member_api):
    mock_orcid_api = MockOrcidAPI({'orcid-search-results': {'num-found': 0}})
    mock_member_api.return_value = mock_orcid_api

    config = {}

    with patch.dict(current_app.config, config, clear=True):
        field = MockField(u'THIS-ORCID-DOES-NOT-EXIST')

        assert ORCIDValidator(None, field) is None
Exemplo n.º 3
0
def test_orcid_validator_accepts_existing_orcids(mock_member_api):
    mock_orcid_api = MockOrcidAPI({'orcid-search-results': {'num-found': 1}})
    mock_member_api.return_value = mock_orcid_api

    config = {
        'ORCID_APP_CREDENTIALS': {
            'consumer_key': 'consumer_key',
            'consumer_secret': 'consumer_secret',
        }
    }

    with patch.dict(current_app.config, config):
        field = MockField(u'0000-0003-1032-3957')

        assert ORCIDValidator(None, field) is None
Exemplo n.º 4
0
def test_orcid_validator_raises_on_non_existing_orcids(mock_member_api):
    mock_orcid_api = MockOrcidAPI({'orcid-search-results': {'num-found': 0}})
    mock_member_api.return_value = mock_orcid_api

    config = {
        'ORCID_APP_CREDENTIALS': {
            'consumer_key': 'consumer_key',
            'consumer_secret': 'consumer_secret',
        }
    }

    with patch.dict(current_app.config, config):
        field = MockField(u'THIS-ORCID-DOES-NOT-EXIST')

        with pytest.raises(StopValidation):
            ORCIDValidator(None, field)
Exemplo n.º 5
0
def test_orcid_validator_accepts_everything_when_orcid_is_down(
        mock_member_api):
    mock_orcid_api = MockOrcidAPI()
    mock_member_api.return_value = mock_orcid_api

    config = {
        'ORCID_APP_CREDENTIALS': {
            'consumer_key': 'consumer_key',
            'consumer_secret': 'consumer_secret',
        }
    }

    with patch.dict(current_app.config, config):
        field = MockField(u'THIS-ORCID-DOES-NOT-EXIST')

        assert ORCIDValidator(None, field) is None