Skip to content

Commit 81d86e8

Browse files
committed
made correction for test_plotly
1 parent 933aae3 commit 81d86e8

File tree

1 file changed

+28
-76
lines changed

1 file changed

+28
-76
lines changed

plotly/tests/test_core/test_plotly/test_plot.py

Lines changed: 28 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from unittest import TestCase
1414
from nose.tools import raises
15-
from unittest import skip
1615

1716
import plotly.tools as tls
1817
from plotly.plotly import plotly as py
@@ -66,70 +65,47 @@ def test_plot_invalid_args_2():
6665

6766
class TestPlot(TestCase):
6867

68+
def setUp(self):
69+
self.simple_figure = {'data': [{'x': [1, 2, 3], 'y': [2, 1, 2]}]}
70+
super(TestPlot, self).setUp()
71+
6972
def test_plot_empty_data(self):
7073
py.sign_in('PlotlyImageTest', '786r5mecv0')
7174
self.assertRaises(PlotlyEmptyDataError, py.plot, [],
7275
filename='plot_invalid')
7376

74-
def test_plot_sharing_argument(self):
77+
def test_plot_sharing_invalid_argument(self):
7578

7679
# Raise an error if sharing argument is incorrect
7780
# correct arguments {'public, 'private', 'secret'}
7881

79-
fig = {
80-
'data': [
81-
{
82-
'x': [1, 2, 3],
83-
'y': [2, 1, 2]
84-
}
85-
]
86-
}
87-
8882
kwargs = {'filename': 'invalid-sharing-argument',
8983
'sharing': 'privste'}
9084

9185
with self.assertRaisesRegexp(PlotlyError, 'sharing'):
92-
py.plot(fig, **kwargs)
86+
py.plot(self.simple_figure, **kwargs)
9387

9488
def test_plot_world_readable_sharing_conflict_1(self):
9589

9690
# Raise an error if world_readable=False but sharing='public'
9791

98-
fig = {
99-
'data': [
100-
{
101-
'x': [1, 2, 3],
102-
'y': [2, 1, 2]
103-
}
104-
]
105-
}
106-
10792
kwargs = {'filename': 'invalid-privacy-setting',
10893
'world_readable': False,
10994
'sharing': 'public'}
11095

11196
with self.assertRaisesRegexp(PlotlyError, 'sharing'):
112-
py.plot(fig, **kwargs)
97+
py.plot(self.simple_figure, **kwargs)
11398

11499
def test_plot_world_readable_sharing_conflict_2(self):
115100

116101
# Raise an error if world_readable=True but sharing='secret'
117102

118-
fig = {
119-
'data': [
120-
{
121-
'x': [1, 2, 3],
122-
'y': [2, 1, 2]
123-
}
124-
]
125-
}
126-
127103
kwargs = {'filename': 'invalid-privacy-setting',
128104
'world_readable': True,
129105
'sharing': 'secret'}
130106

131107
with self.assertRaisesRegexp(PlotlyError, 'sharing'):
132-
py.plot(fig, **kwargs)
108+
py.plot(self.simple_figure, **kwargs)
133109

134110
def test_plot_option_logic_only_world_readable_given(self):
135111

@@ -173,22 +149,14 @@ def test_plot_option_logic_only_sharing_given(self):
173149
'sharing': 'private'}
174150
self.assertEqual(plot_option_logic, expected_plot_option_logic)
175151

176-
# @skip('added to see if everything else passes on circle')
177152
def test_plot_url_given_sharing_key(self):
178153

179154
# Give share_key is requested, the retun url should contain
180155
# the share_key
181156

182-
data = {
183-
'data': [
184-
{
185-
'x': [1, 2, 3],
186-
'y': [2, 1, 2]
187-
}
188-
]
189-
}
190157
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)
192160
kwargs = {'filename': 'is_share_key_included',
193161
'fileopt': 'overwrite',
194162
'world_readable': False,
@@ -200,57 +168,41 @@ def test_plot_url_given_sharing_key(self):
200168

201169
def test_plot_url_response_given_sharing_key(self):
202170

203-
# Give share_key is requested, the get request of url should
171+
# Given share_key is requested, get request of the url should
204172
# be 200
205173

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)
216174
kwargs = {'filename': 'is_share_key_included',
217175
'fileopt': 'overwrite',
176+
'auto_open': False,
218177
'world_readable': False,
219178
'sharing': 'secret'}
220179

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)
225183

226184
def test_private_plot_response_with_and_without_share_key(self):
227185

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+
241189
kwargs = {'filename': 'is_share_key_included',
242190
'fileopt': 'overwrite',
243191
'world_readable': False,
244192
'sharing': 'private'}
245193

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")
247197

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)
250200

251201
secret_plot_url = py.add_share_key_to_url(private_plot_url)
252202
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(
254204
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

Comments
 (0)