Skip to content

Commit

Permalink
Merge fa3a097 into ea745e6
Browse files Browse the repository at this point in the history
  • Loading branch information
michellemho committed Sep 7, 2017
2 parents ea745e6 + fa3a097 commit b472957
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cartoframes/context.py
Expand Up @@ -203,11 +203,12 @@ def delete(self, table_name):
None
"""
try:
self.auth_client.send(
resp = self.auth_client.send(
'api/v1/viz/{table_name}'.format(table_name=table_name),
http_method='DELETE'
)
except CartoException as err:
resp.raise_for_status()
except requests.exceptions.HTTPError as err:
warn('Failed to delete the following table from CARTO '
'account: `{table_name}`. ({err})'.format(
table_name=table_name,
Expand Down
21 changes: 20 additions & 1 deletion test/test_context.py
Expand Up @@ -45,6 +45,8 @@ def setUp(self):
ver=sys.version[0:3].replace('.', '_')))
self.test_query_table = 'cartoframes_test_query_table_{ver}'.format(
ver=sys.version[0:3].replace('.', '_'))
self.test_delete_table = 'cartoframes_test_delete_table_{ver}'.format(
ver=sys.version[0:3].replace('.', '_'))

def tearDown(self):
"""restore to original state"""
Expand Down Expand Up @@ -186,6 +188,23 @@ def test_cartocontext_table_exists(self):
with self.assertRaises(NameError):
cc._table_exists(self.test_read_table)

def test_cartocontext_delete(self):
"""CartoContext.delete"""
cc = cartoframes.CartoContext(base_url=self.baseurl,
api_key=self.apikey)
data = {'col1': [1,2,3],
'col2': ['a','b','c']}
schema = {'col1': int,
'col2': 'object'}
df = pd.DataFrame(data).astype(schema)

cc.write(df, self.test_delete_table)
resp = cc.delete(self.test_delete_table)
self.assertIsNone(resp)

#try to delete a table that does not exists
with self.assertWarns(UserWarning):
cc.delete('non_existent_table')

def test_cartocontext_send_dataframe(self):
"""CartoContext._send_dataframe"""
Expand Down Expand Up @@ -292,7 +311,7 @@ def test_cartocontext_map(self):
self.assertIsInstance(labels_front, IPython.core.display.HTML)

# test with one Layer
one_layer = cc.map(layers=Layer('tweets_obama'))
one_layer = cc.map(layers=Layer('tweets_obama'))
self.assertIsInstance(one_layer, IPython.core.display.HTML)

# test with two Layers
Expand Down

0 comments on commit b472957

Please sign in to comment.