<s> from test . unit_tests . providers import common <EOL> from test . unit_tests . providers . common import ProviderTestCase <EOL> from totalimpact . providers . provider import Provider , ProviderContentMalformedError <EOL> from totalimpact . providers import provider <EOL> from test . utils import http <EOL> import os <EOL> import collections <EOL> from nose . tools import assert_equals , assert_items_equal , raises <EOL> datadir = os . path . join ( os . path . split ( __file__ ) [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_METRICS_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_ALIASES_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_MEMBER_ITEMS_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_BIBLIO_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> class TestPublons ( ProviderTestCase ) : <EOL> provider_name = "<STR_LIT>" <EOL> testitem_members = "<STR_LIT>" <EOL> testitem_metrics = ( "<STR_LIT:url>" , "<STR_LIT>" ) <EOL> testitem_aliases = ( "<STR_LIT:url>" , "<STR_LIT>" ) <EOL> testitem_biblio = ( "<STR_LIT:url>" , "<STR_LIT>" ) <EOL> def setUp ( self ) : <EOL> ProviderTestCase . setUp ( self ) <EOL> def test_is_relevant_alias ( self ) : <EOL> assert_equals ( self . provider . is_relevant_alias ( self . testitem_aliases ) , True ) <EOL> assert_equals ( self . provider . is_relevant_alias ( ( "<STR_LIT>" , "<STR_LIT>" ) ) , False ) <EOL> def test_extract_metrics_success ( self ) : <EOL> f = open ( SAMPLE_EXTRACT_METRICS_PAGE , "<STR_LIT:r>" ) <EOL> metrics_dict = self . provider . _extract_metrics ( f . read ( ) ) <EOL> print metrics_dict <EOL> assert_equals ( metrics_dict [ "<STR_LIT>" ] , <NUM_LIT> ) <EOL> def test_extract_members_success ( self ) : <EOL> f = open ( SAMPLE_EXTRACT_MEMBER_ITEMS_PAGE , "<STR_LIT:r>" ) <EOL> members = self . provider . _extract_members ( f . read ( ) , self . testitem_members ) <EOL> expected = [ ( '<STR_LIT:url>' , '<STR_LIT>' ) ] <EOL> assert_equals ( expected , members ) <EOL> def test_provenance_url ( self ) : <EOL> provenance_url = self . provider . provenance_url ( "<STR_LIT>" , [ self . testitem_aliases ] ) <EOL> assert_equals ( provenance_url , "<STR_LIT>" ) <EOL> @ http <EOL> def test_metrics ( self ) : <EOL> metrics_dict = self . provider . metrics ( [ self . testitem_metrics ] ) <EOL> print metrics_dict <EOL> expected = { '<STR_LIT>' : ( <NUM_LIT> , '<STR_LIT>' ) } <EOL> for key in expected : <EOL> assert metrics_dict [ key ] [ <NUM_LIT:0> ] >= expected [ key ] [ <NUM_LIT:0> ] , [ key , metrics_dict [ key ] , expected [ key ] ] <EOL> assert metrics_dict [ key ] [ <NUM_LIT:1> ] == expected [ key ] [ <NUM_LIT:1> ] , [ key , metrics_dict [ key ] , expected [ key ] ] <EOL> @ http <EOL> def test_aliases ( self ) : <EOL> aliases = self . provider . aliases ( [ self . testitem_aliases ] ) <EOL> print aliases <EOL> expected = [ ( '<STR_LIT>' , u'<STR_LIT>' ) ] <EOL> assert_equals ( expected , aliases ) <EOL> @ http <EOL> def test_biblio ( self ) : <EOL> biblio_dict = self . provider . biblio ( [ self . testitem_biblio ] ) <EOL> print biblio_dict <EOL> expected = { '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:title>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' } <EOL> assert_items_equal ( biblio_dict . keys ( ) , expected . keys ( ) ) <EOL> for key in [ "<STR_LIT>" , "<STR_LIT:title>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> assert_equals ( biblio_dict [ key ] , expected [ key ] ) <EOL> @ http <EOL> def test_members ( self ) : <EOL> members = self . provider . member_items ( self . testitem_members ) <EOL> print members <EOL> expected = [ ( '<STR_LIT:url>' , '<STR_LIT>' ) ] <EOL> for member in expected : <EOL> assert ( member in members ) </s>
