Beispiel #1
0
def retrieve_vocab():
    """Get the vocabulary data for the field.

    Retrieves and returns the vocabulary. Upon failure, returns None.
    """
    url = VOCABULARIES_URL.replace('all', 'all-verbose')
    try:
        return eval(urllib2.urlopen(url).read())
    except:
        return None
def test_get_vocabularies_multiple_attempts_succeeds(mock_urlopen, capsys):
    """Test vocabularies are fetched when not in cache."""
    output = 'Exception caught while trying to retrieve vocabs: '
    vocab_url = VOCABULARIES_URL.replace('all', 'all-verbose')
    us.VOCAB_CACHE = {}
    vocabularies = us.get_vocabularies()
    assert mock_urlopen.call_count == 2
    assert output in capsys.readouterr().out
    assert vocabularies == VOCAB
    assert us.VOCAB_CACHE == {vocab_url: VOCAB}
Beispiel #3
0
 def get_vocabularies(self):
     """Get the vocabularies to pull the qualifiers from."""
     # Timeout in seconds.
     timeout = 15
     socket.setdefaulttimeout(timeout)
     # Create the ordered vocabulary URL.
     vocab_url = VOCABULARIES_URL.replace('all', 'all-verbose')
     # Request the vocabularies dictionary.
     try:
         vocab_dict = eval(urllib2.urlopen(vocab_url).read())
     except:
         raise UNTLStructureException('Could not retrieve the vocabularies')
     return vocab_dict