<s> from __future__ import absolute_import <EOL> import os <EOL> import sys <EOL> import ConfigParser <EOL> from datetime import datetime <EOL> from . . client import AggcatClient <EOL> from . . exceptions import HTTPError <EOL> from nose . tools import raises , nottest <EOL> class TestClient ( object ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setup_class ( self ) : <EOL> self . institution_id = <NUM_LIT> <EOL> self . base_url = '<STR_LIT>' <EOL> self . config_file = os . path . join ( os . environ [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> if not os . path . isfile ( self . config_file ) : <EOL> sys . exit ( '<STR_LIT>' ) <EOL> client_config = ConfigParser . ConfigParser ( ) <EOL> client_config . readfp ( open ( self . config_file ) ) <EOL> self . client_args = ( <EOL> client_config . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> client_config . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> client_config . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> client_config . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> client_config . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> self . ac = AggcatClient ( * self . client_args , objectify = True ) <EOL> @ classmethod <EOL> def teardown_class ( self ) : <EOL> self . ac . delete_customer ( ) <EOL> @ nottest <EOL> def get_data ( self , file_name ) : <EOL> with open ( '<STR_LIT>' % file_name , '<STR_LIT:r>' ) as f : <EOL> return f . read ( ) <EOL> def test_client_setup ( self ) : <EOL> """<STR_LIT>""" <EOL> consumer_key , consumer_secret , saml_identity_provider_id , customer_id , private_key = self . client_args <EOL> assert self . ac . consumer_key == consumer_key <EOL> assert self . ac . consumer_secret == consumer_secret <EOL> assert self . ac . saml_identity_provider_id == saml_identity_provider_id <EOL> assert self . ac . customer_id == customer_id <EOL> assert self . ac . private_key == private_key <EOL> @ nottest <EOL> def _float_test ( self , string ) : <EOL> try : <EOL> float ( string ) <EOL> return True <EOL> except ValueError : <EOL> return False <EOL> @ raises ( HTTPError ) <EOL> def test_bad_account ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> @ raises ( HTTPError ) <EOL> def test_bad2_account ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> @ raises ( HTTPError ) <EOL> def test_request_error_account ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> def test_two_factor_q_account ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> assert r . content . to_xml ( ) == self . get_data ( '<STR_LIT>' ) <EOL> def test_two_factor2_q_account ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> assert r . content . to_xml ( ) == self . get_data ( '<STR_LIT>' ) <EOL> def test_two_factor_choice_account ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> assert r . content . to_xml ( ) == self . get_data ( '<STR_LIT>' ) <EOL> def test_two_factor_image_account ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> assert r . content . to_xml ( ) == self . get_data ( '<STR_LIT>' ) <EOL> def test_two_factor_dynamic_image_account ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> assert r . content . to_xml ( ) == self . get_data ( '<STR_LIT>' ) <EOL> def test_get_credential_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> return_value = eval ( self . get_data ( '<STR_LIT>' ) ) <EOL> r = self . ac . get_credential_fields ( self . institution_id ) <EOL> assert r == return_value <EOL> assert r [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] == return_value [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] <EOL> assert r [ <NUM_LIT:1> ] [ '<STR_LIT>' ] == return_value [ <NUM_LIT:1> ] [ '<STR_LIT>' ] <EOL> assert r [ <NUM_LIT:0> ] [ '<STR_LIT:description>' ] == return_value [ <NUM_LIT:0> ] [ '<STR_LIT:description>' ] <EOL> assert r [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] == return_value [ <NUM_LIT:1> ] [ '<STR_LIT:name>' ] <EOL> def test_get_institution_details ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . get_institution_details ( self . institution_id ) <EOL> assert int ( r . content . institution_id ) == self . institution_id <EOL> assert r . content . home_url == '<STR_LIT>' <EOL> assert r . content . email_address == '<STR_LIT>' <EOL> def test_url_building ( self ) : <EOL> """<STR_LIT>""" <EOL> assert self . ac . _build_url ( '<STR_LIT>' ) == '<STR_LIT>' % ( self . base_url , '<STR_LIT>' ) <EOL> @ raises ( ValueError ) <EOL> def test_y0_credentials_validation_failure ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . _validate_credentials ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> @ raises ( HTTPError ) <EOL> def test_y01_get_account ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . get_account ( '<STR_LIT>' ) <EOL> @ raises ( HTTPError ) <EOL> def test_y02_get_account_transactions ( self ) : <EOL> """<STR_LIT>""" <EOL> start_date = datetime . now ( ) . strftime ( '<STR_LIT>' ) <EOL> end_date = datetime . now ( ) . strftime ( '<STR_LIT>' ) <EOL> self . ac . get_account_transactions ( '<STR_LIT>' , start_date , end_date ) <EOL> def test_z01_discover_and_add_accounts ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . discover_and_add_accounts ( self . institution_id , ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> for account in r . content : <EOL> assert int ( account . institution_id ) == self . institution_id <EOL> def test_z02_get_customer_accounts ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . ac . get_customer_accounts ( ) <EOL> for account in r . content : <EOL> assert int ( account . institution_id ) == self . institution_id <EOL> def test_z03_get_account ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> r = self . ac . get_account ( accounts . content [ <NUM_LIT:0> ] . account_id ) <EOL> assert r . content . account_id == accounts . content [ <NUM_LIT:0> ] . account_id <EOL> def test_z04_get_account_transactions ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> start_date = datetime . now ( ) . strftime ( '<STR_LIT>' ) <EOL> end_date = datetime . now ( ) . strftime ( '<STR_LIT>' ) <EOL> r = self . ac . get_account_transactions ( <EOL> accounts . content [ <NUM_LIT:0> ] . account_id , <EOL> start_date , <EOL> end_date <EOL> ) <EOL> for t in r . content : <EOL> assert self . _float_test ( t . amount ) == True <EOL> @ raises ( HTTPError ) <EOL> def test_z05_get_account_transactions_bad_date ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> self . ac . get_account_transactions ( <EOL> accounts . content [ <NUM_LIT:0> ] . account_id , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> @ raises ( HTTPError ) <EOL> def test_z06_delete_account_bad_id ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . delete_account ( '<STR_LIT>' ) <EOL> def test_z07_delete_account ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> r = self . ac . delete_account ( accounts . content [ <NUM_LIT:0> ] . account_id ) <EOL> assert r . content == '<STR_LIT>' <EOL> assert r . status_code == <NUM_LIT:200> <EOL> def test_z08_get_login_accounts ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> r = self . ac . get_login_accounts ( accounts . content [ <NUM_LIT:0> ] . institution_login_id ) <EOL> for account in r . content : <EOL> assert int ( account . institution_id ) == self . institution_id <EOL> def test_z09_get_investement_positions ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> r = self . ac . get_investment_positions ( accounts . content [ <NUM_LIT:0> ] . account_id ) <EOL> assert r . content . to_xml ( ) == self . get_data ( '<STR_LIT>' ) <EOL> @ raises ( ValueError ) <EOL> def test_z10_update_account_type_invalid_params ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . update_account_type ( <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ raises ( HTTPError ) <EOL> def test_z11_update_account_type ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> self . ac . update_account_type ( accounts . content [ <NUM_LIT:0> ] . account_id , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_z12_update_institution_login ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> r = self . ac . update_institution_login ( <EOL> self . institution_id , <EOL> accounts . content [ <NUM_LIT:0> ] . institution_login_id , <EOL> ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> assert r . content == '<STR_LIT>' <EOL> assert r . status_code == <NUM_LIT:200> <EOL> @ raises ( HTTPError ) <EOL> def test_z13_update_institution_login ( self ) : <EOL> """<STR_LIT>""" <EOL> accounts = self . ac . get_customer_accounts ( ) <EOL> self . ac . update_institution_login ( <EOL> self . institution_id , <EOL> accounts . content [ <NUM_LIT:0> ] . institution_login_id , <EOL> ** { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_z14_list_files ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . list_files ( ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_z15_get_file_data ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . get_file_data ( '<STR_LIT>' ) <EOL> @ raises ( NotImplementedError ) <EOL> def test_z16_delete_file ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ac . delete_file ( '<STR_LIT>' ) </s>
