Skip to content

Fix failing test and refact to TestCase. #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions plotly/tests/test_core/test_file/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@
A module intended for use with Nose.

"""

from nose.tools import raises
from nose import with_setup

import random
import string
import requests
from unittest import TestCase

import plotly.plotly as py
import plotly.tools as tls
from plotly.exceptions import PlotlyRequestError


def _random_filename():
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
unique_filename = 'Valid Folder'+''.join(random_chars)
return unique_filename


def init():
py.sign_in('PythonTest', '9v9f20pext')

class FolderAPITestCase(TestCase):

@with_setup(init)
def test_create_folder():
py.file_ops.mkdirs(_random_filename())
def setUp(self):
py.sign_in('PythonTest', '9v9f20pext')

def _random_filename(self):
random_chars = [random.choice(string.ascii_uppercase)
for _ in range(5)]
unique_filename = 'Valid Folder'+''.join(random_chars)
return unique_filename

@with_setup(init)
def test_create_nested_folders():
first_folder = _random_filename()
nested_folder = '{0}/{1}'.format(first_folder, _random_filename())
py.file_ops.mkdirs(nested_folder)
def test_create_folder(self):
try:
py.file_ops.mkdirs(self._random_filename())
except PlotlyRequestError as e:
self.fail('Expected this *not* to fail! Status: {}'
.format(e.status_code))

def test_create_nested_folders(self):
first_folder = self._random_filename()
nested_folder = '{0}/{1}'.format(first_folder, self._random_filename())
try:
py.file_ops.mkdirs(nested_folder)
except PlotlyRequestError as e:
self.fail('Expected this *not* to fail! Status: {}'
.format(e.status_code))

@with_setup(init)
def test_duplicate_folders():
first_folder = _random_filename()
py.file_ops.mkdirs(first_folder)
try:
def test_duplicate_folders(self):
first_folder = self._random_filename()
py.file_ops.mkdirs(first_folder)
except PlotlyRequestError as e:
if e.status_code != 409:
raise e
try:
py.file_ops.mkdirs(first_folder)
except PlotlyRequestError as e:
self.assertTrue(400 <= e.status_code < 500)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it sort of helpful to know which error code was thrown? I can imagine writing code against a specific error code (e.g. "if conflict, then the folder exists, so don't make a new folder")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i could definitely see that, it's just that i don't think the python library should couple so closely to streambed. this holds for streaming too, we should try and be as transparent about interacting with the plotly apis as possible. i think :)

Also, the 4xx is like "hey, you did something wrong, you'll need to change your code to fix it", which is much different from 5xx, "oops, our bad, you might want to try that again later".

else:
self.fail('Expected this to fail!')
2 changes: 1 addition & 1 deletion plotly/tests/test_optional/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_pandas_json_encoding():
# Test that data wasn't mutated
assert_series_equal(df['col 1'],
pd.Series([1, 2, 3, dt(2014, 1, 5),
pd.NaT, np.NaN, np.Inf]))
pd.NaT, np.NaN, np.Inf], name='col 1'))

j2 = json.dumps(df.index, cls=utils.PlotlyJSONEncoder)
assert(j2 == '[0, 1, 2, 3, 4, 5, 6]')
Expand Down