10
10
11
11
import random
12
12
import string
13
- import requests
13
+ from nose . plugins . attrib import attr
14
14
15
15
from plotly .graph_objs import Scatter
16
16
import plotly .plotly as py
17
17
import plotly .tools as tls
18
18
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
21
20
22
- def upload_and_return_grid ():
23
- tls .set_config_file ('https://local.plot.ly' )
24
- py .sign_in ('GridTest' , 'fp4rldzhv0' )
25
21
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 ():
26
29
c1 = Column ('first column' , [1 , 2 , 3 , 4 ])
27
30
c2 = Column ('second column' , ['a' , 'b' , 'c' , 'd' ])
28
31
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 ()
29
44
30
- random_chars = [random .choice (string .ascii_uppercase ) for _ in range (5 )]
31
- unique_filename = 'Valid Grid ' + '' .join (random_chars )
32
45
py .grid_ops .upload (g , unique_filename , auto_open = False )
33
46
return g
34
47
48
+
35
49
## Nominal usage
36
50
def test_grid_upload ():
37
51
upload_and_return_grid ()
38
52
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
+
39
71
def test_column_append ():
40
72
g = upload_and_return_grid ()
41
73
new_col = Column ('new col' , [1 , 5 , 3 ])
@@ -104,15 +136,15 @@ def test_scatter_from_non_uploaded_grid():
104
136
Scatter (xsrc = g [0 ], ysrc = g [1 ])
105
137
106
138
107
- @raises (requests . exceptions . HTTPError )
139
+ @raises (PlotlyRequestError )
108
140
def test_column_append_of_non_uploaded_grid ():
109
141
c1 = Column ('first column' , [1 , 2 , 3 , 4 ])
110
142
c2 = Column ('second column' , ['a' , 'b' , 'c' , 'd' ])
111
143
g = Grid ([c1 ])
112
144
py .grid_ops .append_columns ([c2 ], grid = g )
113
145
114
146
115
- @raises (requests . exceptions . HTTPError )
147
+ @raises (PlotlyRequestError )
116
148
def test_row_append_of_non_uploaded_grid ():
117
149
c1 = Column ('first column' , [1 , 2 , 3 , 4 ])
118
150
rows = [[1 ], [2 ]]
@@ -136,13 +168,27 @@ def test_duplicate_columns():
136
168
Grid ([c1 , c2 ])
137
169
138
170
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
+
139
181
## Plotly failures
140
- @raises (requests .exceptions .HTTPError )
141
182
def test_duplicate_filenames ():
142
183
c1 = Column ('first column' , [1 , 2 , 3 , 4 ])
143
184
g = Grid ([c1 ])
144
185
145
186
random_chars = [random .choice (string .ascii_uppercase ) for _ in range (5 )]
146
187
unique_filename = 'Valid Grid ' + '' .join (random_chars )
147
188
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
+
0 commit comments