Skip to content

Commit a49f721

Browse files
committed
folder tests; test for plotly exception
1 parent 6fc1d29 commit a49f721

File tree

3 files changed

+71
-22
lines changed

3 files changed

+71
-22
lines changed

plotly/tests/test_core/test_file/test_file.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import plotly.plotly as py
1616
import plotly.tools as tls
17-
17+
from plotly.exceptions import PlotlyRequestError
1818

1919
def _random_filename():
2020
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
@@ -29,20 +29,22 @@ def init():
2929

3030
def test_create_folder():
3131
init()
32-
py.file_ops.mkdir(_random_filename())
32+
py.file_ops.mkdirs(_random_filename())
3333

3434

3535
def test_create_nested_folders():
3636
init()
3737
first_folder = _random_filename()
38-
second_folder = '{}/{}'.format(first_folder, _random_filename())
39-
py.file_ops.mkdir(first_folder)
40-
py.file_ops.mkdir(second_folder)
38+
nested_folder = '{}/{}'.format(first_folder, _random_filename())
39+
py.file_ops.mkdirs(nested_folder)
4140

4241

43-
@raises(requests.exceptions.HTTPError) # TODO: 409, not just any 4xx
4442
def test_duplicate_folders():
4543
init()
4644
first_folder = _random_filename()
47-
py.file_ops.mkdir(first_folder)
48-
py.file_ops.mkdir(first_folder)
45+
py.file_ops.mkdirs(first_folder)
46+
try:
47+
py.file_ops.mkdirs(first_folder)
48+
except PlotlyRequestError as e:
49+
if e.status_code != 409:
50+
raise e

plotly/tests/test_core/test_grid/test_grid.py

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,64 @@
1010

1111
import random
1212
import string
13-
import requests
13+
from nose.plugins.attrib import attr
1414

1515
from plotly.graph_objs import Scatter
1616
import plotly.plotly as py
1717
import plotly.tools as tls
1818
from plotly.grid_objs import Column, Grid
19-
from plotly.exceptions import InputError
20-
from nose.plugins.attrib import attr
19+
from plotly.exceptions import InputError, PlotlyRequestError
2120

22-
def upload_and_return_grid():
23-
tls.set_config_file('https://local.plot.ly')
24-
py.sign_in('GridTest', 'fp4rldzhv0')
2521

22+
def _random_filename():
23+
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
24+
unique_filename = 'Valid Grid '+''.join(random_chars)
25+
return unique_filename
26+
27+
28+
def _get_grid():
2629
c1 = Column('first column', [1, 2, 3, 4])
2730
c2 = Column('second column', ['a', 'b', 'c', 'd'])
2831
g = Grid([c1, c2])
32+
return g
33+
34+
35+
def _init():
36+
tls.set_config_file('https://local.plot.ly')
37+
py.sign_in('GridTest', 'fp4rldzhv0')
38+
39+
40+
def upload_and_return_grid():
41+
_init()
42+
g = _get_grid()
43+
unique_filename = _random_filename()
2944

30-
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
31-
unique_filename = 'Valid Grid '+''.join(random_chars)
3245
py.grid_ops.upload(g, unique_filename, auto_open=False)
3346
return g
3447

48+
3549
## Nominal usage
3650
def test_grid_upload():
3751
upload_and_return_grid()
3852

53+
54+
def test_grid_upload_in_new_folder():
55+
_init()
56+
g = _get_grid()
57+
path = 'new folder: {}/grid in folder {}'.format(_random_filename(), _random_filename())
58+
py.grid_ops.upload(g, path, auto_open=False)
59+
60+
61+
def test_grid_upload_in_existing_folder():
62+
_init()
63+
g = _get_grid()
64+
folder = _random_filename()
65+
filename = _random_filename()
66+
py.file_ops.mkdirs(folder)
67+
path = 'existing folder: {}/grid in folder {}'.format(folder, filename)
68+
py.grid_ops.upload(g, path, auto_open=False)
69+
70+
3971
def test_column_append():
4072
g = upload_and_return_grid()
4173
new_col = Column('new col', [1, 5, 3])
@@ -104,15 +136,15 @@ def test_scatter_from_non_uploaded_grid():
104136
Scatter(xsrc=g[0], ysrc=g[1])
105137

106138

107-
@raises(requests.exceptions.HTTPError)
139+
@raises(PlotlyRequestError)
108140
def test_column_append_of_non_uploaded_grid():
109141
c1 = Column('first column', [1, 2, 3, 4])
110142
c2 = Column('second column', ['a', 'b', 'c', 'd'])
111143
g = Grid([c1])
112144
py.grid_ops.append_columns([c2], grid=g)
113145

114146

115-
@raises(requests.exceptions.HTTPError)
147+
@raises(PlotlyRequestError)
116148
def test_row_append_of_non_uploaded_grid():
117149
c1 = Column('first column', [1, 2, 3, 4])
118150
rows = [[1], [2]]
@@ -136,13 +168,27 @@ def test_duplicate_columns():
136168
Grid([c1, c2])
137169

138170

171+
# Test delete
172+
def test_delete_grid():
173+
_init()
174+
g = _get_grid()
175+
fn = _random_filename()
176+
py.grid_ops.upload(g, fn, auto_open=False)
177+
py.grid_ops.delete(g)
178+
py.grid_ops.upload(g, fn, auto_open=False)
179+
180+
139181
## Plotly failures
140-
@raises(requests.exceptions.HTTPError)
141182
def test_duplicate_filenames():
142183
c1 = Column('first column', [1, 2, 3, 4])
143184
g = Grid([c1])
144185

145186
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
146187
unique_filename = 'Valid Grid '+''.join(random_chars)
147188
py.grid_ops.upload(g, unique_filename, auto_open=False)
148-
py.grid_ops.upload(g, unique_filename, auto_open=False)
189+
try:
190+
py.grid_ops.upload(g, unique_filename, auto_open=False)
191+
except PlotlyRequestError as e:
192+
if e.status_code != 409:
193+
raise e
194+

plotly/tests/test_core/test_meta/test_meta.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import plotly.plotly as py
1616
import plotly.tools as tls
1717
from plotly.grid_objs import Column, Grid
18-
from nose.plugins.attrib import attr
18+
from plotly.exceptions import PlotlyRequestError
19+
1920

2021
def init():
2122
tls.set_config_file('https://local.plot.ly')
@@ -57,7 +58,7 @@ def test_upload_meta_with_grid():
5758
auto_open=False)
5859

5960

60-
@raises(requests.exceptions.HTTPError)
61+
@raises(PlotlyRequestError)
6162
def test_metadata_to_nonexistent_grid():
6263
init()
6364

0 commit comments

Comments
 (0)