12
12
13
13
from unittest import TestCase
14
14
from nose .tools import raises
15
- from unittest import skip
16
15
17
16
import plotly .tools as tls
18
17
from plotly .plotly import plotly as py
@@ -66,70 +65,47 @@ def test_plot_invalid_args_2():
66
65
67
66
class TestPlot (TestCase ):
68
67
68
+ def setUp (self ):
69
+ self .simple_figure = {'data' : [{'x' : [1 , 2 , 3 ], 'y' : [2 , 1 , 2 ]}]}
70
+ super (TestPlot , self ).setUp ()
71
+
69
72
def test_plot_empty_data (self ):
70
73
py .sign_in ('PlotlyImageTest' , '786r5mecv0' )
71
74
self .assertRaises (PlotlyEmptyDataError , py .plot , [],
72
75
filename = 'plot_invalid' )
73
76
74
- def test_plot_sharing_argument (self ):
77
+ def test_plot_sharing_invalid_argument (self ):
75
78
76
79
# Raise an error if sharing argument is incorrect
77
80
# correct arguments {'public, 'private', 'secret'}
78
81
79
- fig = {
80
- 'data' : [
81
- {
82
- 'x' : [1 , 2 , 3 ],
83
- 'y' : [2 , 1 , 2 ]
84
- }
85
- ]
86
- }
87
-
88
82
kwargs = {'filename' : 'invalid-sharing-argument' ,
89
83
'sharing' : 'privste' }
90
84
91
85
with self .assertRaisesRegexp (PlotlyError , 'sharing' ):
92
- py .plot (fig , ** kwargs )
86
+ py .plot (self . simple_figure , ** kwargs )
93
87
94
88
def test_plot_world_readable_sharing_conflict_1 (self ):
95
89
96
90
# Raise an error if world_readable=False but sharing='public'
97
91
98
- fig = {
99
- 'data' : [
100
- {
101
- 'x' : [1 , 2 , 3 ],
102
- 'y' : [2 , 1 , 2 ]
103
- }
104
- ]
105
- }
106
-
107
92
kwargs = {'filename' : 'invalid-privacy-setting' ,
108
93
'world_readable' : False ,
109
94
'sharing' : 'public' }
110
95
111
96
with self .assertRaisesRegexp (PlotlyError , 'sharing' ):
112
- py .plot (fig , ** kwargs )
97
+ py .plot (self . simple_figure , ** kwargs )
113
98
114
99
def test_plot_world_readable_sharing_conflict_2 (self ):
115
100
116
101
# Raise an error if world_readable=True but sharing='secret'
117
102
118
- fig = {
119
- 'data' : [
120
- {
121
- 'x' : [1 , 2 , 3 ],
122
- 'y' : [2 , 1 , 2 ]
123
- }
124
- ]
125
- }
126
-
127
103
kwargs = {'filename' : 'invalid-privacy-setting' ,
128
104
'world_readable' : True ,
129
105
'sharing' : 'secret' }
130
106
131
107
with self .assertRaisesRegexp (PlotlyError , 'sharing' ):
132
- py .plot (fig , ** kwargs )
108
+ py .plot (self . simple_figure , ** kwargs )
133
109
134
110
def test_plot_option_logic_only_world_readable_given (self ):
135
111
@@ -173,22 +149,14 @@ def test_plot_option_logic_only_sharing_given(self):
173
149
'sharing' : 'private' }
174
150
self .assertEqual (plot_option_logic , expected_plot_option_logic )
175
151
176
- # @skip('added to see if everything else passes on circle')
177
152
def test_plot_url_given_sharing_key (self ):
178
153
179
154
# Give share_key is requested, the retun url should contain
180
155
# the share_key
181
156
182
- data = {
183
- 'data' : [
184
- {
185
- 'x' : [1 , 2 , 3 ],
186
- 'y' : [2 , 1 , 2 ]
187
- }
188
- ]
189
- }
190
157
validate = True
191
- fig = tls .return_figure_from_figure_or_data (data , validate )
158
+ fig = tls .return_figure_from_figure_or_data (self .simple_figure ,
159
+ validate )
192
160
kwargs = {'filename' : 'is_share_key_included' ,
193
161
'fileopt' : 'overwrite' ,
194
162
'world_readable' : False ,
@@ -200,57 +168,41 @@ def test_plot_url_given_sharing_key(self):
200
168
201
169
def test_plot_url_response_given_sharing_key (self ):
202
170
203
- # Give share_key is requested, the get request of url should
171
+ # Given share_key is requested, get request of the url should
204
172
# be 200
205
173
206
- data = {
207
- 'data' : [
208
- {
209
- 'x' : [1 , 2 , 3 ],
210
- 'y' : [2 , 1 , 2 ]
211
- }
212
- ]
213
- }
214
- validate = True
215
- fig = tls .return_figure_from_figure_or_data (data , validate )
216
174
kwargs = {'filename' : 'is_share_key_included' ,
217
175
'fileopt' : 'overwrite' ,
176
+ 'auto_open' : False ,
218
177
'world_readable' : False ,
219
178
'sharing' : 'secret' }
220
179
221
- self .assertTrue (200 ==
222
- requests .get (
223
- py ._send_to_plotly (fig , ** kwargs )['url' ])
224
- .status_code )
180
+ plot_url = py .plot (self .simple_figure , ** kwargs )
181
+ response = requests .get (plot_url )
182
+ self .assertEqual (response .status_code , 200 )
225
183
226
184
def test_private_plot_response_with_and_without_share_key (self ):
227
185
228
- # The get response of private plot should be 404 and once share_key
229
- # is added it should be 200
230
-
231
- data = {
232
- 'data' : [
233
- {
234
- 'x' : [1 , 2 , 3 ],
235
- 'y' : [2 , 1 , 2 ]
236
- }
237
- ]
238
- }
239
- validate = True
240
- fig = tls .return_figure_from_figure_or_data (data , validate )
186
+ # The json file of the private plot should be 404 and once
187
+ # share_key is added it should be 200
188
+
241
189
kwargs = {'filename' : 'is_share_key_included' ,
242
190
'fileopt' : 'overwrite' ,
243
191
'world_readable' : False ,
244
192
'sharing' : 'private' }
245
193
246
- private_plot_url = py ._send_to_plotly (fig , ** kwargs )['url' ]
194
+ private_plot_url = py ._send_to_plotly (self .simple_figure ,
195
+ ** kwargs )['url' ]
196
+ private_plot_response = requests .get (private_plot_url + ".json" )
247
197
248
- self . assertTrue ( 404 ==
249
- requests . get ( private_plot_url + ".json" ). status_code )
198
+ # The json file of the private plot should be 404
199
+ self . assertEqual ( private_plot_response . status_code , 404 )
250
200
251
201
secret_plot_url = py .add_share_key_to_url (private_plot_url )
252
202
urlsplit = six .moves .urllib .parse .urlparse (secret_plot_url )
253
- secret_plot_url_in_json = six .moves .urllib .parse .urljoin (
203
+ secret_plot_json_file = six .moves .urllib .parse .urljoin (
254
204
urlsplit .geturl (), "?.json" + urlsplit .query )
255
- self .assertTrue (200 ==
256
- requests .get (secret_plot_url_in_json ).status_code )
205
+ secret_plot_response = requests .get (secret_plot_json_file )
206
+
207
+ # The json file of the secret plot should be 200
208
+ self .assertTrue (secret_plot_response .status_code , 200 )
0 commit comments