def test_convert_type(self, field_type, value, expected): with patch('bqlib.is_str_or_unicode', return_value=True): if isclass(expected) and issubclass(expected, Exception): with pytest.raises(expected): BQHelper.convert_type(field_type, value) else: assert BQHelper.convert_type(field_type, value) == expected
def test_retrieve_discovery_document(self): class _DiscoveryHTTPResponse(object): def read(self): return Mock() class _DiscoveryDocumentStorage(object): def __init__(self): self._storage = {} def get(self, key): self._storage.get(key) def set(self, key, value, *args, **kwargs): self._storage[key] = value with nested( patch('urllib2.urlopen', return_value=_DiscoveryHTTPResponse()), patch('bqlib.BQHelper.is_gae_runtime', return_value=False)): storage = _DiscoveryDocumentStorage() # retrieve from HTTP request without storage assert BQHelper.retrieve_discovery_document() is not None # retrieve from HTTP request with storage assert BQHelper.retrieve_discovery_document(storage) is not None # retrieve from storage assert BQHelper.retrieve_discovery_document(storage) is not None
def test_retrieve_discovery_document(self): class _DiscoveryHTTPResponse(object): def read(self): return Mock() class _DiscoveryDocumentStorage(object): def __init__(self): self._storage = {} def get(self, key): self._storage.get(key) def set(self, key, value, *args, **kwargs): self._storage[key] = value with nested( patch('urllib2.urlopen', return_value=_DiscoveryHTTPResponse()), patch('bqlib.BQHelper.is_gae_runtime', return_value=False) ): storage = _DiscoveryDocumentStorage() # retrieve from HTTP request without storage assert BQHelper.retrieve_discovery_document() is not None # retrieve from HTTP request with storage assert BQHelper.retrieve_discovery_document(storage) is not None # retrieve from storage assert BQHelper.retrieve_discovery_document(storage) is not None
def test_build_fully_qualified_table_name(self, project_id, dataset_id, table_id, expected): assert BQHelper.build_fully_qualified_table_name( project_id, dataset_id, table_id) == expected
def test_is_gae_runtime(self, runtime, expected): if runtime: os.environ['SERVER_SOFTWARE'] = runtime assert BQHelper.is_gae_runtime() == expected