Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1441b71

Browse filesBrowse files
committed
🔧 Cleanup test_get_requests.py.
1 parent 463dfae commit 1441b71
Copy full SHA for 1441b71

File tree

Expand file treeCollapse file tree

1 file changed

+114
-128
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+114
-128
lines changed

‎plotly/tests/test_core/test_get_requests/test_get_requests.py

Copy file name to clipboardExpand all lines: plotly/tests/test_core/test_get_requests/test_get_requests.py
+114-128Lines changed: 114 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from nose.plugins.attrib import attr
1313
from requests.compat import json as _json
1414

15+
from plotly.tests.utils import PlotlyTestCase
1516

1617
default_headers = {'plotly-username': '',
1718
'plotly-apikey': '',
@@ -20,137 +21,122 @@
2021

2122
server = "https://plot.ly"
2223

23-
# username = "get_test_user"
24-
# password = "password"
25-
# api_key = "vgs6e0cnoi" (currently...)
26-
27-
28-
@attr('slow')
29-
def test_user_does_not_exist():
30-
username = 'user_does_not_exist'
31-
api_key = 'invalid-apikey'
32-
file_owner = 'get_test_user'
33-
file_id = 0
34-
hd = copy.copy(default_headers)
35-
hd['plotly-username'] = username
36-
hd['plotly-apikey'] = api_key
37-
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
38-
response = requests.get(server + resource, headers=hd)
39-
if six.PY3:
40-
content = _json.loads(response.content.decode('unicode_escape'))
41-
else:
42-
content = _json.loads(response.content)
43-
print(response.status_code)
44-
print(content)
45-
assert response.status_code == 404
46-
assert (content['error'] == "Aw, snap! We don't have an account for {0}. "
47-
"Want to try again? Sign in is not case "
48-
"sensitive.".format(username))
49-
50-
51-
@attr('slow')
52-
def test_file_does_not_exist():
53-
username = 'PlotlyImageTest'
54-
api_key = '786r5mecv0'
55-
file_owner = 'get_test_user'
56-
file_id = 1000
57-
hd = copy.copy(default_headers)
58-
hd['plotly-username'] = username
59-
hd['plotly-apikey'] = api_key
60-
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
61-
response = requests.get(server + resource, headers=hd)
62-
if six.PY3:
63-
content = _json.loads(response.content.decode('unicode_escape'))
64-
else:
65-
content = _json.loads(response.content)
66-
print(response.status_code)
67-
print(content)
68-
assert response.status_code == 404
69-
assert (content['error'] == "Aw, snap! It looks like this file does not "
70-
"exist. Want to try again?")
71-
72-
73-
@attr('slow')
74-
def test_wrong_api_key(): # TODO: does this test the right thing?
75-
username = 'PlotlyImageTest'
76-
api_key = 'invalid-apikey'
77-
file_owner = 'get_test_user'
78-
file_id = 0
79-
hd = copy.copy(default_headers)
80-
hd['plotly-username'] = username
81-
hd['plotly-apikey'] = api_key
82-
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
83-
response = requests.get(server + resource, headers=hd)
84-
assert response.status_code == 401
85-
# TODO: check error message?
86-
87-
88-
# Locked File
89-
# TODO
90-
91-
@attr('slow')
92-
def test_private_permission_defined():
93-
username = 'PlotlyImageTest'
94-
api_key = '786r5mecv0'
95-
file_owner = 'get_test_user'
96-
file_id = 1 # 1 is a private file
97-
hd = copy.copy(default_headers)
98-
hd['plotly-username'] = username
99-
hd['plotly-apikey'] = api_key
100-
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
101-
response = requests.get(server + resource, headers=hd)
102-
if six.PY3:
103-
content = _json.loads(response.content.decode('unicode_escape'))
104-
else:
105-
content = _json.loads(response.content)
106-
print(response.status_code)
107-
print(content)
108-
assert response.status_code == 403
109-
110-
# Private File that is shared
111-
# TODO
112-
113-
114-
@attr('slow')
115-
def test_missing_headers():
116-
file_owner = 'get_test_user'
117-
file_id = 0
118-
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
119-
headers = list(default_headers.keys())
120-
for header in headers:
24+
25+
class GetRequestsTest(PlotlyTestCase):
26+
27+
@attr('slow')
28+
def test_user_does_not_exist(self):
29+
username = 'user_does_not_exist'
30+
api_key = 'invalid-apikey'
31+
file_owner = 'get_test_user'
32+
file_id = 0
33+
hd = copy.copy(default_headers)
34+
hd['plotly-username'] = username
35+
hd['plotly-apikey'] = api_key
36+
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
37+
response = requests.get(server + resource, headers=hd)
38+
if six.PY3:
39+
content = _json.loads(response.content.decode('unicode_escape'))
40+
else:
41+
content = _json.loads(response.content)
42+
error_message = ("Aw, snap! We don't have an account for {0}. Want to "
43+
"try again? Sign in is not case sensitive."
44+
.format(username))
45+
self.assertEqual(response.status_code, 404)
46+
self.assertEqual(content['error'], error_message)
47+
48+
@attr('slow')
49+
def test_file_does_not_exist(self):
50+
username = 'PlotlyImageTest'
51+
api_key = '786r5mecv0'
52+
file_owner = 'get_test_user'
53+
file_id = 1000
54+
hd = copy.copy(default_headers)
55+
hd['plotly-username'] = username
56+
hd['plotly-apikey'] = api_key
57+
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
58+
response = requests.get(server + resource, headers=hd)
59+
if six.PY3:
60+
content = _json.loads(response.content.decode('unicode_escape'))
61+
else:
62+
content = _json.loads(response.content)
63+
error_message = ("Aw, snap! It looks like this file does "
64+
"not exist. Want to try again?")
65+
self.assertEqual(response.status_code, 404)
66+
self.assertEqual(content['error'], error_message)
67+
68+
@attr('slow')
69+
def test_wrong_api_key(self): # TODO: does this test the right thing?
70+
username = 'PlotlyImageTest'
71+
api_key = 'invalid-apikey'
72+
file_owner = 'get_test_user'
73+
file_id = 0
74+
hd = copy.copy(default_headers)
75+
hd['plotly-username'] = username
76+
hd['plotly-apikey'] = api_key
77+
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
78+
response = requests.get(server + resource, headers=hd)
79+
self.assertEqual(response.status_code, 401)
80+
# TODO: check error message?
81+
82+
# Locked File
83+
# TODO
84+
85+
@attr('slow')
86+
def test_private_permission_defined(self):
87+
username = 'PlotlyImageTest'
88+
api_key = '786r5mecv0'
89+
file_owner = 'get_test_user'
90+
file_id = 1 # 1 is a private file
91+
hd = copy.copy(default_headers)
92+
hd['plotly-username'] = username
93+
hd['plotly-apikey'] = api_key
94+
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
95+
response = requests.get(server + resource, headers=hd)
96+
if six.PY3:
97+
content = _json.loads(response.content.decode('unicode_escape'))
98+
else:
99+
content = _json.loads(response.content)
100+
self.assertEqual(response.status_code, 403)
101+
102+
# Private File that is shared
103+
# TODO
104+
105+
@attr('slow')
106+
def test_missing_headers(self):
107+
file_owner = 'get_test_user'
108+
file_id = 0
109+
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
110+
headers = list(default_headers.keys())
111+
for header in headers:
112+
hd = copy.copy(default_headers)
113+
del hd[header]
114+
response = requests.get(server + resource, headers=hd)
115+
if six.PY3:
116+
content = _json.loads(response.content.decode('unicode_escape'))
117+
else:
118+
content = _json.loads(response.content)
119+
self.assertEqual(response.status_code, 422)
120+
121+
@attr('slow')
122+
def test_valid_request(self):
123+
username = 'PlotlyImageTest'
124+
api_key = '786r5mecv0'
125+
file_owner = 'get_test_user'
126+
file_id = 0
121127
hd = copy.copy(default_headers)
122-
del hd[header]
128+
hd['plotly-username'] = username
129+
hd['plotly-apikey'] = api_key
130+
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
123131
response = requests.get(server + resource, headers=hd)
124132
if six.PY3:
125133
content = _json.loads(response.content.decode('unicode_escape'))
126134
else:
127135
content = _json.loads(response.content)
128-
print(response.status_code)
129-
print(content)
130-
assert response.status_code == 422
131-
132-
133-
@attr('slow')
134-
def test_valid_request():
135-
username = 'PlotlyImageTest'
136-
api_key = '786r5mecv0'
137-
file_owner = 'get_test_user'
138-
file_id = 0
139-
hd = copy.copy(default_headers)
140-
hd['plotly-username'] = username
141-
hd['plotly-apikey'] = api_key
142-
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
143-
response = requests.get(server + resource, headers=hd)
144-
if six.PY3:
145-
content = _json.loads(response.content.decode('unicode_escape'))
146-
else:
147-
content = _json.loads(response.content)
148-
print(response.status_code)
149-
print(content)
150-
assert response.status_code == 200
151-
# content = _json.loads(res.content)
152-
# response_payload = content['payload']
153-
# figure = response_payload['figure']
154-
# if figure['data'][0]['x'] != [u'1', u'2', u'3']:
155-
# print('ERROR')
156-
# return res
136+
self.assertEqual(response.status_code, 200)
137+
# content = _json.loads(res.content)
138+
# response_payload = content['payload']
139+
# figure = response_payload['figure']
140+
# if figure['data'][0]['x'] != [u'1', u'2', u'3']:
141+
# print('ERROR')
142+
# return res

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.