<s> from totalimpact . providers import provider <EOL> from totalimpact . providers . provider import Provider , ProviderFactory <EOL> from totalimpactwebapp import app , db <EOL> from nose . tools import assert_equals , nottest <EOL> from xml . dom import minidom <EOL> from test . utils import setup_postgres_for_unittests , teardown_postgres_for_unittests <EOL> import simplejson , BeautifulSoup <EOL> import os <EOL> from sqlalchemy . sql import text <EOL> sampledir = os . path . join ( os . path . split ( __file__ ) [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> class Test_Provider ( ) : <EOL> TEST_PROVIDER_CONFIG = [ <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : <NUM_LIT:1> } ) , <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : <NUM_LIT:3> } ) , <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : <NUM_LIT:3> } ) , <EOL> ] <EOL> TEST_JSON = """<STR_LIT>""" <EOL> TEST_XML = open ( os . path . join ( sampledir , "<STR_LIT>" , "<STR_LIT>" ) ) . read ( ) <EOL> def setUp ( self ) : <EOL> self . db = setup_postgres_for_unittests ( db , app ) <EOL> def tearDown ( self ) : <EOL> teardown_postgres_for_unittests ( self . db ) <EOL> def test_get_provider ( self ) : <EOL> provider = ProviderFactory . get_provider ( "<STR_LIT>" ) <EOL> assert_equals ( provider . __class__ . __name__ , "<STR_LIT>" ) <EOL> def test_get_providers ( self ) : <EOL> providers = ProviderFactory . get_providers ( self . TEST_PROVIDER_CONFIG ) <EOL> provider_names = [ provider . __class__ . __name__ for provider in providers ] <EOL> assert_equals ( set ( provider_names ) , set ( [ '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ] ) ) <EOL> def test_get_providers_filters_by_metrics ( self ) : <EOL> providers = ProviderFactory . get_providers ( self . TEST_PROVIDER_CONFIG , "<STR_LIT>" ) <EOL> provider_names = [ provider . __class__ . __name__ for provider in providers ] <EOL> assert_equals ( set ( provider_names ) , set ( [ '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ] ) ) <EOL> def test_get_providers_filters_by_biblio ( self ) : <EOL> providers = ProviderFactory . get_providers ( self . TEST_PROVIDER_CONFIG , "<STR_LIT>" ) <EOL> provider_names = [ provider . __class__ . __name__ for provider in providers ] <EOL> assert_equals ( set ( provider_names ) , set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> def test_get_providers_filters_by_aliases ( self ) : <EOL> providers = ProviderFactory . get_providers ( self . TEST_PROVIDER_CONFIG , "<STR_LIT>" ) <EOL> provider_names = [ provider . __class__ . __name__ for provider in providers ] <EOL> assert_equals ( set ( provider_names ) , set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> def test_lookup_json ( self ) : <EOL> page = self . TEST_JSON <EOL> data = simplejson . loads ( page ) <EOL> response = provider . _lookup_json ( data , [ '<STR_LIT>' , '<STR_LIT:name>' ] ) <EOL> assert_equals ( response , u'<STR_LIT>' ) <EOL> def test_extract_json ( self ) : <EOL> page = self . TEST_JSON <EOL> dict_of_keylists = { <EOL> '<STR_LIT:title>' : [ '<STR_LIT>' , '<STR_LIT:name>' ] , <EOL> '<STR_LIT:description>' : [ '<STR_LIT>' , '<STR_LIT:description>' ] } <EOL> response = provider . _extract_from_json ( page , dict_of_keylists ) <EOL> assert_equals ( response , { '<STR_LIT:description>' : u'<STR_LIT>' , '<STR_LIT:title>' : u'<STR_LIT>' } ) <EOL> def test_lookup_xml_from_dom ( self ) : <EOL> page = self . TEST_XML <EOL> doc = minidom . parseString ( page . strip ( ) ) <EOL> response = provider . _lookup_xml_from_dom ( doc , [ '<STR_LIT>' ] ) <EOL> assert_equals ( response , <NUM_LIT> ) <EOL> def test_lookup_xml_from_soup ( self ) : <EOL> page = self . TEST_XML <EOL> doc = BeautifulSoup . BeautifulStoneSoup ( page ) <EOL> response = provider . _lookup_xml_from_soup ( doc , [ '<STR_LIT>' ] ) <EOL> assert_equals ( response , <NUM_LIT> ) <EOL> def test_extract_xml ( self ) : <EOL> page = self . TEST_XML <EOL> dict_of_keylists = { <EOL> '<STR_LIT:count>' : [ '<STR_LIT>' ] } <EOL> response = provider . _extract_from_xml ( page , dict_of_keylists ) <EOL> assert_equals ( response , { '<STR_LIT:count>' : <NUM_LIT> } ) <EOL> def test_doi_from_url_string ( self ) : <EOL> test_url = "<STR_LIT>" <EOL> expected = "<STR_LIT>" <EOL> response = provider . doi_from_url_string ( test_url ) <EOL> assert_equals ( response , expected ) <EOL> def test_is_issn_in_doaj_false ( self ) : <EOL> response = provider . is_issn_in_doaj ( "<STR_LIT>" ) <EOL> assert_equals ( response , False ) <EOL> def test_is_issn_in_doaj_true ( self ) : <EOL> zookeys_issn = "<STR_LIT>" <EOL> response = provider . is_issn_in_doaj ( zookeys_issn ) <EOL> assert_equals ( response , True ) <EOL> def test_import_products ( self ) : <EOL> response = provider . import_products ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] } ) <EOL> expected = [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT:url>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> assert_equals ( response , expected ) <EOL> def test_import_products_bad_providername ( self ) : <EOL> response = provider . import_products ( "<STR_LIT>" , { } ) <EOL> expected = [ ] <EOL> assert_equals ( response , expected ) <EOL> class TestProviderFactory ( ) : <EOL> TEST_PROVIDER_CONFIG = [ <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : <NUM_LIT:1> } ) , <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : <NUM_LIT:3> } ) , <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : <NUM_LIT:3> } ) , <EOL> ] <EOL> def test_get_all_static_meta ( self ) : <EOL> sm = ProviderFactory . get_all_static_meta ( self . TEST_PROVIDER_CONFIG ) <EOL> expected = '<STR_LIT>' <EOL> assert_equals ( sm [ "<STR_LIT>" ] [ "<STR_LIT:description>" ] , expected ) <EOL> def test_get_all_metric_names ( self ) : <EOL> response = ProviderFactory . get_all_metric_names ( self . TEST_PROVIDER_CONFIG ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> assert_equals ( response , expected ) <EOL> def test_get_all_metadata ( self ) : <EOL> md = ProviderFactory . get_all_metadata ( self . TEST_PROVIDER_CONFIG ) <EOL> print md [ "<STR_LIT>" ] <EOL> assert_equals ( md [ "<STR_LIT>" ] [ '<STR_LIT:url>' ] , '<STR_LIT>' ) </s>
