<s> import re <EOL> import unittest2 <EOL> from test . helpers . httpretty_extension import httpretty <EOL> import json <EOL> import datetime <EOL> from quandl . model . dataset import Dataset <EOL> from quandl . model . database import Database <EOL> from mock import patch , call <EOL> from test . factories . dataset import DatasetFactory <EOL> from test . factories . meta import MetaFactory <EOL> class GetDatasetTest ( unittest2 . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> httpretty . enable ( ) <EOL> dataset = { '<STR_LIT>' : DatasetFactory . build ( <EOL> database_code = '<STR_LIT>' , dataset_code = '<STR_LIT>' ) } <EOL> httpretty . register_uri ( httpretty . GET , <EOL> re . compile ( <EOL> '<STR_LIT>' ) , <EOL> body = json . dumps ( dataset ) ) <EOL> dataset_code = Dataset . get_code_from_meta ( dataset [ '<STR_LIT>' ] ) <EOL> cls . dataset_instance = Dataset ( dataset_code , dataset [ '<STR_LIT>' ] ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> httpretty . disable ( ) <EOL> httpretty . reset ( ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_dataset_calls_connection ( self , mock ) : <EOL> d = Dataset ( '<STR_LIT>' ) <EOL> d . data_fields ( ) <EOL> expected = call ( '<STR_LIT>' , '<STR_LIT>' , params = { } ) <EOL> self . assertEqual ( mock . call_args , expected ) <EOL> def test_dataset_returns_dataset_object ( self ) : <EOL> dataset = Dataset ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( dataset , Dataset ) <EOL> self . assertEqual ( dataset . dataset_code , '<STR_LIT>' ) <EOL> def test_dataset_attributes_are_datetime_objects ( self ) : <EOL> dataset = Dataset ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( dataset . refreshed_at , datetime . datetime ) <EOL> self . assertIsInstance ( dataset . newest_available_date , datetime . date ) <EOL> def test_dataset_column_names_match_expected ( self ) : <EOL> dataset = Dataset ( '<STR_LIT>' ) <EOL> self . assertItemsEqual ( <EOL> dataset . column_names , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_dataset_database_gives_instance_of_database ( self ) : <EOL> database = self . dataset_instance . database ( ) <EOL> self . assertIsInstance ( database , Database ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_dataset_data_calls_data_all ( self , mock ) : <EOL> self . dataset_instance . data ( <EOL> params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> expected = call ( params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( mock . call_args , expected ) <EOL> class ListDatasetsTest ( unittest2 . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> httpretty . enable ( ) <EOL> datasets = { '<STR_LIT>' : DatasetFactory . build_batch ( <NUM_LIT:3> ) } <EOL> meta = { '<STR_LIT>' : MetaFactory . build ( current_page = <NUM_LIT:1> , total_pages = <NUM_LIT:1> ) } <EOL> datasets . update ( meta ) <EOL> httpretty . register_uri ( httpretty . GET , <EOL> re . compile ( <EOL> '<STR_LIT>' ) , <EOL> body = json . dumps ( datasets ) ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> httpretty . disable ( ) <EOL> httpretty . reset ( ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_datasets_calls_connection ( self , mock ) : <EOL> Dataset . all ( ) <EOL> expected = call ( '<STR_LIT>' , '<STR_LIT>' , params = { } ) <EOL> self . assertEqual ( mock . call_args , expected ) <EOL> def test_datasets_return_dataset_objects ( self ) : <EOL> results = Dataset . all ( ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:3> ) <EOL> for result in results : <EOL> self . assertIsInstance ( result , Dataset ) <EOL> def test_datasets_has_more_results ( self ) : <EOL> results = Dataset . all ( ) <EOL> self . assertFalse ( results . has_more_results ( ) ) <EOL> def test_values_exist ( self ) : <EOL> results = Dataset . all ( ) <EOL> self . assertIsInstance ( results . values , list ) <EOL> self . assertIsInstance ( results . values [ <NUM_LIT:0> ] , Dataset ) <EOL> def test_meta_attributes_can_be_accessed ( self ) : <EOL> results = Dataset . all ( ) <EOL> self . assertEqual ( results . meta [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( results . current_page , <NUM_LIT:1> ) <EOL> def test_to_list_returns_list ( self ) : <EOL> results = Dataset . all ( ) <EOL> data = results . to_list ( ) <EOL> self . assertIsInstance ( data , list ) <EOL> self . assertIsInstance ( data [ <NUM_LIT:0> ] , list ) </s>
